首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >获得地面高度CesiumJS

获得地面高度CesiumJS
EN

Stack Overflow用户
提问于 2015-02-03 03:45:17
回答 2查看 8.5K关注 0票数 7

在CesiumJS中,有任何方法可以获得给定位置的地面高度吗?我尝试过scene.globe.getHeight func,但它返回的是未定义的。

代码语言:javascript
复制
    //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

谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-02-03 14:53:14

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

代码语言:javascript
复制
// 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);
});
票数 4
EN

Stack Overflow用户

发布于 2015-02-09 11:44:29

这是另一种选择:

代码语言:javascript
复制
var marker = new Cesium.Cartesian3.fromDegrees(lon, lat, 0);
markers.push(marker);

var cartographicPositions =
  Cesium.Ellipsoid.WGS84.cartesianArrayToCartographicArray(markers);

var HeightCheck = setInterval(function () {
  if (cesiumTerrainProviderHeightmaps.ready) {
    clearInterval(HeightCheck);

    var promise = Cesium.sampleTerrain(
      cesiumTerrainProviderHeightmaps,
      11,
      cartographicPositions
    );
    Cesium.when(promise, function (cartographicPositions) {
      // you got the altitudes
    });
  } else {
    // "Waiting for height data of terrain...."
  }
}, 1000);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28291013

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档