cesium获取鼠标的实时经纬度和高度信息。
var cesiumViewer = this.viewer;
var canvas = cesiumViewer.scene.canvas;
var ellipsoid = cesiumViewer.scene.globe.ellipsoid;
var handler = new Cesium.ScreenSpaceEventHandler(canvas);
handler.setInputAction(function(movement){
//捕获椭球体,将笛卡尔二维平面坐标转为椭球体的笛卡尔三维坐标,返回球体表面的点
var cartesian = cesiumViewer.camera.pickEllipsoid(movement.endPosition, ellipsoid);
if(cartesian){
//将笛卡尔三维坐标转为地图坐标(弧度)
var cartographic = cesiumViewer.scene.globe.ellipsoid.cartesianToCartographic(cartesian);
//将地图坐标(弧度)转为十进制的度数
var lat = Cesium.Math.toDegrees(cartographic.latitude).toFixed(4);
var lng = Cesium.Math.toDegrees(cartographic.longitude).toFixed(4);
var height = (cesiumViewer.camera.positionCartographic.height/1000).toFixed(2);
// console.log(lng+','+lat+","+height);
_this.mousePosition = lng+", "+lat+", "+height;
}
},Cesium.ScreenSpaceEventType.MOUSE_MOVE)
网友评论