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); //每帧去监听
  },
};

 

posted @ 2024-11-18 10:16  小七要走  阅读(12)  评论(0编辑  收藏  举报