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)
});
});
饮水思源,不忘初心。
要面包,也要有诗和远方。