Cesium自定义气泡弹窗、Cesium自定义信息框

气泡弹出窗口在项目中会经常用到,但Cesium提供的信息窗口比较丑。
以下弹窗基于Vue封装,也有原生js版本。

效果图

在这里插入图片描述
在这里插入图片描述

关键代码

    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 + 80 + "px";
        const elWidth = this.vmInstance.$el.offsetWidth;
        this.vmInstance.$el.style.left = windowPosition.x - (elWidth / 2) + "px";

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

this.infoWindow = new MultiFieldAdaptWindow(this.viewer, e.position._value, "监控信息", ["监控名称", "IP地址", "监控类型", "监控状态"], [e.info.name, e.info.ip, e.info.type, e.info.state]);

详情参见 Cesium实战项目

Logo

前往低代码交流专区

更多推荐