Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
xilanhuaweidapao committed Sep 18, 2024
2 parents f26d15f + f9c31ec commit 36b9900
Show file tree
Hide file tree
Showing 19 changed files with 1,377 additions and 340 deletions.
10 changes: 9 additions & 1 deletion src/common/mapping/MapBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function createMapClassExtending(SuperClass = class {}) {
}

getLayerCatalog() {
return (this._sourceListModel && this._sourceListModel.getSourceList()) || [];
return (this._sourceListModel && this._sourceListModel.getLayerCatalog()) || [];
}

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

setLayersVisible(layers, visibility) {
this._sourceListModel && this._sourceListModel.setLayersVisible(layers, visibility);
}

toggleLayerVisible(layerId, visible) {
this._sourceListModel && this._sourceListModel.toggleLayerVisible(layerId, visible);
}

echartsLayerResize() {}

updateOverlayLayer() {}
Expand Down
10 changes: 9 additions & 1 deletion src/common/mapping/MapStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,12 @@ export function createMapStyleExtending(SuperClass, { MapManager, mapRepo }) {

clean(removeMap = true) {
if (this.map) {
if (this._sourceListModel) {
this._sourceListModel.destroy();
this._sourceListModel = null;
}
removeMap && this.map.remove();
this.map = null;
this._sourceListModel = null;
}
}

Expand Down Expand Up @@ -156,6 +159,11 @@ export function createMapStyleExtending(SuperClass, { MapManager, mapRepo }) {
layers: layersFromStyle,
appendLayers: this._appendLayers
});
this._sourceListModel.on({
layerupdatechanged: (params) => {
this.fire('layerupdatechanged', params);
}
});
this.fire('mapcreatesucceeded', {
map: this.map,
mapparams: { title: this.mapOptions.name, description: '' },
Expand Down
16 changes: 16 additions & 0 deletions src/common/mapping/WebMapBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
*/
'projectionnotmatch',
'layeraddchanged',
'layerupdatechanged',
/**
* @event WebMapBase#mapbeforeremove
* @description 地图销毁前。
Expand Down Expand Up @@ -391,6 +392,21 @@
return (this._handler && this._handler.getLayerCatalog()) || [];
}

setLayersVisible(layers, visibility) {
this._handler && this._handler.setLayersVisible(layers, visibility);
}

/**
* @version 11.2.1
* @function WebMapBase.prototype.toggleLayerVisible
* @param {string} layerId - 图层 id。
* @param {boolean} visible - 图层是否可见。true 表示显示,false 表示隐藏。
* @description 设置图层显隐。
*/
toggleLayerVisible(layerId, visible) {
this._handler && this._handler.toggleLayerVisible(layerId, visible);
}

/**
* @version 11.3.0
* @function WebMapBase.prototype.getWebMapType
Expand Down
80 changes: 44 additions & 36 deletions src/common/mapping/WebMapV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,14 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {

clean(removeMap = true) {
if (this.map) {
if (this._sourceListModel) {
this._sourceListModel.destroy();
this._sourceListModel = null;
}
this.stopCanvg();
removeMap && this.map.remove();
this.map = null;
this._legendList = [];
this._sourceListModel = null;
this.center = null;
this.zoom = null;
if (this._dataflowService) {
Expand Down Expand Up @@ -2229,6 +2232,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
_sendMapToUser(count, layersLen) {
if (count === layersLen) {
this.addLayersSucceededLen = this._cacheLayerId.size;
this._changeSourceListModel();
const appreciableLayers = this.getLayers();
const layerOptions = this._getSelfAppreciableLayers(appreciableLayers);
this._rectifyLayersOrder(layerOptions.layers);
Expand Down Expand Up @@ -2772,41 +2776,14 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
const matchInsertIndex = matchIndex < 0 ? renderLayerList.length : matchIndex;
renderLayerList.splice(matchInsertIndex, 0, ...renderLayers);
}
const layersFromMapInfo = [];
const layerList = [this._mapInfo.baseLayer].concat(this._mapInfo.layers);
if (this._graticuleLayer) {
const { id: layerID, visible } = this._graticuleLayer;
layerList.push({ layerID, visible, name: 'GraticuleLayer' });
}
// this._mapInfo.layers 是有序的
layerList.forEach((layerInfo) => {
const targetLayerId = layerInfo.layerID || layerInfo.name;
const targetLayerVisible =
layerInfo.visible === void 0 || layerInfo.visible === 'visible' || layerInfo.visible === true;
const matchLayers = this._cacheLayerId.get(targetLayerId);
if (matchLayers) {
const renderLayers = matchLayers.map((item) => item.layerId);
if (!renderLayers.length) {
return;
}
layersFromMapInfo.push({
...layerInfo,
id: targetLayerId,
visible: targetLayerVisible,
renderLayers,
reused: matchLayers.some((item) => item.reused)
});
}
});
this._changeSourceListModel(layersFromMapInfo);
const appreciableLayers = this.getLayers();
if (this.addLayersSucceededLen && this._cacheLayerId.size !== this.addLayersSucceededLen) {
if (this.addLayersSucceededLen && this._cacheLayerId.size <= this.expectLayerLen) {
this._changeSourceListModel();
const appreciableLayers = this.getLayers();
const selfAppreciableLayers = this.getSelfAppreciableLayers(appreciableLayers);
const topLayerBeforeId = this._findTopLayerBeforeId(selfAppreciableLayers);
this._rectifyLayersOrder(selfAppreciableLayers, topLayerBeforeId);
this.addLayersSucceededLen = this._cacheLayerId.size;
this.fire('layeraddchanged', this._getSelfAppreciableLayers(appreciableLayers));
}
this.fire('layeraddchanged', this._getSelfAppreciableLayers(appreciableLayers));
}

_findTopLayerBeforeId(selfAppreciableLayers) {
Expand All @@ -2831,22 +2808,53 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
}
}

_changeSourceListModel(layersFromMapInfo) {
_changeSourceListModel() {
const layersFromMapInfo = [];
const layerList = [this._mapInfo.baseLayer].concat(this._mapInfo.layers);
if (this._graticuleLayer) {
const { id: layerID, visible } = this._graticuleLayer;
layerList.push({ layerID, visible, name: 'GraticuleLayer' });
}
// this._mapInfo.layers 是有序的
layerList.forEach((layerInfo) => {
const targetLayerId = layerInfo.layerID || layerInfo.name;
const targetLayerVisible =
layerInfo.visible === void 0 || layerInfo.visible === 'visible' || layerInfo.visible === true;
const matchLayers = this._cacheLayerId.get(targetLayerId);
if (matchLayers) {
const renderLayers = matchLayers.map((item) => item.layerId);
if (!renderLayers.length) {
return;
}
layersFromMapInfo.push({
...layerInfo,
id: targetLayerId,
visible: targetLayerVisible,
renderLayers,
reused: matchLayers.some((item) => item.reused)
});
}
});
if (!this._sourceListModel) {
this._sourceListModel = new SourceListModelV2({
map: this.map,
layers: layersFromMapInfo,
appendLayers: this._appendLayers
});
} else {
this._sourceListModel.setSelfLayers(layersFromMapInfo);
this._sourceListModel.on({
layerupdatechanged: (params) => {
this.fire('layerupdatechanged', params);
}
});
return;
}
this._sourceListModel.setSelfLayers(layersFromMapInfo);
}

_getSelfAppreciableLayers(appreciableLayers) {
return {
layers: this.getSelfAppreciableLayers(appreciableLayers),
allLoaded: this._cacheLayerId.size === this.addLayersSucceededLen
allLoaded: this._cacheLayerId.size === this.expectLayerLen
};
}

Expand Down
9 changes: 9 additions & 0 deletions src/common/mapping/WebMapV3.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, mapRe

clean(removeMap = true) {
if (this.map) {
if (this._sourceListModel) {
this._sourceListModel.destroy();
this._sourceListModel = null;
}
if (removeMap) {
const scene = this.map.$l7scene;
scene && scene.removeAllLayer();
Expand Down Expand Up @@ -614,6 +618,11 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, mapRe
legendList: this._legendList,
l7LayerUtil
});
this._sourceListModel.on({
layerupdatechanged: (params) => {
this.fire('layerupdatechanged', params);
}
});
this.fire('mapcreatesucceeded', { map: this.map, mapparams: this.mapParams, layers: this.getSelfAppreciableLayers() });
}

Expand Down
Loading

0 comments on commit 36b9900

Please sign in to comment.