三维简易弹框

这篇博客介绍了如何在Cesium三维视图中创建一个弹窗组件,包括关闭功能、位置更新以及与Vue子组件的交互。通过监听场景渲染事件实现实时更新标签位置,并在相机高度变化时控制显示。Vue子组件包含详细信息展示,支持关闭操作。
摘要由CSDN通过智能技术生成

使用

import PopupWindow from "@/utils/cesiumTool/PopupWindow.js";
              pWindow && pWindow.windowClose();
              pWindow = new PopupWindow(
                window.viewer,
                Cesium.Cartesian3.fromDegrees(
                  pick.id.obj.coordinates[0],
                  pick.id.obj.coordinates[1]
                ),
                {
                  field: ["监控", "ipkk", "测试", "lll"],
                  value: [12, 23, 34, 34],
                }
              );

js数据

import Vue from "vue";
import WindowVue from "./window.vue";
let WindowVm = Vue.extend(WindowVue);
export default class PopupWindow {
    constructor(viewer, position, data) {
        console.log(viewer, position, data)
        this.vmInstance = new WindowVm().$mount();
        this.vmInstance.detail = data
        this.viewer = viewer;
        this.position = position;

        //点击窗口上的关闭按钮
        this.vmInstance.closeEvent = e => {
            this.windowClose();
        };

        viewer.cesiumWidget.container.appendChild(this.vmInstance.$el);
        this.addPostRender(position);
    }


    //添加场景事件
    addPostRender() {
        this.viewer.scene.postRender.addEventListener(this.postRender, this);
    }

    //场景渲染事件 实时更新标签的位置 使其与笛卡尔坐标一致
    postRender() {
        if (!this.vmInstance.$el || !this.vmInstance.$el.style) return;
        const canvasHeight = this.viewer.scene.canvas.height;
        const windowPosition = new Cesium.Cartesian2();
        Cesium.SceneTransforms.wgs84ToWindowCoordinates(this.viewer.scene, this.position, windowPosition);
        this.vmInstance.$el.style.bottom = canvasHeight - windowPosition.y + 70 + "px";
        const elWidth = this.vmInstance.$el.offsetWidth;
        this.vmInstance.$el.style.left = windowPosition.x + 20 + "px";

        // if (this.viewer.camera.positionCartographic.height > 4000) {
        //     this.vmInstance.$el.style.display = "none";
        // } else {
        //     this.vmInstance.$el.style.display = "block";
        // }
    }

    windowClose() {
        this.viewer.selectedEntity = null
        this.vmInstance.show = false; //删除dom
        this.viewer.scene.postRender.removeEventListener(this.postRender, this); //移除事件监听
    }
}

pop的vue文件

<template>
    <div class="popup3d-container" v-if="show">
        <div class="popup3d-header">
            <span class="popup3d-header-title">详细信息</span>
            <span class="popup3d-close" @click="handleClose" title="关闭">×</span>
        </div>
        <div class="popup3d-body">
            <div style="display: flex" v-for="(item, index) in detail.field" :key="index">
                <div>{{item}}</div>
                <div>{{detail.value[index]}}</div>
            </div>
        </div>
    </div>
</template>
<script>
    export default {
        name: "PopupWindow2",
        data() {
            return {
                show: true,
                detail: {}
            };
        },
        props: {
            id: {
                type: Number,
                default: -1
            }
        },
        methods: {
            handleClose() {
                if (this.closeEvent) {
                    this.closeEvent();
                }
            }
        }
    };
</script>

<style   scoped>
    .popup3d-container {
        width: 350px;
        height: 200px;
        background: #14193399;
        position: absolute;
        left: 0px;
        bottom: 0px;
        cursor: default;
    }

    .popup3d-container::before {
        content: "";
        width: calc(100% + 22px);
        height: 39px;
        position: absolute;
        bottom: -39px;
        left: -22px;
        background: url('./popup3d.png') 0px 0px no-repeat;
    }

    .popup3d-header {
        height: 30px;
        color: white;
        background: #1f3f8e;
        line-height: 30px;
    }

    .popup3d-header-title {
        display: inline-block;
        height: 100%;
        margin-left: 5px;
    }

    .popup3d-close {
        position: absolute;
        right: 1px;
        font-size: 25px;
        cursor: pointer;
        width: 29px;
        text-align: center;
    }

    .popup3d-close:hover {
        color: #88aacc;
    }

    .popup3d-body {
        padding: 10px;
        color:white;
    }
</style>


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值