gpt4 book ai didi

cesium - 获取地面高度 CesiumJS

转载 作者:行者123 更新时间:2023-12-03 23:46:35 60 4
gpt4 key购买 nike

有没有办法获得 CesiumJS 中给定位置的地面高度?我试过scene.globe.getHeight func 但它返回未定义。

    //marker is a point on map.
var marker = {latitude: 61.08658108795938, longitude: -99.64592791446208};
var height = scene.globe.getHeight( new Cesium.Cartographic(marker.longitude, marker.latitude ) );//undefined

谢谢你。

最佳答案

您应该使用 sampleTerrain为了这。下面是一个例子:

// Construct the default list of terrain sources.
var terrainModels = Cesium.createDefaultTerrainProviderViewModels();

// Construct the viewer, with a high-res terrain source pre-selected.
var viewer = new Cesium.Viewer('cesiumContainer', {
terrainProviderViewModels: terrainModels,
selectedTerrainProviderViewModel: terrainModels[1] // Select STK High-res terrain
});

// Get a reference to the ellipsoid, with terrain on it. (This API may change soon)
var ellipsoid = viewer.scene.globe.ellipsoid;

// Specify our point of interest.
var pointOfInterest = Cesium.Cartographic.fromDegrees(
-99.64592791446208, 61.08658108795938, 5000, new Cesium.Cartographic());

// [OPTIONAL] Fly the camera there, to see if we got the right point.
viewer.camera.flyTo({
destination: ellipsoid.cartographicToCartesian(pointOfInterest,
new Cesium.Cartesian3())
});

// Sample the terrain (async) and write the answer to the console.
Cesium.sampleTerrain(viewer.terrainProvider, 9, [pointOfInterest])
.then(function(samples) {
console.log('Height in meters is: ' + samples[0].height);
});

关于cesium - 获取地面高度 CesiumJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28291013/

60 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com