Cesium 根据相机高度控制某个图层显示隐藏
一、源码
const cesiumUtils = { viewer: null, isShowLayer: false, layerShowHeight: 500, //小于500展示 layer: null, init() { //,.... }, controlLayerShow() { const updateLayerIsShow = () => { const cameraHeight = Math.round( viewer.camera.positionCartographic.height ); if (cameraHeight < this.layerShowHeight && !this.isShowLayer) { this.layer.show = true; this.isShowLayer = true; } else if (cameraHeight > this.layerShowHeight && this.isShowLayer) { this.layer.show = false; this.isShowLayer = false; } }; this.viewer.scene.postRender.addEventListener(updateLayerIsShow); //每帧去监听 }, };