Skip to content

Commit 49a335d

Browse files
committed
【update】切换底图,title优化; review by songym
1 parent 0bfe216 commit 49a335d

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

src/common/mapping/utils/SourceListModelV3.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@ export class SourceListModelV3 extends AppreciableLayerBase {
5858
const originBaseLayerCatalog = nextLayerCatalog.pop();
5959
this._removeBaseLayerRenderLayers(originBaseLayerCatalog, nextLayers);
6060
const baseLayers = layerItem.layers.map((layer) => {
61+
const title = layer.metadata && layer.metadata.title;
6162
return {
6263
...layer,
6364
layerInfo: {
6465
id: layer.id,
65-
title: layer.id,
66+
title: title || layer.id,
6667
renderLayers: [layer.id]
6768
}
6869
};
@@ -80,9 +81,10 @@ export class SourceListModelV3 extends AppreciableLayerBase {
8081
baseLayerCatalog.id = layerItem.id || defaultId;
8182
baseLayerCatalog.type = 'group';
8283
baseLayerCatalog.children = layerItem.layers.map((layer) => {
84+
const title = layer.metadata && layer.metadata.title;
8385
return {
8486
id: layer.id,
85-
title: layer.id,
87+
title: title || layer.id,
8688
type: 'basic',
8789
visible: true
8890
};

test/common/mapping/utils/SourceListModelV3Spec.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ describe('SourceListV3', () => {
767767
id: 'sameBaseLayer',
768768
layers: layers.slice(1, 3).map((item) => {
769769
const nextItem = Object.assign({}, item);
770-
nextItem.metadata = { SM_Layer_Id: 'sameBaseLayer' };
770+
nextItem.metadata = { SM_Layer_Id: 'sameBaseLayer', title: `custom_${item.id}` };
771771
return nextItem;
772772
}),
773773
sources: {
@@ -790,9 +790,52 @@ describe('SourceListV3', () => {
790790
appreciableLayers = sourceListModel.getLayers();
791791
expect(layerList.length).toBe(3);
792792
expect(layerList[layerList.length - 1].id).toBe('sameBaseLayer');
793+
expect(layerList[layerList.length - 1].children[0].title.match(/custom_TIANDITU_IMG_3857$/)).toBeTruthy();
794+
expect(layerList[layerList.length - 1].children[1].title.match(/custom_ms_TIANDITU_IMG_3857_label$/)).toBeTruthy();
793795
expect(appreciableLayers.length).toBe(5);
794796
expect(appreciableLayers[0].id.match(/TIANDITU_IMG_3857_TIANDITU_IMG_3857_\d+$/)).toBeTruthy();
795797
expect(appreciableLayers[1].id.match(/ms_TIANDITU_IMG_3857_label_ms_TIANDITU_IMG_3857_label_\d+$/)).toBeTruthy();
798+
expect(appreciableLayers[0].title.match(/custom_TIANDITU_IMG_3857/)).toBeTruthy();
799+
expect(appreciableLayers[1].title.match(/custom_ms_TIANDITU_IMG_3857_label/)).toBeTruthy();
800+
done();
801+
});
802+
803+
it('changeBaseLayer show title', (done) => {
804+
const nextBaseLayerMapInfo = cloneDeep(changeBaseLayerMapInfo);
805+
layers = nextBaseLayerMapInfo.layers;
806+
sources = nextBaseLayerMapInfo.sources;
807+
808+
overlayLayersManager = {};
809+
810+
const sourceListModel = new SourceListModelV3({
811+
map,
812+
mapInfo: cloneDeep(nextBaseLayerMapInfo),
813+
mapResourceInfo: {},
814+
legendList: [],
815+
l7LayerUtil: {
816+
isL7Layer,
817+
getL7MarkerLayers: () => []
818+
}
819+
});
820+
expect(map.getStyle().layers.some((item) => ['TIANDITU_IMG_3857', 'ms_TIANDITU_IMG_3857_label'].includes(item.id))).toBeTruthy();
821+
const layerList = sourceListModel.getLayerCatalog();
822+
const appreciableLayers = sourceListModel.getLayers();
823+
expect(layerList.length).toBe(2);
824+
expect(appreciableLayers.length).toBe(3);
825+
const baseLayerInfoCopy = {
826+
...baseLayerInfo,
827+
layers: baseLayerInfo.layers.map((item) => ({
828+
...item,
829+
metadata: { title: `custom_${item.id}`}
830+
}))
831+
};
832+
const nextBaseLayerInfo = sourceListModel.changeBaseLayer(baseLayerInfoCopy);
833+
expect(nextBaseLayerInfo).toBeTruthy();
834+
expect(nextBaseLayerInfo.layers.length).toBe(1);
835+
expect(nextBaseLayerInfo.layers).toEqual(baseLayerInfoCopy.layers);
836+
expect(map.getStyle().layers.some((item) => ['TIANDITU_IMG_3857', 'ms_TIANDITU_IMG_3857_label'].includes(item.id))).toBeFalsy();
837+
const nextAppreciableLayers = sourceListModel.getLayers();
838+
expect(nextAppreciableLayers.some(item => item.title === baseLayerInfoCopy.layers[0].metadata.title)).toBeTruthy();
796839
done();
797840
});
798841
});

0 commit comments

Comments
 (0)