Skip to content

Commit 36b9900

Browse files
2 parents f26d15f + f9c31ec commit 36b9900

19 files changed

+1377
-340
lines changed

src/common/mapping/MapBase.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function createMapClassExtending(SuperClass = class {}) {
1515
}
1616

1717
getLayerCatalog() {
18-
return (this._sourceListModel && this._sourceListModel.getSourceList()) || [];
18+
return (this._sourceListModel && this._sourceListModel.getLayerCatalog()) || [];
1919
}
2020

2121
getLayers() {
@@ -30,6 +30,14 @@ export function createMapClassExtending(SuperClass = class {}) {
3030
return (this._sourceListModel && this._sourceListModel.getSelfLayers(appreciableLayers)) || [];
3131
}
3232

33+
setLayersVisible(layers, visibility) {
34+
this._sourceListModel && this._sourceListModel.setLayersVisible(layers, visibility);
35+
}
36+
37+
toggleLayerVisible(layerId, visible) {
38+
this._sourceListModel && this._sourceListModel.toggleLayerVisible(layerId, visible);
39+
}
40+
3341
echartsLayerResize() {}
3442

3543
updateOverlayLayer() {}

src/common/mapping/MapStyle.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,12 @@ export function createMapStyleExtending(SuperClass, { MapManager, mapRepo }) {
6262

6363
clean(removeMap = true) {
6464
if (this.map) {
65+
if (this._sourceListModel) {
66+
this._sourceListModel.destroy();
67+
this._sourceListModel = null;
68+
}
6569
removeMap && this.map.remove();
6670
this.map = null;
67-
this._sourceListModel = null;
6871
}
6972
}
7073

@@ -156,6 +159,11 @@ export function createMapStyleExtending(SuperClass, { MapManager, mapRepo }) {
156159
layers: layersFromStyle,
157160
appendLayers: this._appendLayers
158161
});
162+
this._sourceListModel.on({
163+
layerupdatechanged: (params) => {
164+
this.fire('layerupdatechanged', params);
165+
}
166+
});
159167
this.fire('mapcreatesucceeded', {
160168
map: this.map,
161169
mapparams: { title: this.mapOptions.name, description: '' },

src/common/mapping/WebMapBase.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@
155155
*/
156156
'projectionnotmatch',
157157
'layeraddchanged',
158+
'layerupdatechanged',
158159
/**
159160
* @event WebMapBase#mapbeforeremove
160161
* @description 地图销毁前。
@@ -391,6 +392,21 @@
391392
return (this._handler && this._handler.getLayerCatalog()) || [];
392393
}
393394

395+
setLayersVisible(layers, visibility) {
396+
this._handler && this._handler.setLayersVisible(layers, visibility);
397+
}
398+
399+
/**
400+
* @version 11.2.1
401+
* @function WebMapBase.prototype.toggleLayerVisible
402+
* @param {string} layerId - 图层 id。
403+
* @param {boolean} visible - 图层是否可见。true 表示显示,false 表示隐藏。
404+
* @description 设置图层显隐。
405+
*/
406+
toggleLayerVisible(layerId, visible) {
407+
this._handler && this._handler.toggleLayerVisible(layerId, visible);
408+
}
409+
394410
/**
395411
* @version 11.3.0
396412
* @function WebMapBase.prototype.getWebMapType

src/common/mapping/WebMapV2.js

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,14 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
5252

5353
clean(removeMap = true) {
5454
if (this.map) {
55+
if (this._sourceListModel) {
56+
this._sourceListModel.destroy();
57+
this._sourceListModel = null;
58+
}
5559
this.stopCanvg();
5660
removeMap && this.map.remove();
5761
this.map = null;
5862
this._legendList = [];
59-
this._sourceListModel = null;
6063
this.center = null;
6164
this.zoom = null;
6265
if (this._dataflowService) {
@@ -2229,6 +2232,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
22292232
_sendMapToUser(count, layersLen) {
22302233
if (count === layersLen) {
22312234
this.addLayersSucceededLen = this._cacheLayerId.size;
2235+
this._changeSourceListModel();
22322236
const appreciableLayers = this.getLayers();
22332237
const layerOptions = this._getSelfAppreciableLayers(appreciableLayers);
22342238
this._rectifyLayersOrder(layerOptions.layers);
@@ -2772,41 +2776,14 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
27722776
const matchInsertIndex = matchIndex < 0 ? renderLayerList.length : matchIndex;
27732777
renderLayerList.splice(matchInsertIndex, 0, ...renderLayers);
27742778
}
2775-
const layersFromMapInfo = [];
2776-
const layerList = [this._mapInfo.baseLayer].concat(this._mapInfo.layers);
2777-
if (this._graticuleLayer) {
2778-
const { id: layerID, visible } = this._graticuleLayer;
2779-
layerList.push({ layerID, visible, name: 'GraticuleLayer' });
2780-
}
2781-
// this._mapInfo.layers 是有序的
2782-
layerList.forEach((layerInfo) => {
2783-
const targetLayerId = layerInfo.layerID || layerInfo.name;
2784-
const targetLayerVisible =
2785-
layerInfo.visible === void 0 || layerInfo.visible === 'visible' || layerInfo.visible === true;
2786-
const matchLayers = this._cacheLayerId.get(targetLayerId);
2787-
if (matchLayers) {
2788-
const renderLayers = matchLayers.map((item) => item.layerId);
2789-
if (!renderLayers.length) {
2790-
return;
2791-
}
2792-
layersFromMapInfo.push({
2793-
...layerInfo,
2794-
id: targetLayerId,
2795-
visible: targetLayerVisible,
2796-
renderLayers,
2797-
reused: matchLayers.some((item) => item.reused)
2798-
});
2799-
}
2800-
});
2801-
this._changeSourceListModel(layersFromMapInfo);
2802-
const appreciableLayers = this.getLayers();
2803-
if (this.addLayersSucceededLen && this._cacheLayerId.size !== this.addLayersSucceededLen) {
2779+
if (this.addLayersSucceededLen && this._cacheLayerId.size <= this.expectLayerLen) {
2780+
this._changeSourceListModel();
2781+
const appreciableLayers = this.getLayers();
28042782
const selfAppreciableLayers = this.getSelfAppreciableLayers(appreciableLayers);
28052783
const topLayerBeforeId = this._findTopLayerBeforeId(selfAppreciableLayers);
28062784
this._rectifyLayersOrder(selfAppreciableLayers, topLayerBeforeId);
2807-
this.addLayersSucceededLen = this._cacheLayerId.size;
2785+
this.fire('layeraddchanged', this._getSelfAppreciableLayers(appreciableLayers));
28082786
}
2809-
this.fire('layeraddchanged', this._getSelfAppreciableLayers(appreciableLayers));
28102787
}
28112788

28122789
_findTopLayerBeforeId(selfAppreciableLayers) {
@@ -2831,22 +2808,53 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
28312808
}
28322809
}
28332810

2834-
_changeSourceListModel(layersFromMapInfo) {
2811+
_changeSourceListModel() {
2812+
const layersFromMapInfo = [];
2813+
const layerList = [this._mapInfo.baseLayer].concat(this._mapInfo.layers);
2814+
if (this._graticuleLayer) {
2815+
const { id: layerID, visible } = this._graticuleLayer;
2816+
layerList.push({ layerID, visible, name: 'GraticuleLayer' });
2817+
}
2818+
// this._mapInfo.layers 是有序的
2819+
layerList.forEach((layerInfo) => {
2820+
const targetLayerId = layerInfo.layerID || layerInfo.name;
2821+
const targetLayerVisible =
2822+
layerInfo.visible === void 0 || layerInfo.visible === 'visible' || layerInfo.visible === true;
2823+
const matchLayers = this._cacheLayerId.get(targetLayerId);
2824+
if (matchLayers) {
2825+
const renderLayers = matchLayers.map((item) => item.layerId);
2826+
if (!renderLayers.length) {
2827+
return;
2828+
}
2829+
layersFromMapInfo.push({
2830+
...layerInfo,
2831+
id: targetLayerId,
2832+
visible: targetLayerVisible,
2833+
renderLayers,
2834+
reused: matchLayers.some((item) => item.reused)
2835+
});
2836+
}
2837+
});
28352838
if (!this._sourceListModel) {
28362839
this._sourceListModel = new SourceListModelV2({
28372840
map: this.map,
28382841
layers: layersFromMapInfo,
28392842
appendLayers: this._appendLayers
28402843
});
2841-
} else {
2842-
this._sourceListModel.setSelfLayers(layersFromMapInfo);
2844+
this._sourceListModel.on({
2845+
layerupdatechanged: (params) => {
2846+
this.fire('layerupdatechanged', params);
2847+
}
2848+
});
2849+
return;
28432850
}
2851+
this._sourceListModel.setSelfLayers(layersFromMapInfo);
28442852
}
28452853

28462854
_getSelfAppreciableLayers(appreciableLayers) {
28472855
return {
28482856
layers: this.getSelfAppreciableLayers(appreciableLayers),
2849-
allLoaded: this._cacheLayerId.size === this.addLayersSucceededLen
2857+
allLoaded: this._cacheLayerId.size === this.expectLayerLen
28502858
};
28512859
}
28522860

src/common/mapping/WebMapV3.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, mapRe
205205

206206
clean(removeMap = true) {
207207
if (this.map) {
208+
if (this._sourceListModel) {
209+
this._sourceListModel.destroy();
210+
this._sourceListModel = null;
211+
}
208212
if (removeMap) {
209213
const scene = this.map.$l7scene;
210214
scene && scene.removeAllLayer();
@@ -614,6 +618,11 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, mapRe
614618
legendList: this._legendList,
615619
l7LayerUtil
616620
});
621+
this._sourceListModel.on({
622+
layerupdatechanged: (params) => {
623+
this.fire('layerupdatechanged', params);
624+
}
625+
});
617626
this.fire('mapcreatesucceeded', { map: this.map, mapparams: this.mapParams, layers: this.getSelfAppreciableLayers() });
618627
}
619628

0 commit comments

Comments
 (0)