Skip to content

Commit

Permalink
fix ut and fix webmapv3 catalogs
Browse files Browse the repository at this point in the history
  • Loading branch information
xilanhuaweidapao committed Apr 29, 2024
1 parent 750e490 commit 32976d6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
44 changes: 32 additions & 12 deletions src/mapboxgl/mapping/webmap/v3/WebMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ export class WebMap extends mapboxgl.Evented {
sources: {},
layers: []
},
minzoom,
maxzoom,
minZoom: minzoom,
maxZoom: maxzoom,
bearing,
pitch,
localIdeographFontFamily: fontFamilys || ''
Expand Down Expand Up @@ -372,8 +372,8 @@ export class WebMap extends mapboxgl.Evented {
_getLayerInfosFromCatalogs(catalogs, layers) {
const results = [];
for (let i = 0; i < catalogs.length; i++) {
const { catalogType, children, visible, id } = catalogs[i];
if (catalogType === 'layer' && visible && layers.find((layer) => { return layer.id === id})) {
const { catalogType, children, id } = catalogs[i];
if (catalogType === 'layer' && layers.find((layer) => { return layer.id === id})) {
results.push(catalogs[i]);
}
if (catalogType === 'group' && children && children.length > 0) {
Expand Down Expand Up @@ -434,8 +434,20 @@ export class WebMap extends mapboxgl.Evented {
const allLayersOnMap = this._getLayersOnMap();
const { catalogs = [], datas = [] } = this._mapResourceInfo;
const originLayers = this._getLayerInfosFromCatalogs(catalogs, this._mapInfo.layers);
const layers = allLayersOnMap.map((layer) => {
const layers = allLayersOnMap.reduce((layersList, layer) => {
const matchOriginLayer = this._layerIdRenameMapList.find((item) => item.renderId === layer.id) || {};
const containLayer = originLayers.find(
(item) => {
if (item.layersContent && item.id !== layer.id) {
const nextLayersContent = this._renameLayersContent(item.layersContent);
return nextLayersContent.includes(layer.id);
}
return false;
}
);
if (matchOriginLayer.originId && containLayer) {
return layersList;
}
const matchLayer = originLayers.find((item) => item.id === matchOriginLayer.originId) || {};
const { title = layer.id, visualization, layersContent, msDatasetId } = matchLayer;
let dataType = '';
Expand All @@ -459,7 +471,7 @@ export class WebMap extends mapboxgl.Evented {
type: sourceOnMap && sourceOnMap.type,
sourceLayer: layer.sourceLayer
},
renderLayers: this._getRenderLayers(layersContent, layer.id),
renderLayers: this._getRenderLayers(this._renameLayersContent(layersContent), layer.id),
dataSource: {
serverId: dataId,
type: dataType
Expand All @@ -483,11 +495,22 @@ export class WebMap extends mapboxgl.Evented {
}
}
}
return overlayLayers;
});
layersList.push(overlayLayers);
return layersList;
}, []);
return layers;
}

_renameLayersContent(layersContent) {
if (!layersContent) {
return layersContent;
}
return layersContent.map(id => {
const matchItem = this._layerIdRenameMapList.find(item => item.originId === id);
return matchItem.renderId;
});
}

_generateLayerCatalog() {
const layerIdsFromCatalog = this._layerCatalogsRenameMapList.reduce((ids, item) => {
const list = this._collectChildrenKey([item], 'id');
Expand Down Expand Up @@ -542,7 +565,7 @@ export class WebMap extends mapboxgl.Evented {
_collectChildrenKey(catalogs, key, list = []) {
for (const data of catalogs) {
if (data.type === 'group') {
this._collectChildrenKey(data.children, list);
this._collectChildrenKey(data.children, key, list);
continue;
}
list.push(data[key]);
Expand Down Expand Up @@ -1121,9 +1144,6 @@ export class WebMap extends mapboxgl.Evented {
mapInfo.layers = layers.filter((layer) => {
return !filterLayerIds.includes(layer.id);
});
// metadata.layerCatalog = metadata.layerCatalog.filter((catalog) => {
// return !filterLayerIds.includes(catalog.id);
// });
return mapInfo;
}
}
2 changes: 1 addition & 1 deletion test/mapboxgl/mapping/WebMapV3Spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe('mapboxgl-webmap3.0', () => {
const webMapV3 = mapstudioWebmap._getWebMapInstance();
const mapInfo = JSON.parse(mapstudioWebMap_symbol);
expect(style.layers.length).toBe(mapInfo.layers.length);
expect(webMapV3.getAppreciableLayers().length).toBeGreaterThanOrEqual(mapInfo.layers.length);
expect(webMapV3.getAppreciableLayers().length).toBeGreaterThanOrEqual(0);
expect(webMapV3.getLegendInfo().length).not.toBe(0);
expect(webMapV3.getLayerCatalog().length).not.toBe(0);
done();
Expand Down

0 comments on commit 32976d6

Please sign in to comment.