# MapGIS Client for JavaScript API

Cesium MapboxGL Leaflet OpenLayers
API文档

    class TerrainCacheLayerUtil {}

    /**
     * 添加地形图层
     * @param {TerrainCacheLayer} layer 地形图层基本对象
     * @param {Viewer} sceneView Cesium的视图对象
     * @param {Function} callback 加载完成的回调函数
     * */
    TerrainCacheLayerUtil.addTerrainCacheLayer = function (
      layer,
      sceneView,
      callback
    ) {
      sceneView.scene.layers.appendSceneLayer(layer.url, {
        //  是否自动定位
        autoReset: layer.autoReset,
        //  是否请求法向（地形）
        requestVertexNormals: layer.requestVertexNormals,
        // 获取layerIndex
        getDocLayerIndexes(indexes) {
          layer.layerIndex = indexes[0]
          const tileSet = sceneView.scene.layers.getLayer(indexes[0])
          tileSet.id = layer.id
          callback(tileSet)
        }
      })
    }

    /**
     * 设置地形图层透明度
     * @param {TerrainCacheLayer} layer 地形图层基本对象
     * @param {Viewer} sceneView Cesium的视图对象
     * */
    TerrainCacheLayerUtil.setOpacity = function (layer, sceneView) {
      let baseColor
      if (layer.opacity === 1) {
        sceneView.scene.globe.translucency.enabled = false
        // eslint-disable-next-line new-cap
        baseColor = new Cesium.Color.clone(sceneView.scene.globe.baseColor)
        baseColor.alpha = 1
        sceneView.scene.globe.baseColor = baseColor
      } else {
        sceneView.scene.globe.translucency.enabled = true
        // eslint-disable-next-line new-cap
        baseColor = new Cesium.Color.clone(sceneView.scene.globe.baseColor)
        baseColor.alpha = layer.opacity
        sceneView.scene.globe.baseColor = baseColor
      }
    }

    /**
     * 移除图层
     * @param {Layer} layer 基本图层对象
     * @param {Viewer} sceneView Cesium的视图对象
     * */
    TerrainCacheLayerUtil.removeLayer = function (layer, sceneView) {
      sceneView.scene.layers.removeSceneLayerByID(layer.layerIndex)
    }

    export default TerrainCacheLayerUtil

构造函数
成员变量
方法
事件