From 47db5ff33fbb9df546b24759d52699a68fd4e841 Mon Sep 17 00:00:00 2001 From: wangrui <zephyrs0894@163.com> Date: 星期二, 22 十二月 2020 18:01:18 +0800 Subject: [PATCH] 修改底图错位的问题。 --- src/components/helpers/ServiceLayerHelper.js | 111 +++++++++++++++++++++++++++++++++++-------------------- 1 files changed, 70 insertions(+), 41 deletions(-) diff --git a/src/components/helpers/ServiceLayerHelper.js b/src/components/helpers/ServiceLayerHelper.js index ad2939c..c815807 100644 --- a/src/components/helpers/ServiceLayerHelper.js +++ b/src/components/helpers/ServiceLayerHelper.js @@ -1,3 +1,4 @@ +/* eslint-disable no-debugger */ /** * 鍒涘缓鍥惧眰鐩稿叧鐨勭被 */ @@ -8,6 +9,7 @@ this.L = options.L this.tileLayersMap = new Map() this.tileLayersArray = [] + this.mapConfig = {} } /** @@ -15,6 +17,16 @@ */ 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) } /** @@ -22,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) + } /** @@ -61,24 +77,34 @@ * @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) - } - this.tileLayersMap.put(options.name, layer) - this.tileLayersArray.push(layer) - } + 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) + } + } + /** + * 闅愯棌鏈嶅姟鍥惧眰 + * @param {*} name + */ hideTileLayer(name){ if(this.tileLayersMap){ let tileLayer = this.tileLayersMap.get(name) @@ -86,6 +112,9 @@ } } + /** + * 鑾峰彇鎵�鏈夌殑鏈嶅姟鍥惧眰 + */ getTileLayers(){ return this.tilelayersArray } -- Gitblit v1.8.0