Cesium获取地形的高度

不要再使用网上的globe的方法了,现在Cesium已经有两种方法可以获取到地形的高度了,分别为:

用法(注意,回调是异步的):

1.sampleTerrain(terrainProvider, level, positions)

Initiates a terrain height query for an array of Cartographic positions by requesting tiles from a terrain provider, sampling, and interpolating. The interpolation matches the triangles used to render the terrain at the specified level. The query happens asynchronously, so this function returns a promise that is resolved when the query completes. Each point height is modified in place. If a height can not be determined because no terrain data is available for the specified level at that location, or another error occurs, the height is set to undefined. As is typical of the Cartographic type, the supplied height is a height above the reference ellipsoid (such as Ellipsoid.WGS84) rather than an altitude above mean sea level. In other words, it will not necessarily be 0.0 if sampled in the ocean. This function needs the terrain level of detail as input, if you need to get the altitude of the terrain as precisely as possible (i.e. with maximum level of detail) use sampleTerrainMostDetailed.

翻译过来就是:

Cartographic通过从地形提供者请求切片,采样和插值来 启动位置数组的地形高度查询。插值匹配用于在指定级别渲染地形的三角形。查询以异步方式发生,因此此函数返回在查询完成时解析的promise。每个点高度都会在适当位置进行修改 如果无法确定高度,因为该位置的指定级别没有可用的地形数据,或者发生其他错误,则高度设置为undefined。作为典型的 Cartographic类型,提供的高度是参考椭球上方的高度(例如Ellipsoid.WGS84而不是高于平均海平面的高度。换句话说,如果在海洋中采样,它不一定是0.0。如果您需要尽可能精确地获取地形的高度(即具有最高细节水平),则此功能需要将地形级别的细节作为输入sampleTerrainMostDetailed

实例:

// Query the terrain height of two Cartographic positions
var terrainProvider = Cesium.createWorldTerrain();
var positions = [
    Cesium.Cartographic.fromDegrees(86.925145, 27.988257),
    Cesium.Cartographic.fromDegrees(87.0, 28.0)
];
var promise = Cesium.sampleTerrain(terrainProvider, 11, positions);
Cesium.when(promise, function(updatedPositions) {
    // positions[0].height and positions[1].height have been updated.
    // updatedPositions is just a reference to positions.
});

2.sampleTerrainMostDetailed(terrainProvider, positions)

实例:

// Query the terrain height of two Cartographic positions
var terrainProvider = Cesium.createWorldTerrain();
var positions = [
    Cesium.Cartographic.fromDegrees(86.925145, 27.988257),
    Cesium.Cartographic.fromDegrees(87.0, 28.0)
];
var promise = Cesium.sampleTerrainMostDetailed(terrainProvider, positions);
Cesium.when(promise, function(updatedPositions) {
    // positions[0].height and positions[1].height have been updated.
    // updatedPositions is just a reference to positions.
});

实战:获取指定position的地形高度:

//x为longtitude,y为latitude,terrain是地形privider
 var positions = [
              Cesium.Cartographic.fromDegrees(x, y),
            ];
            var promise = Cesium.sampleTerrainMostDetailed(terrain, positions);
            Cesium.when(promise, function (updatedPositions) {
              var terrainHeight = updatedPositions[0].height
              console.log(terrainHeight );
            });

 

Cesium是一个用于创建地球和其他地球类行星的JavaScript库。它可以用于可视化地球表面的地形,并提供了一种方法来获取指定位置的地形高度。通过使用CesiumsampleTerrainMostDetailed方法,我们可以异步地获取精确的地形高度。 在实践中,我们可以通过以下代码来获取指定位置的地形高度: ```javascript var positions = [Cesium.Cartographic.fromDegrees(longitude, latitude)]; var promise = Cesium.sampleTerrainMostDetailed(terrainProvider, positions); Cesium.when(promise, function (updatedPositions) { var terrainHeight = updatedPositions<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Cesium高度获取](https://blog.csdn.net/caozl1132/article/details/90247208)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [Cesium获取地形高度](https://blog.csdn.net/u013821237/article/details/84838103)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [64.(cesium篇)cesium根据坐标位置获取地形高度.zip](https://download.csdn.net/download/m0_60387551/85629715)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论 14
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大大大大大碗面

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值