From 612ac3de5dc5067b8140272feb378e4f4da8bde4 Mon Sep 17 00:00:00 2001 From: wangrui <zephyrs0894@163.com> Date: 星期二, 22 十二月 2020 16:53:12 +0800 Subject: [PATCH] 添加服务图层的配置加载。 --- src/components/helpers/ServiceLayerHelper.js | 109 +++++++++++++++++++++++++++++++++++------------------- 1 files changed, 70 insertions(+), 39 deletions(-) diff --git a/src/components/helpers/ServiceLayerHelper.js b/src/components/helpers/ServiceLayerHelper.js index 2ca252a..128a827 100644 --- a/src/components/helpers/ServiceLayerHelper.js +++ b/src/components/helpers/ServiceLayerHelper.js @@ -1,3 +1,4 @@ +/* eslint-disable no-debugger */ /** * 鍒涘缓鍥惧眰鐩稿叧鐨勭被 */ @@ -5,8 +6,27 @@ class ServiceLayerHelper { constructor(options){ this.map = options.map + this.L = options.L this.tileLayersMap = new Map() this.tileLayersArray = [] + this.mapConfig = {} + } + + /** + * 鏍规嵁閰嶇疆鏂囦欢鍒濆鍖栦笟鍔″簳鍥� + */ + initServiceLayers(mapConfig){ + console.log(mapConfig) + this.mapConfig = mapConfig + + this._loadLayers(mapConfig) + } + + _loadLayers(mapConfig, isAddToMap = true){ + console.debug('ServiceLayerHelper鍔犺浇鍙傛暟锛�',mapConfig) + this.loadTileLayer(mapConfig, isAddToMap) + this.loadWmtsLayer(mapConfig, isAddToMap) + this.loadWmtsLayer(mapConfig, isAddToMap) } /** @@ -14,38 +34,42 @@ * @param {}} options * @param {*} isAddToMap */ - loadWmtsLayer(options, isAddToMap) { - const layer =L.tileLayer.wmts(options.url, { - layers: options.layers || 'all',//country - format: options.format || "image/png", - transparent: options.true || true, - crs:options.crs || L.CRS.EPSG4326 - }); - - if(isAddToMap) { - layer.addTo(this.map) + loadWmtsLayer(options, isAddToMap = true) { + for(let i = 0, len = options.mapConfig.ServiceLayers.length; i < len; ++i) { + let opt = options.mapConfig.ServiceLayers[i] + if(opt.type !== 'wmts') { + continue + } + const layer = this.L.tileLayer(opt.url, opt.option); + + if(isAddToMap) { + layer.addTo(this.map) + } + this.tileLayersMap.set(opt.code, layer) + this.tileLayersArray.push(layer) } - this.tileLayersMap.put(options.name, layer) - this.tileLayersArray.push(layer) } /** * 寰�鍦板浘涓姞鍏ヤ竴涓猈MS鏈嶅姟 * @param {}} options * @param {*} isAddToMap */ - loadWmsLayer(options, isAddToMap) { - const layer =L.tileLayer.wms(options.url, { - layers: options.layers || 'all',//country - format: options.format || "image/png", - transparent: options.true || true, - crs:options.crs || L.CRS.EPSG4326 - }); - - if(isAddToMap) { - layer.addTo(this.map) + loadWmsLayer(options, isAddToMap = true) { + for(let i = 0, len = options.mapConfig.ServiceLayers.length; i < len; ++i) { + let opt = options.mapConfig.ServiceLayers[i] + if(opt.type !== 'wms') { + continue + } + + const layer =this.L.tileLayer.wms(opt.url, opt.option); + + if(isAddToMap) { + layer.addTo(this.map) + } + this.tileLayersMap.set(opt.code, layer) + this.tileLayersArray.push(layer) } - this.tileLayersMap.put(options.name, layer) - this.tileLayersArray.push(layer) + } /** @@ -53,22 +77,29 @@ * @param {}} options * @param {*} isAddToMap */ - loadTileLayer(options, isAddToMap) { - const layer =L.tileLayer(options.url, { - layers: options.layers || 'all',//country - format: options.format || "image/png", - transparent: options.true || true, - crs:options.crs || L.CRS.EPSG4326, - maxZoom: options.maxZoom || 21, - minZoom: options.minZoom || 1, - zoomOffset: options.zoomOffset || 0 - }); - - if(isAddToMap) { - layer.addTo(this.map) + loadTileLayer(options, isAddToMap = true) { + for(let i = 0, len = options.mapConfig.ServiceLayers.length; i < len; ++i) { + let opt = options.mapConfig.ServiceLayers[i] + if(opt.type !== 'tile') { + continue + } + + const layer =this.L.tileLayer(opt.url, { + layers: opt.layers || 'all',//country + format: opt.format || "image/png", + transparent: opt.true || true, + crs:opt.crs || L.CRS.EPSG4326, + maxZoom: opt.maxZoom || 21, + minZoom: opt.minZoom || 1, + zoomOffset: opt.zoomOffset || 0 + }); + + if(isAddToMap) { + layer.addTo(this.map) + } + this.tileLayersMap.set(opt.code , layer) + this.tileLayersArray.push(layer) } - this.tileLayersMap.put(options.name, layer) - this.tileLayersArray.push(layer) } hideTileLayer(name){ -- Gitblit v1.8.0