computed: {
handler() {
return new this.Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas)
}
}
//获取经纬度的方法
getPosition() {
const \_this = this //这里必须要转换一下 在setInputAction方法中,this的指向发生了变化
\_this.handler.setInputAction(function (movement) {
//获取屏幕坐标
var position = movement.endPosition
//屏幕坐标转换为世界坐标
var pick = new \_this.Cesium.Cartesian2(position.x, position.y)
var cartesian = \_this.viewer.scene.globe.pick(\_this.viewer.camera.getPickRay(pick), \_this.viewer.scene)
//世界坐标转换为经纬度
var ellipsoid = \_this.viewer.scene.globe.ellipsoid
if(cartesian === undefined){
}else{
var cartesian3 = new \_this.Cesium.Cartesian3(cartesian.x, cartesian.y, cartesian.z)
var cartographic = ellipsoid.cartesianToCartographic(cartesian3)
var lat = \_this.Cesium.Math.toDegrees(cartographic.latitude) //这是纬度
var lng = \_this.Cesium.Math.toDegrees(cartographic.longitude) //这是经度
\_this.latitudeData = lat
\_this.longitudeData = lng
}
}, \_this.Cesium.ScreenSpaceEventType.MOUSE\_MOVE) //\_this.Cesium 是在main.js里配置了全局变量
}
手机扫一扫
移动阅读更方便
你可能感兴趣的文章