cesium——鼠标拾取坐标并转换为经纬高

cesium拾取坐标的两种方法

一、获取椭球体表面的经纬度

var viewer = new Cesium.Viewer('container');
var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
handler.setInputAction(function (event) {
    // 屏幕坐标转世界坐标——关键点
    var ellipsoid = viewer.scene.globe.ellipsoid;
    var cartesian = viewer.camera.pickEllipsoid(event.position, ellipsoid);
    //将笛卡尔坐标转换为地理坐标
    var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
    //将弧度转为度的十进制度表示
    var lon = Cesium.Math.toDegrees(cartographic.longitude);
    var lat = Cesium.Math.toDegrees(cartographic.latitude);
}, Cesium.ScreenSpaceEventType.LEFT_CLICK)

二、获取地形表面经纬高

var viewer = new Cesium.Viewer('container');
var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
handler.setInputAction(function (event) {
    // 屏幕坐标转世界坐标——关键点
    var ray=viewer.camera.getPickRay(event.position);
    var cartesian=viewer.scene.globe.pick(ray,viewer.scene);
    //将笛卡尔坐标转换为地理坐标
    var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
    //将弧度转为度的十进制度表示
    var lon = Cesium.Math.toDegrees(cartographic.longitude);
    var lat = Cesium.Math.toDegrees(cartographic.latitude);
    // 获取海拔高度
    var height1 = viewer.scene.globe.getHeight(cartographic);
    var height2 = cartographic.height;
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);

 

 

你可能感兴趣的:(Cesium)