需求-点击时存在模型则点击事件获取模型高度,没有模型时获取地形高度

版本cesium 1.7.0 ,vue 2.5x ,开启Cesium地形服务

代码

 viewer.screenSpaceEventHandler.setInputAction(function (clickEvent) {
            var ray1 = viewer.camera.getPickRay(clickEvent.position);
            var cartesian = viewer.scene.globe.pick(ray1, viewer.scene);
            console.log('地形高度点',cartesian);
            var pick = viewer.scene.pickPosition(clickEvent.position);
            var pickModel = viewer.scene.pick(clickEvent.position);
            if (pickModel && pick && !pickModel.id) {
                var height = Cesium.Cartographic.fromCartesian(pick).height;
                var lat = Cesium.Math.toDegrees(Cesium.Cartographic.fromCartesian(pick).latitude);
                var lng = Cesium.Math.toDegrees(Cesium.Cartographic.fromCartesian(pick).longitude);
                cartesian = Cesium.Cartesian3.fromDegrees(lng, lat, height);
                 console.log('模型高度点',cartesian);
            }
 }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
Logo

前往低代码交流专区

更多推荐