Skip to content

Commit

Permalink
【fix】ISVJ-5236通过服务添加地图,希望自动读取地图中心点 review by qiwei
Browse files Browse the repository at this point in the history
  • Loading branch information
shallowdream218 committed Sep 27, 2023
1 parent 4b8b03c commit 533847d
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/mapboxgl/web-map/WebMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ interface controlProps {
viewModelProps: [
'mapId',
'serverUrl',
'mapOptions.center',
'mapOptions.zoom',
'mapOptions.center',
'mapOptions.style',
'mapOptions.crs',
'mapOptions.minZoom',
Expand Down
81 changes: 81 additions & 0 deletions src/mapboxgl/web-map/__tests__/WebMap.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -621,4 +621,85 @@ describe('WebMap.vue', () => {
expect(wrapper.vm.mapOptions.bearing).toBe(0);
done();
});
it('Verify the execution order of the set method', async done => {
jest.useFakeTimers();
wrapper = mount(SmWebMap, {
propsData: {
mapOptions: {
style: {
version: 8,
sources: {},
layers: []
},
center: [
0,
0
],
zoom: 1,
bearing: 0,
pitch: 0,
rasterTileSize: 256,
preserveDrawingBuffer: true,
container: 'map',
crs: 'EPSG:3857'
}
}
});
jest.advanceTimersByTime(0);
jest.useRealTimers();
await mapWrapperLoaded(wrapper);
const modifiedProps = {
mapOptions: {
...wrapper.props().mapOptions,
center: [116.84538255155, 39.7881922283],
crs: 'EPSG:4326',
zoom: 7,
style: {
version: 8,
sources: {
'iserver-tiles': {
type: 'raster',
tiles: [
'http://172.16.14.44:8090/iserver/services/map-world/rest/maps/%E4%B8%96%E7%95%8C%E5%9C%B0%E5%9B%BE_Day'
],
tileSize: 256,
prjCoordSys: {
epsgCode: 4326
},
rasterSource: 'iserver',
proxy: null
}
},
layers: [
{
id: 'simple-tiles',
type: 'raster',
source: 'iserver-tiles',
minzoom: 0,
maxzoom: 22
}
]
}
}
};
const executionOrder = [];
const setCenter = jest.spyOn(wrapper.vm.viewModel, 'setCenter');
setCenter.mockImplementation((center) => {
wrapper.vm.viewModel.map.setCenter(center);
executionOrder.push('setCenter');
});
const setZoom = jest.spyOn(wrapper.vm.viewModel, 'setZoom');
setZoom.mockImplementation((zoom) => {
wrapper.vm.viewModel.map.setZoom(zoom);
executionOrder.push('setZoom');
});
wrapper.setProps(modifiedProps);

expect(setCenter).toHaveBeenCalled();
expect(setZoom).toHaveBeenCalled();
expect(executionOrder[0]).toEqual('setZoom');
expect(wrapper.vm.map.getCenter().toArray()).toEqual([116.84538255155, 39.7881922283]);
expect(wrapper.vm.map.getZoom()).toEqual(7);
done();
});
});
3 changes: 3 additions & 0 deletions test/unit/mocks/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@ var Map = function (options) {
this.getZoom = function () {
return this.zoom;
};
this.setZoom = function(zoom) {
this.zoom = zoom;
};
this.getBearing = functor(0);
this.getPitch = functor(0);
this.getCenter = function () {
Expand Down

0 comments on commit 533847d

Please sign in to comment.