派生自 wuyushui/SewerAndRainNetwork

wangrui
2020-12-19 44280203af25006efc4b8939b4fc01477041e9b8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/**
 * 创建图层相关的类
 */
import L from 'leaflet'
class ServiceLayerHelper {
    constructor(options){
        this.map = options.map
        this.tileLayersMap = new Map()
        this.tileLayersArray = []
    }
 
    /**
     * 往地图中加入一个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