【问题标题】:Get ground altitude CesiumJS获取地面高度 CesiumJS
【发布时间】:2015-02-03 03:45:17
【问题描述】:

有没有办法在 CesiumJS 中获取给定位置的地面高度?我尝试了 scene.globe.getHeight func,但它返回 undefined。

    //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

谢谢。

【问题讨论】:

    标签: cesium


    【解决方案1】:

    您应该为此使用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);
    });
    

    【讨论】:

      【解决方案2】:

      这是另一种选择:

      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);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-08-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-03-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多