Skip to content

Commit 5851e54

Browse files
committed
[feature]webmap新增排序方法 review by xiongjj
1 parent dd7d869 commit 5851e54

File tree

5 files changed

+78
-15
lines changed

5 files changed

+78
-15
lines changed

src/common/mapping/MapBase.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,25 @@ export function createMapClassExtending(SuperClass = class {}) {
3838
this._sourceListModel && this._sourceListModel.toggleLayerVisible(layerId, visible);
3939
}
4040

41+
rectifyLayersOrder(appreciableLayers, topLayerBeforeId) {
42+
const renderLayers = appreciableLayers
43+
.filter((item) => !item.reused)
44+
.reduce((layers, layer) => {
45+
return layers.concat(layer.renderLayers);
46+
}, []);
47+
const exsitLayers = renderLayers.filter((layerId) => !!this.map.getLayer(layerId));
48+
for (let index = exsitLayers.length - 1; index > -1; index--) {
49+
const targetlayerId = exsitLayers[index];
50+
const afterLayers = exsitLayers.slice(index + 1);
51+
let beforLayerId = afterLayers.find((id) => this.map.style._layers[id]);
52+
if (!afterLayers.length) {
53+
beforLayerId = topLayerBeforeId;
54+
}
55+
this.map.moveLayer(targetlayerId, beforLayerId);
56+
}
57+
return exsitLayers;
58+
}
59+
4160
echartsLayerResize() {}
4261

4362
updateOverlayLayer() {}

src/common/mapping/WebMapBase.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,15 @@
416416
getWebMapType() {
417417
return this.type;
418418
}
419+
420+
/**
421+
* @version 11.3.0
422+
* @function WebMapBase.prototype.rectifyLayersOrder
423+
* @description 根据已知顺序的可感知图层,对地图上图顺序进行排序。
424+
*/
425+
rectifyLayersOrder(appreciableLayers, topLayerBeforeId) {
426+
this._handler && this._handler.rectifyLayersOrder(appreciableLayers, topLayerBeforeId);
427+
}
419428

420429
/**
421430
* @version 11.2.1

src/common/mapping/WebMapV2.js

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2235,7 +2235,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
22352235
this._changeSourceListModel();
22362236
const appreciableLayers = this.getLayers();
22372237
const layerOptions = this._getSelfAppreciableLayers(appreciableLayers);
2238-
this._rectifyLayersOrder(layerOptions.layers);
2238+
this.rectifyLayersOrder(layerOptions.layers);
22392239
this.fire('mapcreatesucceeded', {
22402240
...layerOptions,
22412241
map: this.map,
@@ -2244,22 +2244,11 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
22442244
}
22452245
}
22462246

2247-
_rectifyLayersOrder(appreciableLayers, topLayerBeforeId) {
2248-
const renderLayers = appreciableLayers
2249-
.filter((item) => !item.reused)
2250-
.reduce((layers, layer) => {
2251-
return layers.concat(layer.renderLayers);
2252-
}, []);
2247+
rectifyLayersOrder(appreciableLayers, topLayerBeforeId) {
2248+
const exsitLayers = super.rectifyLayersOrder(appreciableLayers, topLayerBeforeId);
22532249
const labelLayerIds = [];
2254-
const exsitLayers = renderLayers.filter((layerId) => !!this.map.getLayer(layerId));
22552250
for (let index = exsitLayers.length - 1; index > -1; index--) {
22562251
const targetlayerId = exsitLayers[index];
2257-
const afterLayers = exsitLayers.slice(index + 1);
2258-
let beforLayerId = afterLayers.find((id) => this.map.style._layers[id]);
2259-
if (!afterLayers.length) {
2260-
beforLayerId = topLayerBeforeId;
2261-
}
2262-
this.map.moveLayer(targetlayerId, beforLayerId);
22632252
const labelLayerId = this._getSymbolLabelLayerName(targetlayerId);
22642253
if (this.map.getLayer(labelLayerId)) {
22652254
labelLayerIds.push(labelLayerId);
@@ -2781,7 +2770,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) {
27812770
const appreciableLayers = this.getLayers();
27822771
const selfAppreciableLayers = this.getSelfAppreciableLayers(appreciableLayers);
27832772
const topLayerBeforeId = this._findTopLayerBeforeId(selfAppreciableLayers);
2784-
this._rectifyLayersOrder(selfAppreciableLayers, topLayerBeforeId);
2773+
this.rectifyLayersOrder(selfAppreciableLayers, topLayerBeforeId);
27852774
this.fire('layeraddchanged', this._getSelfAppreciableLayers(appreciableLayers));
27862775
}
27872776
}

test/mapboxgl/mapping/WebMapSpec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,4 +1263,27 @@ describe('mapboxgl_WebMap', () => {
12631263
};
12641264
datavizWebmap.once('mapcreatesucceeded', callback);
12651265
});
1266+
1267+
it('rectifyLayersOrder', (done) => {
1268+
const commonOption = {
1269+
server: 'http://fack:8190/iportal/',
1270+
target: 'map',
1271+
withCredentials: false
1272+
};
1273+
datavizWebmap = new WebMap(
1274+
'',
1275+
{ ...commonOption },
1276+
mapOptionsList[0]
1277+
);
1278+
const callback = function ({map}) {
1279+
let layers = datavizWebmap.getLayers();
1280+
expect(layers.length).toBe(2);
1281+
let newLayers = [layers[1], layers[0]];
1282+
datavizWebmap.rectifyLayersOrder(newLayers);
1283+
const layersOnMap = map.getStyle().layers;
1284+
expect(layersOnMap[0].id).toBe('未命名数据')
1285+
done();
1286+
};
1287+
datavizWebmap.once('mapcreatesucceeded', callback);
1288+
});
12661289
});

test/maplibregl/mapping/WebMapSpec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,4 +1244,27 @@ describe('maplibregl_WebMap', () => {
12441244
};
12451245
datavizWebmap.once('mapcreatesucceeded', callback);
12461246
});
1247+
1248+
it('rectifyLayersOrder', (done) => {
1249+
const commonOption = {
1250+
server: 'http://fack:8190/iportal/',
1251+
target: 'map',
1252+
withCredentials: false
1253+
};
1254+
datavizWebmap = new WebMap(
1255+
'',
1256+
{ ...commonOption },
1257+
mapOptionsList[0]
1258+
);
1259+
const callback = function ({map}) {
1260+
let layers = datavizWebmap.getLayers();
1261+
expect(layers.length).toBe(2);
1262+
let newLayers = [layers[1], layers[0]];
1263+
datavizWebmap.rectifyLayersOrder(newLayers);
1264+
const layersOnMap = map.getStyle().layers;
1265+
expect(layersOnMap[0].id).toBe('未命名数据')
1266+
done();
1267+
};
1268+
datavizWebmap.once('mapcreatesucceeded', callback);
1269+
});
12471270
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy