Cesium点击拾取模型高度
需求-点击时存在模型则点击事件获取模型高度,没有模型时获取地形高度
版本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);
本文转自 https://blog.csdn.net/wo_buzhidao/article/details/106636282?spm=1001.2014.3001.5502,如有侵权,请联系删除。