Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
xilanhuaweidapao committed Nov 25, 2024
2 parents f760540 + 3bb88bf commit 9237ff3
Show file tree
Hide file tree
Showing 4 changed files with 575 additions and 8 deletions.
14 changes: 8 additions & 6 deletions src/common/mapping/WebMapV3.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* This program are made available under the terms of the Apache License, Version 2.0
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
import { FetchRequest } from '../util/FetchRequest';
import { getLayerInfosFromCatalogs, getMainLayerFromCatalog, isSameRasterLayer, mergeFeatures, transformUrl } from './utils/util';
import { getLayerCatalogRenderLayers, getLayerInfosFromCatalogs, getMainLayerFromCatalog, isSameRasterLayer, mergeFeatures, transformUrl } from './utils/util';
import { SourceListModelV3 } from './utils/SourceListModelV3';

const LEGEND_RENDER_TYPE = {
Expand Down Expand Up @@ -504,7 +504,7 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, mapRe
layer.id = layerId;
}
}
layerIdToChange.push({ originId: originId, renderId: layer.id });
layerIdToChange.push({ originId: originId, renderId: layer.id, id: originId });
}
const layerCatalogFromMapJson = JSON.parse(JSON.stringify(style.metadata.layerCatalog), 'parts');
this._updateLayerCatalogsId({
Expand Down Expand Up @@ -592,7 +592,8 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, mapRe
});
return;
}
const matchLayer = layerIdMapList.find((item) => item.originId === id);
const renderLayers = getLayerCatalogRenderLayers(loopItem[layerIdsField], id, layerIdMapList);
const matchLayer = layerIdMapList.find((item) => item.originId === renderLayers[0]);
if (matchLayer) {
const catalog = this._findLayerCatalog(catalogs, id);
catalog.id = matchLayer.renderId;
Expand All @@ -602,7 +603,7 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, mapRe
}
return;
}
if (unspportedLayers.includes(id)) {
if (unspportedLayers.includes(id) || renderLayers.some((layerId) => unspportedLayers.includes(layerId))) {
this._deleteLayerCatalog(catalogs, id);
}
});
Expand Down Expand Up @@ -1407,9 +1408,10 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, mapRe
const unSupportedMsg = 'layer are not supported yet';
const { interaction } = mapInfo;
if (interaction && interaction.drill) {
this.fire('layercreatefailed', { error: `drill ${unSupportedMsg}`, map: this.map });
this.fire('layercreatefailed', { error: `drill ${unSupportedMsg}`, map: this.map, error_code: 'DRILL_LAYERS_NOT_SUPPORTED' });
interaction.drill.forEach((drillItem) => {
filterLayerIds.push(...drillItem.layerIds);
const drillLayerIds = drillItem.layerIds || drillItem.layers.reduce((ids, item) => ids.concat(item.layerIds), []);
filterLayerIds.push(...drillLayerIds);
});
}
return filterLayerIds;
Expand Down
59 changes: 58 additions & 1 deletion test/mapboxgl/mapping/WebMapV3Spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,65 @@ describe('mapboxgl-webmap3.0', () => {
server: server,
target: 'map'
});
mapstudioWebmap.on('layercreatefailed', ({ error }) => {
mapstudioWebmap.on('layercreatefailed', ({ error, error_code }) => {
expect(['drill'].indexOf(error.split(' ')[0]) > -1).toBeTruthy();
expect(error_code).toBe('DRILL_LAYERS_NOT_SUPPORTED');
});
mapstudioWebmap.on('mapcreatesucceeded', ({ map }) => {
const style = map.getStyle();
expect(style.layers.length).toBeLessThan(originMapInfo.layers.length);
expect(style.layers.length).toBe(mapInfo.layers.length);
expect(mapstudioWebmap.getLayers().length).toBe(1);
expect(mapstudioWebmap.getLayerCatalog().length).toBe(1);
done();
});
mapstudioWebmap.initializeMap(mapInfo);
});

it('filter drill ui id test', (done) => {
spyOn(FetchRequest, 'get').and.callFake((url) => {
if (url.indexOf('/sprite') > -1) {
return Promise.resolve(new Response(msSpriteInfo));
}
return Promise.resolve();
});
const mapInfo = JSON.parse(mapstudioWebMap_drill_layers1);
const originMapInfo = JSON.parse(mapstudioWebMap_drill_layers1);
const mapstudioWebmap = new WebMapV3(mapInfo, {
server: server,
target: 'map'
});
mapstudioWebmap.on('layercreatefailed', ({ error, error_code }) => {
expect(['drill'].indexOf(error.split(' ')[0]) > -1).toBeTruthy();
expect(error_code).toBe('DRILL_LAYERS_NOT_SUPPORTED');
});
mapstudioWebmap.on('mapcreatesucceeded', ({ map }) => {
const style = map.getStyle();
expect(style.layers.length).toBeLessThan(originMapInfo.layers.length);
expect(style.layers.length).toBe(mapInfo.layers.length);
expect(mapstudioWebmap.getLayers().length).toBe(1);
expect(mapstudioWebmap.getLayerCatalog().length).toBe(1);
done();
});
mapstudioWebmap.initializeMap(mapInfo);
});

