Skip to content

Commit

Permalink
[fix]sourceList过滤掉经纬网
Browse files Browse the repository at this point in the history
  • Loading branch information
luoxiao-supermap committed Nov 14, 2024
1 parent 7e627a0 commit b55ceba
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 28 deletions.
3 changes: 2 additions & 1 deletion src/common/mapping/utils/AppreciableLayerBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export class AppreciableLayerBase extends Events {
'smmeasure',
'mapbox-gl-draw',
'maplibre-gl-draw',
/tracklayer-\d+-line/
/tracklayer-\d+-line/,
/graticuleLayer_\d+_line/
];
this.uniqueId = +new Date();
this.layersVisibleMap = new Map();
Expand Down
36 changes: 20 additions & 16 deletions test/common/mapping/utils/SourceListModelV2Spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ describe('SourceListV2', () => {
'line-opacity': 0.8
}
},
{
id: 'graticuleLayer_1_line',
type: 'line',
source: 'graticuleLayer_1_line',
layout: {
'line-cap': 'round',
'line-join': 'round'
},
paint: {
'line-color': '#065726',
'line-width': 5,
'line-opacity': 0.8
}
},
{
id: 'tdt-search-line',
type: 'line',
Expand Down Expand Up @@ -215,14 +229,9 @@ describe('SourceListV2', () => {
const sourceListModel = new SourceListModelV2({ map });
const appreciableLayers = sourceListModel.getLayers();
const selfAppreciableLayers = sourceListModel.getSelfLayers();
expect(appreciableLayers.length).toBe(4);
expect(appreciableLayers.length).toBe(3);
expect(appreciableLayers[2].title).toBe('test-source');
expect(appreciableLayers[2].renderLayers).toEqual(['test-id', 'test-id-label']);
expect(appreciableLayers[3].title).toBe('graticuleLayer_1723443238046_line');
expect(appreciableLayers[3].renderLayers).toEqual([
'graticuleLayer_1723443238046_line',
'graticuleLayer_1723443238046'
]);
expect(selfAppreciableLayers.length).toBe(0);
done();
});
Expand All @@ -241,20 +250,15 @@ describe('SourceListV2', () => {
});
const appreciableLayers = sourceListModel.getLayers();
const selfAppreciableLayers = sourceListModel.getSelfLayers(appreciableLayers);
expect(appreciableLayers.length).toBe(4);
expect(selfAppreciableLayers.length).toBe(1);
expect(selfAppreciableLayers[0].title).toBe('GraticuleLayer');
expect(selfAppreciableLayers[0].renderLayers).toEqual([
'graticuleLayer_1723443238046',
'graticuleLayer_1723443238046_line'
]);
expect(appreciableLayers.length).toBe(3);
expect(selfAppreciableLayers.length).toBe(0);
done();
});

it('getLayerCatalog', (done) => {
const sourceListModel = new SourceListModelV2({ map });
const layerList = sourceListModel.getLayerCatalog();
expect(layerList.length).toBe(4);
expect(layerList.length).toBe(3);
done();
});

