其他分享
首页 > 其他分享> > cesium鼠标移入移出实体显示提示框

cesium鼠标移入移出实体显示提示框

作者:互联网

使用cesium的label作为提示框

           //鼠标移动事件point放大缩小
            var canvas = this.cesiumViewer.scene.canvas;
            var handler= new Cesium.ScreenSpaceEventHandler(canvas);
            var viewer = this.cesiumViewer;
            var labelEntity = viewer.entities.add({
                  point: {
                        show:true,
                        color:Cesium.Color.YELLOW,
                        pixelSize: 30,
                        heightReference: Cesium.HeightReference.CLAMP_TO_GROUND
                    },
                 label : {
                        show : false,
                        showBackground : true,
                        font : '14px monospace',
                        backgroundPadding: new Cesium.Cartesian2(10,10),
                        pixelOffset: new Cesium.Cartesian2(10, 0),
                        backgroundColor: new Cesium.Color(0.165,0.165,0.165,0.9),
                        horizontalOrigin : Cesium.HorizontalOrigin.CENTER,
                        verticalOrigin : Cesium.VerticalOrigin.TOP,
                        pixelOffset : new Cesium.Cartesian2(10, 0)
                    }
            });
        //鼠标移入labelEntity提示框
        handler.setInputAction(function(movement) {
        let foundPosition = false;
        if (viewer.scene.mode !== Cesium.SceneMode.MORPHING) {
            let pickedFeatureStart = viewer.scene.pick(movement.startPosition);
            let pickedObject = viewer.scene.pick(movement.endPosition);
            if (viewer.scene.pickPositionSupported && Cesium.defined(pickedObject) && pickedObject.id !== '') {
                let cartesian = viewer.scene.pickPosition(movement.endPosition);
                if (Cesium.defined(cartesian)) {
                    let cartographic = Cesium.Cartographic.fromCartesian(cartesian);
                    labelEntity.position = cartesian;
                    labelEntity.label.show = true;
                    labelEntity.point.show= false;
                    labelEntity.label.text = pickedObject.id._label._text._value;
                    labelEntity.label.eyeOffset = new Cesium.Cartesian3(0.0,0.0,0.0, -cartographic.height * (viewer.scene.mode === Cesium.SceneMode.SCENE2D ? 1.5 : 1.0));
                    pickedObject.id._point._pixelSize._value = 35 
                    foundPosition = true;
                    }
                }
                }else{
                    pickedObject.id._point._pixelSize._value = 30
                }
                if (!foundPosition) {
                    labelEntity.label.show = false;
                }
            }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

标签:viewer,移出,scene,label,Cesium,labelEntity,._,cesium,提示框
来源: https://blog.csdn.net/qq_34297387/article/details/122823206