{{ $t('layerList.opacity') }}
oldKeys.length) {
- // 新增了一个初始加载的图层
+ // 开启图层初始加载后,同步在图层管理里勾选上,并添加图层到map
const addKey = difference(keys, oldKeys);
this.addLayerByCheckedKeys(addKey);
- if (!newCheckedKeys.includes(addKey[0])) {
- newCheckedKeys.push(addKey[0]);
- }
+ addKey.forEach(key => {
+ if (!newCheckedKeys.includes(key)) {
+ newCheckedKeys.push(key);
+ }
+ });
} else {
- // 删除了一个初始加载的图层
+ // 关闭图层初始加载后,同步在图层管理里取消勾选,并从map删除图层
const delKey = difference(oldKeys, keys);
- const node = this.getNodeByKey(this.treeData, delKey[0]);
- this.viewModel.removeLayerLoop(node);
- if (newCheckedKeys.includes(delKey[0])) {
- const indexToRemove = newCheckedKeys.indexOf(delKey[0]);
- newCheckedKeys.splice(indexToRemove, 1);
- }
+ delKey.forEach(key => {
+ const node = this.getNodeByKey(this.oldTreeData, key);
+ this.viewModel.removeLayerLoop(node);
+ if (newCheckedKeys.includes(key)) {
+ const indexToRemove = newCheckedKeys.indexOf(key);
+ newCheckedKeys.splice(indexToRemove, 1);
+ }
+ });
}
this.checkedKeys = newCheckedKeys;
}
@@ -141,6 +152,15 @@ export default {
this.viewModel.off('layersremoved', this.removeMapCombination);
},
methods: {
+ omitVisible(val) {
+ return val.map(item => {
+ const newItem = omit(item, ['visible']);
+ if (newItem.children) {
+ newItem.children = this.omitVisible(newItem.children, ['visible']);
+ }
+ return newItem;
+ });
+ },
checkNode(key, e) {
this.checkedKeys = key;
if (e.checked) {
diff --git a/src/mapboxgl/web-map/control/layer-manager/__tests__/LayerManager.spec.js b/src/mapboxgl/web-map/control/layer-manager/__tests__/LayerManager.spec.js
index 51ad411b..89423733 100644
--- a/src/mapboxgl/web-map/control/layer-manager/__tests__/LayerManager.spec.js
+++ b/src/mapboxgl/web-map/control/layer-manager/__tests__/LayerManager.spec.js
@@ -190,16 +190,31 @@ describe('LayerManager.vue', () => {
]
}
});
+ const treeData = [
+ {
+ mapInfo: { serverUrl: 'https://fakeiportal.supermap.io/iportal', mapId: '801571284' },
+ title: '民航数据-单值',
+ key: 'key1',
+ visible: true
+ }
+ ];
const spyadd= jest.spyOn(wrapper.vm, 'addLayer');
- const key = wrapper.vm.treeData[0].key;
- await wrapper.setProps({
- defaultCheckedKeys: [key]
+ await wrapper.setData({
+ treeData: treeData
});
await mapWrapperLoaded(mapWrapper);
await flushPromises();
- expect(wrapper.vm.checkedKeys).toEqual([key]);
- await wrapper.setProps({
- defaultCheckedKeys: []
+ expect(wrapper.vm.checkedKeys).toEqual(['key1']);
+ wrapper.vm.oldTreeData = treeData;
+ await wrapper.setData({
+ treeData: [
+ {
+ mapInfo: { serverUrl: 'https://fakeiportal.supermap.io/iportal', mapId: '801571284' },
+ title: '民航数据-单值',
+ key: 'key1',
+ visible: false
+ }
+ ]
});
expect(wrapper.vm.checkedKeys).toEqual([]);
expect(spyadd).toBeCalled();