效果图
前端代码
let Cesium = null
let showWater =false
let waterEntity=null
export const drawWater=(viewer)=> {
Cesium = DC.Namespace.Cesium
showWater = true
waterEntity && viewer.entities.remove(waterEntity)
const waterCoord = [119.642769, 30.361905, 100, 119.591604, 30.448757, 100, 119.695767, 30.488232, 100, 119.748406, 30.395983, 100]
let startHeight = 100
const targetHeight = 500
waterEntity = viewer.entities.add({
polygon: {
hierarchy: Cesium.Cartesian3.fromDegreesArrayHeights(waterCoord),
material: Cesium.Color.fromBytes(64, 157, 253, 200),
perPositionHeight: true,
extrudedHeight: new Cesium.CallbackProperty(() => { return startHeight }, false)
}
})
viewer.flyToPosition(
new DC.Position(119.66332661540228,30.443762489412983, 2000, 0, -90, 0)
)
const waterInterval = setInterval(() => {
if (startHeight < targetHeight) {
startHeight += 10
if (startHeight >= targetHeight) {
startHeight = targetHeight
clearInterval(waterInterval)
showWater = false
}
}
}, 100)
}