Skip to content

Commit

Permalink
【feature】webmap checksamelayer 可感知图层优化
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongjiaojiao committed Aug 28, 2024
1 parent a3ed852 commit 221bfa3
Show file tree
Hide file tree
Showing 10 changed files with 449 additions and 185 deletions.
3 changes: 2 additions & 1 deletion src/common/mapping/WebMapBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,8 @@
return;
}
const sourceList = [];
for (const item of this._cacheCleanLayers) {
const layersToClean = this._cacheCleanLayers.filter(item => !item.reused);
for (const item of layersToClean) {
item.renderLayers.forEach((layerId) => {
if (this.map.getLayer(layerId)) {
this.map.removeLayer(layerId);
Expand Down
23 changes: 9 additions & 14 deletions src/common/mapping/WebMapV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
this._appendLayers = false;
}

/**
* @private
* @function WebMapV2.prototype.initializeMap
* @description 登陆窗口后添加地图图层。
* @param {Object} mapInfo - map 信息。
*/
initializeMap(mapInfo, map) {
if (map) {
this._appendLayers = true;
Expand Down Expand Up @@ -2226,7 +2220,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
}

_rectifyLayersOrder(appreciableLayers, topLayerBeforeId) {
const renderLayers = appreciableLayers.reduce((layers, layer) => {
const renderLayers = appreciableLayers.filter(item => !item.reused).reduce((layers, layer) => {
return layers.concat(layer.renderLayers);
}, []);
const labelLayerIds = [];
Expand Down Expand Up @@ -2726,7 +2720,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
const { id } = layerInfo;
if (this.map.getLayer(id)) {
if (this.checkSameLayer && this._isSameRasterLayer(id, layerInfo)) {
this._setCacheLayer({ layerInfo, parentLayerId, id, ignore: true, beforeId });
this._setCacheLayer({ layerInfo, parentLayerId, id, reused: true, beforeId });
return;
}
this._updateLayer(layerInfo);
Expand All @@ -2737,8 +2731,8 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
this._setCacheLayer({ layerInfo, parentLayerId, id, beforeId });
}

_setCacheLayer({ parentLayerId, layerInfo, ignore = false, beforeId, subRenderLayers }) {
const renderLayers = subRenderLayers || [{ layerId: layerInfo.id, ignore }];
_setCacheLayer({ parentLayerId, layerInfo, reused = false, beforeId, subRenderLayers }) {
const renderLayers = subRenderLayers || [{ layerId: layerInfo.id, reused }];
if (!this._cacheLayerId.has(parentLayerId)) {
this._cacheLayerId.set(parentLayerId, renderLayers);
} else {
Expand All @@ -2763,22 +2757,23 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
layerInfo.visible === void 0 || layerInfo.visible === 'visible' || layerInfo.visible === true;
const matchLayers = this._cacheLayerId.get(targetLayerId);
if (matchLayers) {
const renderLayers = matchLayers.filter((item) => !item.ignore).map((item) => item.layerId);
const renderLayers = matchLayers.map((item) => item.layerId);
if (!renderLayers.length) {
return;
}
layersFromMapInfo.push({
...layerInfo,
id: targetLayerId,
visible: targetLayerVisible,
renderLayers
renderLayers,
reused: matchLayers.some(item => item.reused) || void 0
});
}
});
this._changeSourceListModel(layersFromMapInfo);
const appreciableLayers = this.getLayers();
if (this.addLayersSucceededLen && this._cacheLayerId.size !== this.addLayersSucceededLen) {
const selfAppreciableLayers = this.getSelfAppreciableLayers(appreciableLayers)
const selfAppreciableLayers = this.getSelfAppreciableLayers(appreciableLayers);
const topLayerBeforeId = this._findTopLayerBeforeId(selfAppreciableLayers);
this._rectifyLayersOrder(selfAppreciableLayers, topLayerBeforeId);
this.addLayersSucceededLen = this._cacheLayerId.size;
Expand All @@ -2788,7 +2783,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {

_findTopLayerBeforeId(selfAppreciableLayers) {
// fix 追加图层,异步的图层回来排序错乱
const selfLayerIds = selfAppreciableLayers.reduce((ids, item) => ids.concat(item.renderLayers), []);
const selfLayerIds = selfAppreciableLayers.filter(item => !item.reused).reduce((ids, item) => ids.concat(item.renderLayers), []);
const firstSelfLayerIdOnMap = selfLayerIds.find((id) => this.map.style._layers[id]);
if (!firstSelfLayerIdOnMap) {
return;
Expand Down
6 changes: 5 additions & 1 deletion src/common/mapping/utils/AppreciableLayerBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ export class AppreciableLayerBase {
title = name,
visible = layer.visibility ? layer.visibility === 'visible' : true,
CLASS_NAME,
CLASS_INSTANCE
CLASS_INSTANCE,
reused
} = layerInfo;
const sourceOnMap = this.map.getSource(layer.source);
const fields = {
Expand All @@ -179,6 +180,9 @@ export class AppreciableLayerBase {
if (CLASS_INSTANCE) {
fields.CLASS_INSTANCE = CLASS_INSTANCE;
}
if (reused !== void 0) {
fields.reused = reused;
}
return fields;
}
}
3 changes: 3 additions & 0 deletions src/common/mapping/utils/SourceModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ class SourceModel {
this.type = options.type;
this.themeSetting = options.themeSetting;
this.visible = options.visible;
if (options.reused) {
this.reused = options.reused;
}
}

addLayer(layer) {
Expand Down
Loading

0 comments on commit 221bfa3

Please sign in to comment.