Skip to content

Commit 809dd90

Browse files
fix 过滤显示l7 drill 图层 reivew by xiongjj
1 parent 18bec5d commit 809dd90

3 files changed

Lines changed: 708 additions & 10 deletions

File tree

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

Lines changed: 64 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ export const LEGEND_STYLE_TYPES = {
8787
STYLE: 'style'
8888
};
8989

90+
const UN_SUPPORTED_LAYER_TYPE = ['point-extrusion', 'heatmap-extrusion', 'radar', 'line-extrusion', 'line-curve', 'line-curve-extrusion', 'chart']
91+
const UN_SUPPORTED_LAYER_ATTRS_MAP = {
92+
circle: ['circle-animate-speed', 'circle-animate-rings'],
93+
line: ['line-animate-duration', 'line-animate-interval ', 'line-animate-trailLength ']
94+
}
95+
9096
export class WebMap extends mapboxgl.Evented {
9197
constructor(mapId, options, mapOptions = {}) {
9298
super();
@@ -116,6 +122,7 @@ export class WebMap extends mapboxgl.Evented {
116122
* @param {Object} map - map 实例。
117123
*/
118124
initializeMap(mapInfo, map) {
125+
mapInfo = this._handleUnSupportedLayers(mapInfo);
119126
this._mapInfo = mapInfo;
120127
if (map) {
121128
this._appendLayers = true;
@@ -333,15 +340,19 @@ export class WebMap extends mapboxgl.Evented {
333340
}
334341

335342
_updateLayerCatalogsId(catalogs, layerIdMapList) {
336-
catalogs.forEach((catalog) => {
343+
catalogs.forEach((catalog, index) => {
337344
const { id, children } = catalog;
338345
if (catalog.type === 'group') {
339346
this._updateLayerCatalogsId(children, layerIdMapList);
340347
return;
341348
}
342349
const matchLayer = layerIdMapList.find((item) => item.originId === id);
343-
catalog.originId = id;
344-
catalog.id = matchLayer.renderId;
350+
if (matchLayer) {
351+
catalog.originId = id;
352+
catalog.id = matchLayer.renderId;
353+
} else {
354+
catalogs.splice(index, 1);
355+
}
345356
});
346357
}
347358

@@ -358,15 +369,15 @@ export class WebMap extends mapboxgl.Evented {
358369
this.fire('addlayerssucceeded', { map: this.map, mapparams: this.mapParams, layers: matchLayers });
359370
}
360371

361-
_getLayerInfosFromCatalogs(catalogs) {
372+
_getLayerInfosFromCatalogs(catalogs, layers) {
362373
const results = [];
363374
for (let i = 0; i < catalogs.length; i++) {
364-
const { catalogType, children, visible } = catalogs[i];
365-
if (catalogType === 'layer' && visible) {
375+
const { catalogType, children, visible, id } = catalogs[i];
376+
if (catalogType === 'layer' && visible && layers.find((layer) => { return layer.id === id})) {
366377
results.push(catalogs[i]);
367378
}
368379
if (catalogType === 'group' && children && children.length > 0) {
369-
const result = this._getLayerInfosFromCatalogs(children);
380+
const result = this._getLayerInfosFromCatalogs(children, layers);
370381
results.push(...result);
371382
}
372383
}
@@ -422,15 +433,15 @@ export class WebMap extends mapboxgl.Evented {
422433
_generateLayers() {
423434
const allLayersOnMap = this._getLayersOnMap();
424435
const { catalogs = [], datas = [] } = this._mapResourceInfo;
425-
const originLayers = this._getLayerInfosFromCatalogs(catalogs);
436+
const originLayers = this._getLayerInfosFromCatalogs(catalogs, this._mapInfo.layers);
426437
const layers = allLayersOnMap.map((layer) => {
427438
const matchOriginLayer = this._layerIdRenameMapList.find((item) => item.renderId === layer.id) || {};
428439
const matchLayer = originLayers.find((item) => item.id === matchOriginLayer.originId) || {};
429440
const { title = layer.id, visualization, layersContent, msDatasetId } = matchLayer;
430441
let dataType = '';
431442
let dataId = '';
432443
for (const data of datas) {
433-
const matchData = data.datasets.find((dataset) => dataset.msDatasetId === msDatasetId);
444+
const matchData = data.datasets && data.datasets.find((dataset) => dataset.msDatasetId === msDatasetId);
434445
if (matchData) {
435446
dataType = data.sourceType;
436447
dataId = matchData.datasetId;
@@ -625,7 +636,7 @@ export class WebMap extends mapboxgl.Evented {
625636

626637
_createLegendInfo() {
627638
const { catalogs = [] } = this._mapResourceInfo;
628-
const originLayers = this._getLayerInfosFromCatalogs(catalogs);
639+
const originLayers = this._getLayerInfosFromCatalogs(catalogs, this._mapInfo.layers);
629640
for (const layer of originLayers) {
630641
const { renderer } = layer.visualization || {};
631642
if (!renderer) {
@@ -1072,4 +1083,47 @@ export class WebMap extends mapboxgl.Evented {
10721083
});
10731084
return Number((topBoundary - bottomBoundary).toFixed(2));
10741085
}
1086+
1087+
_handleUnSupportedLayers(mapInfo) {
1088+
let filterLayerIds = [];
1089+
const unSupportedMsg = 'layer are not supported yet';
1090+
let { layers, interaction } = mapInfo;
1091+
if (interaction && interaction.drill) {
1092+
this.fire('getlayersfailed', { error: `drill ${unSupportedMsg}` });
1093+
interaction.drill.forEach((drillItem) => {
1094+
filterLayerIds = filterLayerIds.concat(drillItem.layerIds);
1095+
});
1096+
}
1097+
layers.forEach((layerInfo) => {
1098+
if (UN_SUPPORTED_LAYER_TYPE.includes(layerInfo.type)) {
1099+
this.fire('getlayersfailed', { error: `${layerInfo.type} ${unSupportedMsg}` });
1100+
filterLayerIds.push(layerInfo.id);
1101+
return;
1102+
}
1103+
if (layerInfo.type === 'heatmap' && layerInfo.paint && ['spuare', 'hexagon'].includes(layerInfo.paint['heatmap-shape'])) {
1104+
this.fire('getlayersfailed', { error: `${layerInfo.paint['heatmap-shape']}-heatmap ${unSupportedMsg}` });
1105+
filterLayerIds.push(layerInfo.id);
1106+
}
1107+
let partialUnSupportProps = UN_SUPPORTED_LAYER_ATTRS_MAP[layerInfo.type];
1108+
let triggered = false;
1109+
if (partialUnSupportProps) {
1110+
partialUnSupportProps.forEach((attr) => {
1111+
layerInfo.layout && Object.keys(layerInfo.layout).forEach((layoutProp) => {
1112+
if (layoutProp === attr && !triggered) {
1113+
this.fire('getlayersfailed', { error: `${layerInfo.type}-animate ${unSupportedMsg}` });
1114+
filterLayerIds.push(layerInfo.id);
1115+
triggered = true;
1116+
}
1117+
});
1118+
});
1119+
}
1120+
});
1121+
mapInfo.layers = layers.filter((layer) => {
1122+
return !filterLayerIds.includes(layer.id);
1123+
});
1124+
// metadata.layerCatalog = metadata.layerCatalog.filter((catalog) => {
1125+
// return !filterLayerIds.includes(catalog.id);
1126+
// });
1127+
return mapInfo;
1128+
}
10751129
}

test/mapboxgl/mapping/WebMapV3Spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,4 +280,27 @@ describe('mapboxgl-webmap3.0', () => {
280280
done();
281281
});
282282
});
283+
284+
it('filter l7 and drill test', (done) => {
285+
spyOn(FetchRequest, 'get').and.callFake((url) => {
286+
if (url.indexOf('/sprite') > -1) {
287+
return Promise.resolve(new Response(msSpriteInfo));
288+
}
289+
return Promise.resolve();
290+
});
291+
const mapInfo = JSON.parse(mapstudioWebMap_l7_and_drill);
292+
const mapstudioWebmap = new WebMapV3(mapInfo, {
293+
server: server,
294+
target: 'map'
295+
});
296+
let count = 0;
297+
mapstudioWebmap.on('getlayersfailed', ({ error }) => {
298+
expect(['drill', 'line-curve', 'chart', 'circle-animate', 'heatmap-extrusion', 'point-extrusion'].indexOf(error.split(' ')[0]) > -1).toBeTruthy();
299+
count++;
300+
if (count === 7) {
301+
done();
302+
}
303+
});
304+
mapstudioWebmap.initializeMap(mapInfo);
305+
});
283306
});

0 commit comments

Comments
 (0)