Skip to content

Commit

Permalink
【feature】更新可感知图层显隐初始值优化
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongjiaojiao committed May 23, 2024
1 parent 7e0df52 commit f080092
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 11 deletions.
36 changes: 36 additions & 0 deletions src/mapboxgl/_types/__tests__/map-event.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { mount, createLocalVue } from '@vue/test-utils';
import mapEvent from '../map-event';

describe('map-event-mapboxgl', () => {

afterEach(() => {
jest.clearAllMocks();
jest.resetAllMocks();
jest.restoreAllMocks();
});

it ('webmap', () => {
const changeItemVisibleSpy = jest.fn();
const webmap1 = {
changeItemVisible: changeItemVisibleSpy,
getAppreciableLayers: () => [{id: 'layer1'}],
cacheLayerIds: ['layer1']
}
const webmap2 = {
changeItemVisible: changeItemVisibleSpy,
getAppreciableLayers: () => [{id: 'layer2'}],
cacheLayerIds: ['layer2']
}
const mapTarget = 'webmap1';
mapEvent.$options.setWebMap(mapTarget, webmap1);
mapEvent.$options.setWebMap(mapTarget, webmap2, 'webmap2');
let webmap = mapEvent.$options.getWebMap('map');
expect(webmap).toBeUndefined();
webmap = mapEvent.$options.getWebMap(mapTarget);
expect(webmap).not.toBeUndefined();
expect(webmap.getAppreciableLayers().length).toBe(2);
webmap.changeItemVisible();
expect(changeItemVisibleSpy).toHaveBeenCalledTimes(2);
expect(webmap.cacheLayerIds).toEqual(['layer1']);
})
});
9 changes: 9 additions & 0 deletions src/mapboxgl/_types/map-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ export default new Vue({
}
return () => datas;
}
if (['changeItemVisible'].includes(propKey)) {
return function () {
const webmaps = webMapCombinations.map(item => item[1]);
const argumentsList = arguments;
webmaps.forEach((webmap) => {
webmap[propKey].apply(webmap, argumentsList);
});
};
}
return target[propKey];
}
});
Expand Down
8 changes: 4 additions & 4 deletions src/mapboxgl/web-map/SourceListModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ class SourceListModel {
const layersOnMap = this.map.getStyle().layers.map(layer => this.map.getLayer(layer.id));
const overlayLayers = Object.values(this.map.overlayLayersManager).reduce((layers, overlayLayer) => {
if (overlayLayer.id && !layers.some(item => item.id === overlayLayer.id)) {
let visibility = overlayLayer.visibility;
if (!visibility && 'visible' in overlayLayer) {
visibility = overlayLayer.visible ? 'visible' : 'none';
}
const visibility =
!('visible' in overlayLayer) || overlayLayer.visibility === 'visible' || overlayLayer.visible
? 'visible'
: 'none';
let source = overlayLayer.source || overlayLayer.sourceId;
if (typeof source === 'object') {
source = overlayLayer.id;
Expand Down
3 changes: 2 additions & 1 deletion src/mapboxgl/web-map/WebMapV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2210,7 +2210,8 @@ export default class WebMap extends WebMapBase {
if (this.map.getLayer(baseLayerId)) {
layersFromMapInfo.unshift({
id: baseLayerId,
name: this._mapInfo.baseLayer.title || baseLayerId
name: this._mapInfo.baseLayer.title || baseLayerId,
visible: this._mapInfo.baseLayer.visible
});
}
// strokeLine之类
Expand Down
6 changes: 1 addition & 5 deletions src/mapboxgl/web-map/WebMapViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,11 +362,7 @@ export default class WebMapViewModel extends Events {
}
}

updateLayersVisible(
layers: Array<Record<string, any>>,
visibility: 'visible' | 'none',
ignoreIds: string[] = []
) {
updateLayersVisible(layers: Array<Record<string, any>>, visibility: 'visible' | 'none', ignoreIds: string[] = []) {
layers.forEach(layer => {
const visbleId = this.getLayerVisibleId(layer);
this._appreciableLayersVisibleMap.set(visbleId, visibility === 'visible');
Expand Down
2 changes: 1 addition & 1 deletion static/libs/iclient-mapboxgl/iclient-mapboxgl.min.js

Large diffs are not rendered by default.

0 comments on commit f080092

Please sign in to comment.