Cesium实战系列文章总目录
:
传送门
1.实现效果
2.实现方法
基于面状entity的extrudedHeight高度来拉伸面,实现简单的淹没分析效果。
但直接使用setInterval设置extrudedHeight,会导致闪烁问题严重,可视化效果不好。
因此使用Cesium回调函数CallbackProperty来动态设置拉伸高度,可视化效果较好。
/**
* 淹没分析函数,通过拉伸面的高度来进行分析
* @param {*} viewer
* @param {*} targertWaterHeight :目标水位高度
* @param {*} positions :研究区域底部坐标数组
* @param {*} waterHeight :当前水位高度
*/
function induationAnalysis(viewer, targertWaterHeight, positions, waterHeight) {
viewer.entities.add({
polygon: {
hierarchy: new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArray(positions)),
perPositionHeight: true,
// 使用回调函数Callback,直接设置extrudedHeight会导致闪烁
extrudedHeight: new Cesium.CallbackProperty(function() {
waterHeight += 0.2;
if (waterHeight > targertWaterHeight) {
waterHeight = targertWaterHeight;
}
return waterHeight;
}, false),
material: new Cesium.Color.fromBytes(64, 157, 253, 150),
}
});
}