根据鼠标移动的位置计算鼠标所在位置的经纬度
监听视角变化情况显示视高、方位角、俯仰角
监测底图切片等级来显示当前地图缩放等级
showMapData() {
let _this = this
let handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas)
handler.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 lontitude = Cesium.Math.toDegrees(
cartographic.longitude
).toFixed(6)
let latitude = Cesium.Math.toDegrees(
cartographic.latitude
).toFixed(6)
_this.lontitudeData = lontitude
_this.latitudeData = latitude
// 如果加了地形可以用这个去计算海拔
// let baseHeight = viewer.scene.sampleHeight(
// new Cesium.Cartographic(
// Cesium.Math.toRadians(cartographic.longitude), //转换成弧度
// Cesium.Math.toRadians(cartographic.latitude) //弧度
// )
// );
let h = viewer.scene.globe.getHeight(cartographic) //获取当前海拔高度
h = h !== null && h !== undefined ? h.toFixed(0) : ""
_this.baseHeight = h
}
}
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE)
viewer.camera.changed.addEventListener(() => {
let heading = Cesium.Math.toDegrees(viewer.camera.heading).toFixed(2)
let pitch = Cesium.Math.toDegrees(viewer.camera.pitch).toFixed(2)
let viewHeight = viewer.camera.positionCartographic.height.toFixed(2)
_this.headingData = heading
_this.pitchData = pitch
_this.viewHeight = viewHeight
let tileRender = viewer.scene.globe._surface._tilesToRender
if (tileRender && tileRender.length > 0) {
this.mapLevelData = tileRender[0]._level
}
})
},