Cesium 获取鼠标当前位置的模型高度,地形高度,OSGB高度,及其经纬度。

时间:2023-03-09 08:54:24
Cesium 获取鼠标当前位置的模型高度,地形高度,OSGB高度,及其经纬度。

var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene._imageryLayerCollection);
var ray,position1,cartographic1,lon,lat,height;
handler.setInputAction(function (event) { 
ray = viewer.scene.camera.getPickRay(event.endPosition); 
position1 = viewer.scene.globe.pick(ray,viewer.scene); 
cartographic1 = Cesium.Ellipsoid.WGS84.cartesianToCartographic(position1); 
var feature = scene.pick(event.endPosition); 
if (feature == undefined) { 
lon = Cesium.Math.toDegrees(cartographic1.longitude); 
lat = Cesium.Math.toDegrees(cartographic1.latitude); 
height = cartographic1.height; } 
else if(feature instanceof Cesium.Cesium3DTileFeature){ 
var cartesian = viewer.scene.pickPosition(event.endPosition); 
if (Cesium.defined(cartesian) ){ 
var cartographic = Cesium.Cartographic.fromCartesian(cartesian); 
lng = Cesium.Math.toDegrees(cartographic.longitude); 
lat = Cesium.Math.toDegrees(cartographic.latitude); 
height = cartographic.height;//模型高度 } }
//--------------------------------------------------------------
} , Cesium.ScreenSpaceEventType.MOUSE_MOVE);