Expand Down Expand Up @@ -525,7 +529,7 @@ describe('SourceListV2', () => {
it('toggleLayerVisible', (done) => {
const sourceListModel = new SourceListModelV2({ map });
const layerList = sourceListModel.getLayerCatalog();
expect(layerList.length).toBe(4);
expect(layerList.length).toBe(3);
expect(layerList[1].visible).toBeTruthy();
sourceListModel.on({
layerupdatechanged: () => {
Expand All @@ -543,7 +547,7 @@ describe('SourceListV2', () => {
it('setLayersVisible', (done) => {
const sourceListModel = new SourceListModelV2({ map });
const layerList = sourceListModel.getLayerCatalog();
expect(layerList.length).toBe(4);
expect(layerList.length).toBe(3);
expect(layerList[1].visible).toBeTruthy();
sourceListModel.on({
layerupdatechanged: () => {
Expand Down
35 changes: 24 additions & 11 deletions test/common/mapping/utils/SourceListModelV3Spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ describe('SourceListV3', () => {
'line-opacity': 0.8
}
},
{
id: 'graticuleLayer_1_line',
type: 'line',
source: 'graticuleLayer_1_line',
layout: {
'line-cap': 'round',
'line-join': 'round'
},
paint: {
'line-color': '#065726',
'line-width': 5,
'line-opacity': 0.8
}
},
{
id: 'tdt-search-line',
type: 'line',
Expand Down Expand Up @@ -227,13 +241,12 @@ describe('SourceListV3', () => {
});
const appreciableLayers = sourceListModel.getLayers();
const selfAppreciableLayers = sourceListModel.getSelfLayers();
expect(appreciableLayers.length).toBe(mapInfo.metadata.layerCatalog.length + 3);
expect(appreciableLayers.length).toBe(mapInfo.metadata.layerCatalog.length + 2);
expect(selfAppreciableLayers.length).toBe(mapInfo.metadata.layerCatalog.length);
const extraLayers = appreciableLayers.slice(mapInfo.metadata.layerCatalog.length);
expect(extraLayers[1].title).toBe('test-source');
expect(extraLayers[1].renderLayers).toEqual(['test-id', 'test-id-label']);
expect(extraLayers[2].title).toBe('graticuleLayer_1723443238046_line');
expect(extraLayers[2].renderLayers).toEqual(['graticuleLayer_1723443238046_line', 'graticuleLayer_1723443238046']);
expect(extraLayers[2]).toBe(undefined);
done();
});

Expand All @@ -250,7 +263,7 @@ describe('SourceListV3', () => {
}
});
const layerList = sourceListModel.getLayerCatalog();
expect(layerList.length).toBe(mapInfo.metadata.layerCatalog.length + 3);
expect(layerList.length).toBe(mapInfo.metadata.layerCatalog.length + 2);
done();
});

Expand All @@ -267,7 +280,7 @@ describe('SourceListV3', () => {
}
});
const layerList = sourceListModel.getLayerCatalog();
expect(layerList.length).toBe(mapInfo.metadata.layerCatalog.length + 3);
expect(layerList.length).toBe(mapInfo.metadata.layerCatalog.length + 2);
done();
});

Expand All @@ -284,7 +297,7 @@ describe('SourceListV3', () => {
}
});
const layerList = sourceListModel.getLayerCatalog();
expect(layerList.length).toBe(mapInfo.metadata.layerCatalog.length + 4);
expect(layerList.length).toBe(mapInfo.metadata.layerCatalog.length + 3);
const selfIds = mapInfo.metadata.layerCatalog.map(item => item.id);
const selfLayerCatalogs = layerList.filter(layer => selfIds.includes(layer.id));
expect(selfLayerCatalogs.some(layer => !layer.renderLayers.includes(layer.id))).toBe(false);
Expand All @@ -304,7 +317,7 @@ describe('SourceListV3', () => {
}
});
const layerList = sourceListModel.getLayerCatalog();
expect(layerList.length).toBe(mapInfo.metadata.layerCatalog.length + 3);
expect(layerList.length).toBe(mapInfo.metadata.layerCatalog.length + 2);
const selfIds = mapInfo.metadata.layerCatalog.map(item => item.id);
const selfLayerCatalogs = layerList.filter(layer => selfIds.includes(layer.id));
expect(selfLayerCatalogs.some(layer => !layer.renderLayers.includes(layer.id))).toBe(false);
Expand All @@ -324,7 +337,7 @@ describe('SourceListV3', () => {
}
});
const layerList = sourceListModel.getLayerCatalog();
expect(layerList.length).toBe(mapInfo.metadata.layerCatalog.length + 4);
expect(layerList.length).toBe(mapInfo.metadata.layerCatalog.length + 3);
const selfIds = mapInfo.metadata.layerCatalog.filter(item => item.parts).map(item => item.id);
const selfLayerCatalogs = layerList.filter(layer => selfIds.includes(layer.id));
expect(selfLayerCatalogs.some(layer => layer.renderLayers.includes(layer.id))).toBe(false);
Expand Down Expand Up @@ -368,7 +381,7 @@ describe('SourceListV3', () => {
}
});
const layerList = sourceListModel.getLayerCatalog();
expect(layerList.length).toBe(mapInfo.metadata.layerCatalog.length + 3);
expect(layerList.length).toBe(mapInfo.metadata.layerCatalog.length + 2);
expect(layerList[0].id).toBe('中国金牌个人获奖者(1)');
expect(layerList[0].type).toBe('chart');
expect(layerList[0].visible).toBeTruthy();
Expand Down Expand Up @@ -402,7 +415,7 @@ describe('SourceListV3', () => {
}
});
let layerList = sourceListModel.getLayerCatalog();
expect(layerList.length).toBe(mapInfo.metadata.layerCatalog.length + 3);
expect(layerList.length).toBe(mapInfo.metadata.layerCatalog.length + 2);
expect(layerList[0].visible).toBeTruthy();
sourceListModel.toggleLayerVisible(layerList[0], false);
layerList = sourceListModel.getLayerCatalog();
Expand Down Expand Up @@ -460,7 +473,7 @@ describe('SourceListV3', () => {
}
});
const layerList = sourceListModel.getLayerCatalog();
expect(layerList.length).toBe(mapInfo.metadata.layerCatalog.length + 3);
expect(layerList.length).toBe(mapInfo.metadata.layerCatalog.length + 2);
expect(layerList[4].visible).toBeTruthy();
sourceListModel.on({
layerupdatechanged: () => {
Expand Down

0 comments on commit b55ceba

Please sign in to comment.