派生自 wuyushui/SewerAndRainNetwork

wangrui
2020-12-19 02d584c8d0f31b56f24e367681aa034cd2acf0e9
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* eslint-disable no-debugger */
import AjaxUtils from '@/utils/AjaxUtils'
/**
 * 底图管理助手,负责底图创建及开关
 */
class BasemapHelper{
    constructor(options) {
        this.map = options.map
        this.L = options.L
        this.basemapList = []
        this.basemapMap = new Map()
        this.basemapLayerGroup = options.L.layerGroup().addTo(options.map)
    }
 
    /**
     * 该方法负责各种底图加载到地图上
     * @param map
     * @param defBasemapName 初始化完成后,默认显示的图层
     */
    initBasemap = (mapConfig, isIntranet) => {
        debugger
        if(isIntranet) {
            this._getToken(mapConfig); // 获取token,并按配置加载地图
        }else {
            this._createBasemapByConfig(mapConfig)
        }
 
        return this.basemapMap
    }
 
    /**
     * 获取所有的底图列表
     * @returns {null} 结构:[{名称, 图层引用}]
     */
    getBasemapList = (map) => {
        console.log(map)
        return null
    }
 
    /**
     * 通过名称获取底图对象
     * @param map 结构:[{名称, 图层引用}]
     * @param name 名称
     */
    getBasemap = (map, name) => {
        console.log(map, name)
    }
 
    /**
     * 显示某个图层
     * @param map 地图对象
     * @param layer 待显示图层引用
     * @param isHideOthers 是否先关闭其他图层,默认是true
     */
    showBasemap = (map, layer, isHideOthers) => {
        console.log(map, layer, isHideOthers)
    }
 
    /**
     * 隐藏某个图层
     * @param map 地图对象
     * @param layer 待关闭图层引用
     */
    hideBasemap = (map, layer) => {
        console.log(map, layer)
    }
 
    // 公网创建地图部分
    _createBasemapByConfig(mapConfig){
        console.log(mapConfig)
        let internetBasemaps = mapConfig.mapConfig.InternetBaseMaps
        for(let i = 0, len = internetBasemaps.length; i < len; ++i) {
            let basemapConfig = internetBasemaps[i]
            let basemapLayer = this.L.tileLayer(basemapConfig.map.url, basemapConfig.map.options)
            let basemapAnnotationLayer = this.L.tileLayer(basemapConfig.annotation.url, basemapConfig.annotation.options)
 
            let basemap = {
                code: basemapConfig.code,
                name: basemapConfig.name,
                layer: basemapLayer,
                annotation: basemapAnnotationLayer
            }
         
            this.basemapList.push(basemap);
            this.basemapMap.set(basemapConfig.code, basemap)
            if(typeof basemapConfig.isAddToMap !== 'undefined' && basemapConfig.isAddToMap) {
                this.basemapLayerGroup.addLayer(basemapLayer)
                this.basemapLayerGroup.addLayer(basemapAnnotationLayer)
            }
        }
    }
 
    // 内网地图创建部分
    // 获取内网地图token,并加载到地图中
    _getToken = (mapConfig) => {
        let params = mapConfig.TokenConfig
        AjaxUtils.GetDataAsynByUrl(params.url, params.option, (token) => {
            this._showTDT(token, mapConfig)
        })
    }
 
    // 内网地图加载,并加载到地图
    _showTDT = (token, mapConfig) => {
        let intranetBasemaps = mapConfig.mapConfig.IntranetBaseMaps
        for(let i = 0, len = intranetBasemaps.length; i < len; ++i) {
            let basemapConfig = intranetBasemaps[i]
            let basemapLayer = this.L.tileLayer(basemapConfig.map.url, basemapConfig.map.options)
            let basemapAnnotationLayer = this.L.tileLayer(basemapConfig.annotation.url, basemapConfig.annotation.options)
 
            let basemap = {
                code: basemapConfig.code,
                name: basemapConfig.name,
                layer: basemapLayer,
                annotation: basemapAnnotationLayer
            }
         
            this.basemapList.push(basemap);
            this.basemapMap.set(basemapConfig.code, basemap)
            if(typeof basemapConfig.isAddToMap !== 'undefined' && basemapConfig.isAddToMap) {
                this.basemapLayerGroup.addLayer(basemapLayer)
                this.basemapLayerGroup.addLayer(basemapAnnotationLayer)
            }
        }
    }
}
 
export default BasemapHelper