let self = this
let scene = viewer.scene
let handler3D = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas)
handler3D.setInputAction(function(movement) {
let pick = new Cesium.Cartesian2(movement.endPosition.x, movement.endPosition.y)
if (pick) {
let cartesian = viewer.scene.globe.pick(viewer.camera.getPickRay(pick), viewer.scene)
if (cartesian) {
//世界坐标转地理坐标(弧度)
let cartographic = viewer.scene.globe.ellipsoid.cartesianToCartographic(cartesian)
if (cartographic) {
//海拔
let height = viewer.scene.globe.getHeight(cartographic)
//视角海拔高度
let he = Math.sqrt(
viewer.scene.camera.positionWC.x * viewer.scene.camera.positionWC.x +
viewer.scene.camera.positionWC.y * viewer.scene.camera.positionWC.y +
viewer.scene.camera.positionWC.z * viewer.scene.camera.positionWC.z
)
let he2 = Math.sqrt(
cartesian.x * cartesian.x + cartesian.y * cartesian.y + cartesian.z * cartesian.z
)
//地理坐标(弧度)转经纬度坐标
let point = [
(cartographic.longitude / Math.PI) * 180,
(cartographic.latitude / Math.PI) * 180,
]
if (!height) {
height = 0
}
if (!he) {
he = 0
}
if (!he2) {
he2 = 0
}
if (!point) {
point = [0, 0]
}
self.viewHeight = (he - he2).toFixed(1) //视高
self.lot = point[0].toFixed(6) //经度
self.lat = point[1].toFixed(6)//纬度
self.elevation = height.toFixed(2)//海拔
}
}
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE)
效果图
网友评论