Skip to content

Commit

Permalink
[fix]修复加载dv被隐藏的矢量瓦片,初始显隐不对的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxianhuii committed Sep 11, 2024
1 parent 5e9b59e commit 702dea4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/mapboxgl/web-map/SourceModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ class SourceModel {
this.renderSource = {};
this.dataSource = {};
this.themeSetting = {};
this.visible = true;
this.title = this.id;
}
if (layer.visible || this.visible) {
this.visible = true;
} else {
this.visible = false;
}
this.children.push(layer);
return;
}
Expand Down
4 changes: 4 additions & 0 deletions src/mapboxgl/web-map/WebMapV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ export default class WebMap extends WebMapBase {

private _createMVTBaseLayer(layerInfo, addedCallback?: Function) {
let url = layerInfo.dataSource.url;
const visible = layerInfo.visible;
if (url.indexOf('/restjsr/') > -1 && !/\/style\.json$/.test(url)) {
url += '/style.json';
}
Expand All @@ -427,6 +428,9 @@ export default class WebMap extends WebMapBase {
addedCallback && addedCallback();
return;
}
style.layers.forEach(layer => {
layer.layout && (layer.layout.visibility = visible ? 'visible' : 'none');
});
// @ts-ignore
this.map.addStyle(style);
const layerIds = [];
Expand Down
23 changes: 23 additions & 0 deletions src/mapboxgl/web-map/__tests__/WebMapViewModel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2579,4 +2579,27 @@ describe('WebMapViewModel.spec', () => {
};
viewModel.on({ addlayerssucceeded: callback });
});

it('MAPBOXSTYLE visible false', async done => {
const mvtLayerClone = JSON.parse(JSON.stringify(mvtLayer));
mvtLayerClone.layers[0].visible = false;
const fetchResource = {
'https://fakeiportal.supermap.io/iportal/web/config/portal.json': iportal_serviceProxy,
'https://fakeiportal.supermap.io/iportal/web/maps/123/map.json': mvtLayerClone,
'https://fakeiportal.supermap.io/iportal/web/datas/676516522/content.json?pageSize=9999999&currentPage=1&parentResType=MAP&parentResId=123':layerData_CSV,
'http://fake/iserver/services/map-4548new/restjsr/v1/vectortile/maps/ChinaqxAlberts_4548%40fl-new/style.json': styleJson
};
mockFetch(fetchResource);
const viewModel = new WebMapViewModel(commonId, { ...commonOption });
const callback = function (data) {
const appreciableLayers = viewModel.getAppreciableLayers();
expect(appreciableLayers[1].id).toBe('ChinaqxAlberts_4548@fl-new');
expect(appreciableLayers[1].visible).toBe(false);
expect(appreciableLayers[2].id).toBe('民航数据');
done();
};
viewModel.on({ addlayerssucceeded: callback });
await flushPromises();
jest.advanceTimersByTime(0);
});
});

0 comments on commit 702dea4

Please sign in to comment.