From 243c4782ce378d9238a60ae8cd41723657675d69 Mon Sep 17 00:00:00 2001 From: wangrui <zephyrs0894@163.com> Date: 星期四, 24 十二月 2020 15:43:49 +0800 Subject: [PATCH] 服务图层,动态生成 --- src/components/helpers/ServiceLayerHelper.js | 59 +++++++++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 45 insertions(+), 14 deletions(-) diff --git a/src/components/helpers/ServiceLayerHelper.js b/src/components/helpers/ServiceLayerHelper.js index 9f9140e..b571d98 100644 --- a/src/components/helpers/ServiceLayerHelper.js +++ b/src/components/helpers/ServiceLayerHelper.js @@ -8,7 +8,9 @@ this.map = options.map this.L = options.L this.tileLayersMap = new Map() - this.tileLayersArray = [] + this.tileLayersWMSArray = [] + this.tileLayersWMTSArray = [] + this.tileLayersTileArray = [] this.mapConfig = {} } @@ -30,11 +32,11 @@ for(let i = 0, len = mapConfig.mapConfig.ServiceLayers.length; i < len; ++i) { let opt = mapConfig.mapConfig.ServiceLayers[i] if(opt.type === 'wmts') { - this.loadWmtsLayer(opt, isAddToMap) + this.loadWmtsLayer(opt, isAddToMap, mapConfig.mapConfig.ServiceLayers[i]) }else if(opt.type === 'wms') { - this.loadWmsLayer(opt, isAddToMap) + this.loadWmsLayer(opt, isAddToMap, mapConfig.mapConfig.ServiceLayers[i]) }else if(opt.type === 'tile') { - this.loadTileLayer(opt, isAddToMap) + this.loadTileLayer(opt, isAddToMap, mapConfig.mapConfig.ServiceLayers[i]) } } } @@ -44,28 +46,30 @@ * @param {}} options * @param {*} isAddToMap */ - loadWmtsLayer(options, isAddToMap = true) { + loadWmtsLayer(options, isAddToMap = true, config) { const layer = this.L.tileLayer(options.url, options.option); - + layer.config = config + if(isAddToMap) { layer.addTo(this.map) } this.tileLayersMap.set(options.code, layer) - this.tileLayersArray.push(layer) + this.tileLayersWMTSArray.push(layer) } /** * 寰�鍦板浘涓姞鍏ヤ竴涓猈MS鏈嶅姟 * @param {}} options * @param {*} isAddToMap */ - loadWmsLayer(options, isAddToMap = true) { + loadWmsLayer(options, isAddToMap = true, config) { const layer =this.L.tileLayer.wms(options.url, options.option); - + layer.config = config + if(isAddToMap) { layer.addTo(this.map) } this.tileLayersMap.set(options.code, layer) - this.tileLayersArray.push(layer) + this.tileLayersWMSArray.push(layer) } /** @@ -73,7 +77,7 @@ * @param {}} options * @param {*} isAddToMap */ - loadTileLayer(options, isAddToMap = true) { + loadTileLayer(options, isAddToMap = true, config) { const layer =this.L.tileLayer(options.url, { layers: options.layers || 'all',//country format: options.format || "image/png", @@ -83,12 +87,13 @@ minZoom: options.minZoom || 1, zoomOffset: options.zoomOffset || 0 }); + layer.config = config if(isAddToMap) { layer.addTo(this.map) } this.tileLayersMap.set(options.code , layer) - this.tileLayersArray.push(layer) + this.tileLayersTileArray.push(layer) } /** * 闅愯棌鏈嶅姟鍥惧眰 @@ -112,10 +117,36 @@ } /** - * 鑾峰彇鎵�鏈夌殑鏈嶅姟鍥惧眰 + * 鑾峰彇鎵�鏈夌殑TILE鏈嶅姟鍥惧眰 */ getTileLayers(){ - return this.tilelayersArray + return this.tileLayersTileArray + } + /** + * 鑾峰彇鎵�鏈夌殑WMTS鏈嶅姟鍥惧眰 + */ + getWmtsLayers(){ + return this.tileLayersWMTSArray + } + /** + * 鑾峰彇鎵�鏈夌殑WMS鏈嶅姟鍥惧眰 + */ + getWmsLayers(){ + return this.tileLayersWMSArray + } + + /** + * 閫氳繃code鏌ユ壘WMS鐨勬湇鍔¢厤缃� + * @param {} code wms鏈嶅姟閰嶇疆鐨刢ode + */ + getWMSConfig(code){ + let mc = this.mapConfig + for(let i = 0, len = mc.mapConfig.ServiceLayers.length; i < len; ++i) { + if(code == mc.mapConfig.ServiceLayers[i].code && mc.mapConfig.ServiceLayers[i].type === 'wms'){ + return mc.mapConfig.ServiceLayers[i] + } + } + return null } } export default ServiceLayerHelper -- Gitblit v1.8.0