Cesiumjs 获取坐标点高度的三种方式[转]

第一种(镜头高度太高获取的高度会为错误的负数,镜头高度要足够低)

let cartographic = Cesium.Cartographic.fromDegrees(lon,lat);
let height = viewer.scene.globe.getHeight(cartographic);

第二种(获取屏幕坐标点高度)

let scene = viewer.scene;
let globe = scene.globe;
let ray = viewer.camera.getPickRay(position);//position屏幕坐标 
let cartesian = globe.pick(ray, scene);
let ellipsoid = Cesium.Ellipsoid.WGS84;
let cartographic = ellipsoid.cartesianToCartographic(cartesian);
let height = cartographic.height;

第三种(要11级? 不然获取不到)

let cartographics= [Cesium.Cartographic.fromDegrees(lon,lat)];
Cesium.sampleTerrain(viewer.terrainProvider, 11, cartographics)
.then((updatedPositions)=>{
     updatedPositions.forEach((pos, i) => {
         console.log(pos)
      });
});
ttps://www.jianshu.com/p/ed3c8711f213
posted on 2020-08-28 12:07  3D入魔  阅读(3060)  评论(0编辑  收藏  举报