在Cesium中,对于terrain地形、3dtiles模型、gltf模型的高度采样是一个很基本的功能,基于此,可以做一些深度应用,而Cesium已经帮我们提供了相应的API,在这里,我帮大家总结一下,如果遇到了,可以当做帮助文档随时浏览。
terrain地形 高度采样(API: Cesium.sampleTerrainMostDetailed)
通过两点决定一条直线,求取这条直线在地表高度
-
var start = Cesium.Cartesian3.fromDegrees(114, 30);
-
var end = Cesium.Cartesian3.fromDegrees(115, 30);
-
-
var positions = [Cesium.Cartographic.fromCartesian(start)];
-
// 插值100个点(自定义)
-
var count = 100;
-
for (var i = 1; i < count; i++) {
-
var cart = Cesium.Cartesian3.lerp(start, end, i / count, new Cesium.Cartesian3());
-
positions.push(Cesium.Cartographic.fromCartesian(cart));
-
}
-
positions.push(Cesium.Cartographic.fromCartesian(end));
-
-
var promise = Cesium.sampleTerrainMostDetailed(terrainProvider, positions);
-
Cesium.when(promise, function (updatedPositions) {
-
// 每个点的高度
-
var height = [];
-
for (var i = 0; i < updatedPositions.length; i++) {
-
height.push(updatedPositions[i].height);
-
}
-
}
3dtiles模型 高度采样(API: Scene.clampToHeightMostDetailed)
-
var start = new Cesium.Cartesian3(1216467.760147752, -4736154.3567799, 4081478.9167016773);
-
var end = new Cesium.Cartesian3(1216183.8039071201, -4736456.592237458, 4081200.6372076278);
-
// 插值100个点
-
var count = 100;
-
var positions = [];
-
for (var i = 0; i <= count; i++) {
-
positions.push(Cesium.Cartesian3.lerp(start , end , i / count, new Cesium.Cartesian3()));
-
}
-
scene.clampToHeightMostDetailed(positions).then( function (clampedCartesians) {
-
// 每个点的高度
-
var height = [];
-
for (var i = 0; i < count; ++i) {
-
height.push(Cesium.Cartographic.fromCartesian(clampedCartesians[i]).height);
-
}
-
}
gltf模型 高度采样(API: Scene.sampleHeightMostDetailed)
更多详情见下面链接文章:
Cesium专栏-terrain地形、3dtiles模型、gltf模型 高度采样
对本专栏感兴趣的话,可以关注一波
来源:oschina
链接:https://my.oschina.net/u/4338312/blog/3376987