From 20c50e95af03ca0b6f2ef25fe7502df1a99d3b88 Mon Sep 17 00:00:00 2001 From: 徐旺旺 <11530253@qq.com> Date: 星期二, 13 四月 2021 14:52:04 +0800 Subject: [PATCH] 根据不同地图级别显示隐藏图层 --- src/components/LayerController/service/LayerFactory.js | 39 +++++++++++++++++++++++---------------- 1 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/components/LayerController/service/LayerFactory.js b/src/components/LayerController/service/LayerFactory.js index 65f89e6..fef724f 100644 --- a/src/components/LayerController/service/LayerFactory.js +++ b/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) - if (checked && config.minZoom) { - if (zoom > config.minZoom) { - this.show(config) - } else { - console.log(config.name) - this.hide(config) - } - } + 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 { + this.hide(config) } } } -- Gitblit v1.8.0