| | |
| | | this.map = options.map |
| | | this.L = options.L |
| | | this.tileLayersMap = new Map() |
| | | this.tileLayersArray = [] |
| | | this.tileLayersWMSArray = [] |
| | | this.tileLayersWMTSArray = [] |
| | | this.tileLayersTileArray = [] |
| | | this.mapConfig = {} |
| | | } |
| | | |
| | |
| | | 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]) |
| | | } |
| | | } |
| | | } |
| | |
| | | * @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) |
| | | } |
| | | /** |
| | | * 往地图中加入一个WMS服务 |
| | | * @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) |
| | | } |
| | | |
| | | /** |
| | |
| | | * @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", |
| | |
| | | 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) |
| | | } |
| | | /** |
| | | * 隐藏服务图层 |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取所有的服务图层 |
| | | * 获取所有的TILE服务图层 |
| | | */ |
| | | getTileLayers(){ |
| | | return this.tilelayersArray |
| | | return this.tileLayersTileArray |
| | | } |
| | | /** |
| | | * 获取所有的WMTS服务图层 |
| | | */ |
| | | getWmtsLayers(){ |
| | | return this.tileLayersWMTSArray |
| | | } |
| | | /** |
| | | * 获取所有的WMS服务图层 |
| | | */ |
| | | getWmsLayers(){ |
| | | return this.tileLayersWMSArray |
| | | } |
| | | |
| | | /** |
| | | * 通过code查找WMS的服务配置 |
| | | * @param {} code wms服务配置的code |
| | | */ |
| | | 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 |