/**
|
* 创建图层相关的类
|
*/
|
import L from 'leaflet'
|
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
|
}
|
|
/**
|
* 往地图中加入一个tile服务
|
* @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)
|
}
|
this.tileLayersMap.put(options.name, layer)
|
this.tileLayersArray.push(layer)
|
}
|
/**
|
* 往地图中加入一个WMS服务
|
* @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)
|
}
|
this.tileLayersMap.put(options.name, layer)
|
this.tileLayersArray.push(layer)
|
}
|
|
/**
|
* 往地图中加入一个WMS服务
|
* @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)
|
}
|
|
hideTileLayer(name){
|
if(this.tileLayersMap){
|
let tileLayer = this.tileLayersMap.get(name)
|
this.map.removeLayer(tileLayer)
|
}
|
}
|
|
getTileLayers(){
|
return this.tilelayersArray
|
}
|
}
|
export default ServiceLayerHelper
|