Skip to content

Commit b652915

Browse files
committed
【feature】图层列表排序优化;webmap cleanLayers 优化
1 parent 8ef50b7 commit b652915

File tree

15 files changed

+389
-112
lines changed

15 files changed

+389
-112
lines changed

src/common/mapping/MapBase.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,25 @@ export function createMapClassExtending(SuperClass = class {}) {
6262
updateOverlayLayer() {}
6363

6464
copyLayer() {}
65+
66+
cleanLayers(layers) {
67+
const sourceList = [];
68+
for (const item of layers) {
69+
item.renderLayers.forEach((layerId) => {
70+
if (this.map.getLayer(layerId)) {
71+
this.map.removeLayer(layerId);
72+
if (!item.l7Layer && this.map.getSource(layerId)) {
73+
sourceList.push(layerId);
74+
}
75+
}
76+
});
77+
if (this.map.getSource(item.renderSource.id) && !item.l7Layer) {
78+
sourceList.push(item.renderSource.id);
79+
}
80+
}
81+
Array.from(new Set(sourceList)).forEach((sourceId) => {
82+
this.map.removeSource(sourceId);
83+
});
84+
}
6585
};
6686
}

src/common/mapping/WebMapBase.js

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -488,21 +488,8 @@ export function createWebMapBaseExtending(SuperClass, { mapRepo }) {
488488
if (!this.map) {
489489
return;
490490
}
491-
const sourceList = [];
492-
const layersToClean = this._cacheCleanLayers.filter((item) => !item.reused);
493-
for (const item of layersToClean) {
494-
item.renderLayers.forEach((layerId) => {
495-
if (this.map.getLayer(layerId)) {
496-
this.map.removeLayer(layerId);
497-
}
498-
});
499-
if (this.map.getSource(item.renderSource.id) && !item.l7Layer) {
500-
sourceList.push(item.renderSource.id);
501-
}
502-
}
503-
Array.from(new Set(sourceList)).forEach((sourceId) => {
504-
this.map.removeSource(sourceId);
505-
});
491+
const layersToClean = this._cacheCleanLayers.filter(item => !item.reused);
492+
this._handler && this._handler.cleanLayers(layersToClean);
506493
this._cacheCleanLayers = [];
507494
this.clean(false);
508495
}

src/common/mapping/WebMapV2.js

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
5050
this._getMapInfo(mapInfo, this._taskID);
5151
}
5252

53+
cleanLayers(layers) {
54+
super.cleanLayers(layers);
55+
this.echartslayer.forEach(echartLayer => {
56+
echartLayer.remove();
57+
});
58+
}
59+
5360
clean(removeMap = true) {
5461
if (this.map) {
5562
if (this._sourceListModel) {
@@ -320,7 +327,6 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
320327
},
321328
fadeDuration: 0
322329
});
323-
window.map = this.map;
324330
this.fire('mapinitialized', { map: this.map });
325331
}
326332

@@ -522,7 +528,8 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
522528
this.map.addLayer(graticuleLayer);
523529
this._setCacheLayer({
524530
parentLayerId: graticuleLayer.id,
525-
subRenderLayers: [{ layerId: graticuleLayer.id }, { layerId: graticuleLayer.sourceId }]
531+
subRenderLayers: [{ layerId: graticuleLayer.id }, { layerId: graticuleLayer.sourceId }],
532+
metadata: { SM_Layer_Order: 'Top' }
526533
});
527534
this._addLayerSucceeded();
528535
}
@@ -1072,7 +1079,8 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
10721079
echartslayer.chart._dom.style.display = 'none';
10731080
}
10741081
}
1075-
}
1082+
},
1083+
metadata: { SM_Layer_Order: 'top' }
10761084
});
10771085
this._addLayerSucceeded({ layerInfo, features });
10781086
}
@@ -2755,23 +2763,25 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
27552763
this._updateLayer(layerInfo);
27562764
return;
27572765
}
2758-
const nextLayerInfo = Object.assign(layerInfo, { metadata: { parentLayerId } });
2766+
const nextLayerInfo = Object.assign({}, layerInfo);
2767+
nextLayerInfo.metadata = Object.assign({}, nextLayerInfo.metadata, { SM_Layer_Id: parentLayerId })
27592768
this.map.addLayer(nextLayerInfo);
27602769
this._setCacheLayer({ layerInfo, parentLayerId, id, beforeId });
27612770
}
27622771