it('filter drill interaction changed test', (done) => {
spyOn(FetchRequest, 'get').and.callFake((url) => {
if (url.indexOf('/sprite') > -1) {
return Promise.resolve(new Response(msSpriteInfo));
}
return Promise.resolve();
});
const mapInfo = JSON.parse(mapstudioWebMap_drill_layers2);
const originMapInfo = JSON.parse(mapstudioWebMap_drill_layers2);
const mapstudioWebmap = new WebMapV3(mapInfo, {
server: server,
target: 'map'
});
mapstudioWebmap.on('layercreatefailed', ({ error, error_code }) => {
expect(['drill'].indexOf(error.split(' ')[0]) > -1).toBeTruthy();
expect(error_code).toBe('DRILL_LAYERS_NOT_SUPPORTED');
});
mapstudioWebmap.on('mapcreatesucceeded', ({ map }) => {
const style = map.getStyle();
Expand Down
59 changes: 58 additions & 1 deletion test/maplibregl/mapping/WebMapV3Spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,65 @@ describe('maplibregl-webmap3.0', () => {
server: server,
target: 'map'
});
mapstudioWebmap.on('layercreatefailed', ({ error }) => {
mapstudioWebmap.on('layercreatefailed', ({ error, error_code }) => {
expect(['drill'].indexOf(error.split(' ')[0]) > -1).toBeTruthy();
expect(error_code).toBe('DRILL_LAYERS_NOT_SUPPORTED');
});
mapstudioWebmap.on('mapcreatesucceeded', ({ map }) => {
const style = map.getStyle();
expect(style.layers.length).toBeLessThan(originMapInfo.layers.length);
expect(style.layers.length).toBe(mapInfo.layers.length);
expect(mapstudioWebmap.getLayers().length).toBe(1);
expect(mapstudioWebmap.getLayerCatalog().length).toBe(1);
done();
});
mapstudioWebmap.initializeMap(mapInfo);
});

it('filter drill ui id test', (done) => {
spyOn(FetchRequest, 'get').and.callFake((url) => {
if (url.indexOf('/sprite') > -1) {
return Promise.resolve(new Response(msSpriteInfo));
}
return Promise.resolve();
});
const mapInfo = JSON.parse(mapstudioWebMap_drill_layers1);
const originMapInfo = JSON.parse(mapstudioWebMap_drill_layers1);
const mapstudioWebmap = new WebMapV3(mapInfo, {
server: server,
target: 'map'
});
mapstudioWebmap.on('layercreatefailed', ({ error, error_code }) => {
expect(['drill'].indexOf(error.split(' ')[0]) > -1).toBeTruthy();
expect(error_code).toBe('DRILL_LAYERS_NOT_SUPPORTED');
});
mapstudioWebmap.on('mapcreatesucceeded', ({ map }) => {
const style = map.getStyle();
expect(style.layers.length).toBeLessThan(originMapInfo.layers.length);
expect(style.layers.length).toBe(mapInfo.layers.length);
expect(mapstudioWebmap.getLayers().length).toBe(1);
expect(mapstudioWebmap.getLayerCatalog().length).toBe(1);
done();
});
mapstudioWebmap.initializeMap(mapInfo);
});

it('filter drill interaction changed test', (done) => {
spyOn(FetchRequest, 'get').and.callFake((url) => {
if (url.indexOf('/sprite') > -1) {
return Promise.resolve(new Response(msSpriteInfo));
}
return Promise.resolve();
});
const mapInfo = JSON.parse(mapstudioWebMap_drill_layers2);
const originMapInfo = JSON.parse(mapstudioWebMap_drill_layers2);
const mapstudioWebmap = new WebMapV3(mapInfo, {
server: server,
target: 'map'
});
mapstudioWebmap.on('layercreatefailed', ({ error, error_code }) => {
expect(['drill'].indexOf(error.split(' ')[0]) > -1).toBeTruthy();
expect(error_code).toBe('DRILL_LAYERS_NOT_SUPPORTED');
});
mapstudioWebmap.on('mapcreatesucceeded', ({ map }) => {
const style = map.getStyle();
Expand Down
Loading

0 comments on commit 9237ff3

Please sign in to comment.