forked from SuperMap/iClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapBase.js
More file actions
87 lines (74 loc) · 2.53 KB
/
MapBase.js
File metadata and controls
87 lines (74 loc) · 2.53 KB
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
export function createMapClassExtending(SuperClass = class {}) {
return class MapBase extends SuperClass {
constructor() {
super();
this._sourceListModel = null;
this._legendList = [];
}
initializeMap() {
throw new Error('initializeMap is not implemented');
}
clean() {
throw new Error('clean is not implemented');
}
getLayerCatalog() {
return (this._sourceListModel && this._sourceListModel.getLayerCatalog()) || [];
}
getLayers() {
return (this._sourceListModel && this._sourceListModel.getLayers()) || [];
}
getLegends() {
return this._legendList;
}
getSelfAppreciableLayers() {
return (this._sourceListModel && this._sourceListModel.getSelfLayers(...arguments)) || [];
}
setLayersVisible() {
this._sourceListModel && this._sourceListModel.setLayersVisible(...arguments);
}
toggleLayerVisible() {
this._sourceListModel && this._sourceListModel.toggleLayerVisible(...arguments);
}
rectifyLayersOrder(appreciableLayers, topLayerBeforeId) {
const renderLayers = appreciableLayers
.filter((item) => !item.reused)
.reduce((layers, layer) => {
return layers.concat(layer.renderLayers);
}, []);
const exsitLayers = renderLayers.filter((layerId) => !!this.map.getLayer(layerId));
for (let index = exsitLayers.length - 1; index > -1; index--) {
const targetlayerId = exsitLayers[index];
const afterLayers = exsitLayers.slice(index + 1);
let beforLayerId = afterLayers.find((id) => this.map.style._layers[id]);
if (!afterLayers.length) {
beforLayerId = topLayerBeforeId;
}
this.map.moveLayer(targetlayerId, beforLayerId);
}
return exsitLayers;
}
echartsLayerResize() {}
updateOverlayLayer() {}
copyLayer() {}
cleanLayers(layers) {
const sourceList = [];
for (const item of layers) {
item.renderLayers.forEach((layerId) => {
const layer = this.map.getLayer(layerId);
if (layer) {
this.map.removeLayer(layerId);
if (!item.l7Layer && layer.source && typeof layer.source === 'string') {
sourceList.push(layer.source);
}
}
});
if (this.map.getSource(item.renderSource.id) && !item.l7Layer) {
sourceList.push(item.renderSource.id);
}
}
Array.from(new Set(sourceList)).forEach((sourceId) => {
this.map.removeSource(sourceId);
});
}
};
}