Skip to content

Commit

Permalink
[fix]图层管理配置或取消图层的初始加载时,对应在图层管理里勾选并添加图层或取消勾选并删除图层 review by luox
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxianhuii committed Oct 30, 2024
1 parent a05e928 commit 93aaa8a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/mapboxgl/web-map/control/layer-manager/LayerManager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import LayerManagerViewModel from './LayerManagerViewModel';
import uniqueId from 'lodash.uniqueid';
import clonedeep from 'lodash.clonedeep';
import isequal from 'lodash.isequal';
import difference from 'lodash.difference';
export default {
name: 'SmLayerManager',
Expand Down Expand Up @@ -104,6 +105,30 @@ export default {
},
deep: true,
immediate: true
},
defaultCheckedKeys(keys, oldKeys) {
if (isequal(keys, oldKeys)) {
return;
}
const newCheckedKeys = [].concat(this.checkedKeys);
if (keys.length > oldKeys.length) {
// 新增了一个初始加载的图层
const addKey = difference(keys, oldKeys);
this.addLayerByCheckedKeys(addKey);
if (!newCheckedKeys.includes(addKey[0])) {
newCheckedKeys.push(addKey[0]);
}
} else {
// 删除了一个初始加载的图层
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);
}
}
this.checkedKeys = newCheckedKeys;
}
},
created() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ describe('LayerManager.vue', () => {
await mapWrapperLoaded(mapWrapper);
await flushPromises();
expect(wrapper.vm.checkedKeys).toEqual([key]);
await wrapper.setProps({
defaultCheckedKeys: []
});
expect(wrapper.vm.checkedKeys).toEqual([]);
expect(spyadd).toBeCalled();
done();
});
Expand Down

0 comments on commit 93aaa8a

Please sign in to comment.