2763-
_setCacheLayer({ parentLayerId, layerInfo, reused = false, beforeId, subRenderLayers }) {
2772+
_setCacheLayer({ parentLayerId, layerInfo, reused = false, beforeId, subRenderLayers, metadata }) {
27642773
const renderLayers = subRenderLayers || [{ layerId: layerInfo.id, reused }];
27652774
if (!this._cacheLayerId.has(parentLayerId)) {
2766-
this._cacheLayerId.set(parentLayerId, renderLayers);
2775+
const metadataInfo = Object.assign({}, metadata || layerInfo && layerInfo.metadata, { SM_Layer_Id: parentLayerId });
2776+
this._cacheLayerId.set(parentLayerId, { renderLayers, metadata: metadataInfo });
27672777
} else {
2768-
const renderLayerList = this._cacheLayerId.get(parentLayerId);
2778+
const layerCacheData = this._cacheLayerId.get(parentLayerId);
27692779
let matchIndex = -1;
27702780
if (beforeId) {
2771-
matchIndex = renderLayerList.findIndex((item) => item.layerId === beforeId);
2781+
matchIndex = layerCacheData.renderLayers.findIndex((item) => item.layerId === beforeId);
27722782
}
2773-
const matchInsertIndex = matchIndex < 0 ? renderLayerList.length : matchIndex;
2774-
renderLayerList.splice(matchInsertIndex, 0, ...renderLayers);
2783+
const matchInsertIndex = matchIndex < 0 ? layerCacheData.renderLayers.length : matchIndex;
2784+
layerCacheData.renderLayers.splice(matchInsertIndex, 0, ...renderLayers);
27752785
}
27762786
if (this.addLayersSucceededLen && this._cacheLayerId.size <= this.expectLayerLen) {
27772787
this._changeSourceListModel();
@@ -2817,18 +2827,19 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
28172827
const targetLayerId = layerInfo.layerID || layerInfo.name;
28182828
const targetLayerVisible =
28192829
layerInfo.visible === void 0 || layerInfo.visible === 'visible' || layerInfo.visible === true;
2820-
const matchLayers = this._cacheLayerId.get(targetLayerId);
2821-
if (matchLayers) {
2822-
const renderLayers = matchLayers.map((item) => item.layerId);
2830+
const matchCacheData = this._cacheLayerId.get(targetLayerId);
2831+
if (matchCacheData) {
2832+
const renderLayers = matchCacheData.renderLayers.map((item) => item.layerId);
28232833
if (!renderLayers.length) {
28242834
return;
28252835
}
28262836
layersFromMapInfo.push({
28272837
...layerInfo,
2838+
...matchCacheData,
28282839
id: targetLayerId,
28292840
visible: targetLayerVisible,
28302841
renderLayers,
2831-
reused: matchLayers.some((item) => item.reused)
2842+
reused: matchCacheData.renderLayers.some((item) => item.reused)
28322843
});
28332844
}
28342845
});
@@ -2845,7 +2856,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
28452856
});
28462857
return;
28472858
}
2848-
this._sourceListModel.setSelfLayers(layersFromMapInfo);
2859+
this._sourceListModel.setLayers(layersFromMapInfo);
28492860
}
28502861

28512862
_getSelfAppreciableLayers(appreciableLayers) {

src/common/mapping/WebMapV3.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,6 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, mapRe
173173
this._baseProjection = '';
174174
}
175175

176-
/**
177-
* @function WebMapV3.prototype.initializeMap
178-
* @description 登陆窗口后添加地图图层。
179-
* @param {Object} mapInfo - map 信息。
180-
* @param {Object} map - map 实例。
181-
* @private
182-
*/
183176
initializeMap(mapInfo, map) {
184177
this._mapInfo = mapInfo;
185178
const proj = this._setBaseProjection();
@@ -203,6 +196,14 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, mapRe
203196
this._createMap();
204197
}
205198

199+
cleanLayers(layers) {
200+
super.cleanLayers(layers);
201+
const l7MarkerLayers = l7LayerUtil.getL7MarkerLayers();
202+
for (const layerId in l7MarkerLayers) {
203+
l7LayerUtil.removeL7MarkerLayer(layerId, this.map.$l7scene);
204+
}
205+
}
206+
206207
clean(removeMap = true) {
207208
if (this.map) {
208209
if (this._sourceListModel) {

0 commit comments

Comments
 (0)