Skip to content

Commit

Permalink
[fix]将label图层的显隐通过viewModel事件传入
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxianhuii committed Sep 13, 2024
1 parent b23e717 commit 05daa12
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
7 changes: 2 additions & 5 deletions src/mapboxgl/tdt/map-switcher/TdtMapSwitcher.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,8 @@ export default {
this.labelChecked = checked;
this.$emit('change-label-status', this.labelChecked);
},
layerUpdate() {
const labelLayer = this.map && this.map.getLayer(this.$t(`tdtMapSwitcher.Tianditu${this.viewModel.tdtLabelType}`));
if (labelLayer && labelLayer.visibility) {
this.labelChecked = labelLayer.visibility === 'visible';
}
layerUpdate(e) {
this.labelChecked = e.visible;
}
},
loaded() {
Expand Down
5 changes: 4 additions & 1 deletion src/mapboxgl/tdt/map-switcher/TdtMapSwitcherViewModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ export default class TdtMapSwitcherViewModel extends mapboxgl.Evented {
}

_updateLayers() {
this.fire('layersUpdated');
const labelLayer = this.map && this.map.getLayer(geti18n().tc(`tdtMapSwitcher.Tianditu${this.tdtLabelType}`));
if (labelLayer && labelLayer.visibility) {
this.fire('layersUpdated', { visible: labelLayer.visibility === 'visible' });
}
}

setTk(tk) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ describe('TdtMapSwitcher.vue', () => {
minzoom: 0,
maxzoom: 18
}
}
},
addLayer: () => {}
};
await mapSubComponentLoaded(wrapper);
const callback = function () {
Expand All @@ -125,6 +126,6 @@ describe('TdtMapSwitcher.vue', () => {
webmap,
map
});
wrapper.vm.viewModel.togglerLabelLayer(false);
mockOnOptions.layersupdated();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,18 @@ describe('TdtMapSwitcherViewModel', () => {
proxy: null
}
};
let mockOnOptions;
const webmap = {
getLayerList: () => layerCatalogs,
changeItemVisible: jest.fn(),
un: jest.fn(),
on: jest.fn(options => {
mockOnOptions = options;
})
};
viewModel.setMap({
map: mapMockFn(initLayers, initSources)
map: mapMockFn(initLayers, initSources),
webmap: webmap
});
expect(viewModel.map.getStyle().layers).toEqual(initLayers);
expect(viewModel.map.getStyle().sources).toEqual(initSources);
Expand Down

0 comments on commit 05daa12

Please sign in to comment.