Cesium 获取鼠标点击坐标及世界坐标与弧度(经纬度)转换

获取鼠标点击坐标:

var handler = new Cesium.ScreenSpaceEventHandler(viewer.canvas);

handler.setInputAction(function(event) {

//获取位置的弧度表示

var earthPosition = viewer.camera.pickEllipsoid(event.position, viewer.scene.globe.ellipsoid);

// 获取世界坐标

console.log(earthPosition);

carToGraphic(earthPosition.x,earthPosition.y,earthPosition.z);

    // 平面坐标系

    //console.log(event);

}, Cesium.ScreenSpaceEventType.LEFT_CLICK);

世界坐标与弧度(经纬度)转换

function carToGraphic(x,y,z){

let ellipsoid = viewer.scene.globe.ellipsoid;

let cartesian3 = new Cesium.Cartesian3(x,y,z);   //传入世界坐标系

let cartographic = ellipsoid.cartesianToCartographic(cartesian3);

let lat = Cesium.Math.toDegrees(cartographic.latitude);   //纬度

let lng = Cesium.Math.toDegrees(cartographic.longitude); //经度

let h = cartographic.height;

let coordinate={

lat:lat,

 long:lng,

 h:h

}

return  coordinate;

}

参考文章:https://blog.csdn.net/qq_34149805/article/details/78393540

坐标的定义:

1:Cartesian2-----new Cesium.Cartesian2(x, y)

2:Cartesian3---- new Cesium.Cartesian3(x, y, z)

3:Cartographic----new Cesium.Cartographic(longitude, latitude, height) 注:经纬度为弧度单位

转换:

Cartesian3→ Cartesian2    Cesium.Cartesian2.fromCartesian3(cartesian, result)→ Cartesian2

经纬度坐标(WGS84)→ Cartesian3    Cesium.Cartesian3.fromDegrees(longitude, latitude, height, ellipsoid, result) → Cartesian3

弧度坐标 → Cartesian3     Cesium.Cartesian3.fromRadians(longitude, latitude, height, ellipsoid, result) → Cartesian3

Cartesian3→ Cartographic        Cesium.Cartographic.fromCartesian(cartesian, ellipsoid, result) → Cartographic

经纬度坐标(WGS84)→ Cartographic   Cesium.Cartographic.fromDegrees(longitude, latitude, height, result) → Cartographic


https://www.e-learn.cn/topic/2611634

你可能感兴趣的:(Cesium 获取鼠标点击坐标及世界坐标与弧度(经纬度)转换)