Skip to content

Commit

Permalink
【feature】fix webmapv2 切换更新数据图例重复
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongjiaojiao committed Sep 11, 2024
1 parent 702dea4 commit d2cf441
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/mapboxgl/web-map/WebMapV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2572,6 +2572,11 @@ export default class WebMap extends WebMapBase {
default:
break;
}
const matchIndex = this._legendList.findIndex(item => item.layerId === layerInfo.layerID);
if (matchIndex > -1) {
this._legendList.splice(matchIndex, 1, legendItem);
return;
}
this._legendList.push(legendItem);
}

Expand Down
2 changes: 2 additions & 0 deletions src/mapboxgl/web-map/__tests__/WebMapViewModel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1519,6 +1519,7 @@ describe('WebMapViewModel.spec', () => {
const viewModel = new WebMapViewModel(commonId, { ...commonOption }, { ...commonMapOptions }, { ...commonMap });
const callback = function (data) {
expect(viewModel.getAppreciableLayers().length).toBe(uniqueLayer_polygon.layers.length + 1);
expect(viewModel.getLegendInfo().length).toBe(2);
const layerInfo = { ...uniqueLayer_polygon.layers[0], id: uniqueLayer_polygon.layers[0].name };
const features = [
{
Expand Down Expand Up @@ -1547,6 +1548,7 @@ describe('WebMapViewModel.spec', () => {
const spy = jest.spyOn(viewModel._handler, '_initOverlayLayer');
viewModel.updateOverlayLayer(layerInfo, features);
expect(spy).toBeCalled();
expect(viewModel.getLegendInfo().length).toBe(2);
done();
};
viewModel.on({ addlayerssucceeded: callback });
Expand Down

0 comments on commit d2cf441

Please sign in to comment.