派生自 wuyushui/SewerAndRainNetwork

徐旺旺
2021-04-13 20c50e95af03ca0b6f2ef25fe7502df1a99d3b88
根据不同地图级别显示隐藏图层
1个文件已修改
29 ■■■■■ 已修改文件
src/components/LayerController/service/LayerFactory.js 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/LayerController/service/LayerFactory.js
@@ -21,6 +21,7 @@
        var checked = config.checked
        checked && this.load(config)
        checked && this.toggleZoomByConfnig(config)
      }
    }
  }
@@ -30,27 +31,33 @@
   * @param layerConfig
   */
  initEvent (layerConfig) {
    this.map.on('zoomend ', (e) => this.toggleByZoom(layerConfig))
    this.map.on('zoomend ', (e) => this.toggleZoomByLayer(layerConfig))
  }
  toggleByZoom (layerConfig) {
    const zoom = this.map.getZoom()
    if (layerConfig) {
  toggleZoomByLayer (layerConfig) {
    var config = layerConfig
    if (Array.isArray(layerConfig)) {
      for (var i = 0, l = layerConfig.length; i < l; i++) {
        var config = layerConfig[i]
        config = layerConfig[i]
        var layers = config.layers
        var checked = config.checked
        var childLayer = config.childLayer
        layers && this.toggleByZoom(layers)
        childLayer && this.toggleByZoom(childLayer)
        layers && this.toggleZoomByLayer(layers)
        childLayer && this.toggleZoomByLayer(childLayer)
        this.toggleZoomByConfnig(config)
      }
    } else {
      this.toggleZoomByConfnig(layerConfig)
    }
  }
  toggleZoomByConfnig (config) {
    const zoom = this.map.getZoom()
    var checked = config.checked
        if (checked && config.minZoom) {
          if (zoom > config.minZoom) {
            this.show(config)
          } else {
            console.log(config.name)
            this.hide(config)
          }
        }
      }
    }
  }