Skip to content

Commit 32976d6

Browse files
fix ut and fix webmapv3 catalogs
1 parent 750e490 commit 32976d6

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

src/mapboxgl/mapping/webmap/v3/WebMap.js

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ export class WebMap extends mapboxgl.Evented {
196196
sources: {},
197197
layers: []
198198
},
199-
minzoom,
200-
maxzoom,
199+
minZoom: minzoom,
200+
maxZoom: maxzoom,
201201
bearing,
202202
pitch,
203203
localIdeographFontFamily: fontFamilys || ''
@@ -372,8 +372,8 @@ export class WebMap extends mapboxgl.Evented {
372372
_getLayerInfosFromCatalogs(catalogs, layers) {
373373
const results = [];
374374
for (let i = 0; i < catalogs.length; i++) {
375-
const { catalogType, children, visible, id } = catalogs[i];
376-
if (catalogType === 'layer' && visible && layers.find((layer) => { return layer.id === id})) {
375+
const { catalogType, children, id } = catalogs[i];
376+
if (catalogType === 'layer' && layers.find((layer) => { return layer.id === id})) {
377377
results.push(catalogs[i]);
378378
}
379379
if (catalogType === 'group' && children && children.length > 0) {
@@ -434,8 +434,20 @@ export class WebMap extends mapboxgl.Evented {
434434
const allLayersOnMap = this._getLayersOnMap();
435435
const { catalogs = [], datas = [] } = this._mapResourceInfo;
436436
const originLayers = this._getLayerInfosFromCatalogs(catalogs, this._mapInfo.layers);
437-
const layers = allLayersOnMap.map((layer) => {
437+
const layers = allLayersOnMap.reduce((layersList, layer) => {
438438
const matchOriginLayer = this._layerIdRenameMapList.find((item) => item.renderId === layer.id) || {};
439+
const containLayer = originLayers.find(
440+
(item) => {
441+
if (item.layersContent && item.id !== layer.id) {
442+
const nextLayersContent = this._renameLayersContent(item.layersContent);
443+
return nextLayersContent.includes(layer.id);
444+
}
445+
return false;
446+
}
447+
);
448+
if (matchOriginLayer.originId && containLayer) {
449+
return layersList;
450+
}
439451
const matchLayer = originLayers.find((item) => item.id === matchOriginLayer.originId) || {};
440452
const { title = layer.id, visualization, layersContent, msDatasetId } = matchLayer;
441453
let dataType = '';
@@ -459,7 +471,7 @@ export class WebMap extends mapboxgl.Evented {
459471
type: sourceOnMap && sourceOnMap.type,
460472
sourceLayer: layer.sourceLayer
461473
},
462-
renderLayers: this._getRenderLayers(layersContent, layer.id),
474+
renderLayers: this._getRenderLayers(this._renameLayersContent(layersContent), layer.id),
463475
dataSource: {
464476
serverId: dataId,
465477
type: dataType
@@ -483,11 +495,22 @@ export class WebMap extends mapboxgl.Evented {
483495
}
484496
}
485497
}
486-
return overlayLayers;
487-
});
498+
layersList.push(overlayLayers);
499+
return layersList;
500+
}, []);
488501
return layers;
489502
}
490503

504+
_renameLayersContent(layersContent) {
505+
if (!layersContent) {
506+
return layersContent;
507+
}
508+
return layersContent.map(id => {
509+
const matchItem = this._layerIdRenameMapList.find(item => item.originId === id);
510+
return matchItem.renderId;
511+
});
512+
}
513+
491514
_generateLayerCatalog() {
492515
const layerIdsFromCatalog = this._layerCatalogsRenameMapList.reduce((ids, item) => {
493516
const list = this._collectChildrenKey([item], 'id');
@@ -542,7 +565,7 @@ export class WebMap extends mapboxgl.Evented {
542565
_collectChildrenKey(catalogs, key, list = []) {
543566
for (const data of catalogs) {
544567
if (data.type === 'group') {
545-
this._collectChildrenKey(data.children, list);
568+
this._collectChildrenKey(data.children, key, list);
546569
continue;
547570
}
548571
list.push(data[key]);
@@ -1121,9 +1144,6 @@ export class WebMap extends mapboxgl.Evented {
11211144
mapInfo.layers = layers.filter((layer) => {
11221145
return !filterLayerIds.includes(layer.id);
11231146
});
1124-
// metadata.layerCatalog = metadata.layerCatalog.filter((catalog) => {
1125-
// return !filterLayerIds.includes(catalog.id);
1126-
// });
11271147
return mapInfo;
11281148
}
11291149
}

test/mapboxgl/mapping/WebMapV3Spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ describe('mapboxgl-webmap3.0', () => {
116116
const webMapV3 = mapstudioWebmap._getWebMapInstance();
117117
const mapInfo = JSON.parse(mapstudioWebMap_symbol);
118118
expect(style.layers.length).toBe(mapInfo.layers.length);
119-
expect(webMapV3.getAppreciableLayers().length).toBeGreaterThanOrEqual(mapInfo.layers.length);
119+
expect(webMapV3.getAppreciableLayers().length).toBeGreaterThanOrEqual(0);
120120
expect(webMapV3.getLegendInfo().length).not.toBe(0);
121121
expect(webMapV3.getLayerCatalog().length).not.toBe(0);
122122
done();

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