Skip to content

Commit

Permalink
【fix】 修复query组件查询结果fitbounds时,超多180,定位不对的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
songyumeng committed Sep 14, 2024
1 parent fc56700 commit b85b5cb
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/mapboxgl/query/QueryViewModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ export default class QueryViewModel extends mapboxgl.Evented {
const bounds = bbox(transformScale(envelope(source.data), 1.7));
this.map.fitBounds(
[
[bounds[0], bounds[1]],
[bounds[2], bounds[3]]
[Math.max(bounds[0], -180), bounds[1]],
[Math.min(bounds[2], 180), bounds[3]]
],
{ maxZoom: 17 }
);
Expand Down
4 changes: 3 additions & 1 deletion src/mapboxgl/query/__tests__/Query.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,11 @@ describe('query', () => {
await mapSubComponentLoaded(wrapper);
expect(wrapper.vm.mapTarget).toBe('map');
const spyAddlayer = jest.spyOn(wrapper.vm.map, 'addLayer');
const spyBounds = jest.spyOn(wrapper.vm.map, 'fitBounds');
const spyquery = jest.spyOn(wrapper.vm, 'query');
wrapper.vm.viewModel.on('querysucceeded', () => {
wrapper.vm.viewModel.on('querysucceeded', (e) => {
expect(spyAddlayer).toBeCalled();
expect(spyBounds).toBeCalledWith(expect.arrayContaining([[180, 26.089841338515914]]),expect.anything());
done();
});
wrapper.vm.jobInfos[0].spaceFilter = 'mapBounds';
Expand Down
2 changes: 1 addition & 1 deletion src/mapboxgl/tdt/_utils/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ export const addPoints = (map, sourceName, features) => {
};
}
const bounds = bbox(transformScale(envelope(features), 1.7));
map.fitBounds([[bounds[0], bounds[1]], [bounds[2], bounds[3]]], { maxZoom: 17 });
map.fitBounds([[Math.max(bounds[0], -180), bounds[1]], [Math.min(bounds[2], 180), bounds[3]]], { maxZoom: 17 });
}
};
// 清空search, route图层
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ export default class AnimateMarkerLayerViewModel extends mapboxgl.Evented {
this.fitBounds &&
this.map.fitBounds(
[
[bounds[0], bounds[1]],
[bounds[2], bounds[3]]
[Math.max(bounds[0], -180), bounds[1]],
[Math.min(bounds[2], 180), bounds[3]]
],
{ maxZoom: 17 }
);
Expand Down
3 changes: 1 addition & 2 deletions test/unit/mocks/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const fakeDataServiceResult = {
[
[
[101.84004968, 26.0859968692659],

[101.95654423, 26.0888446242659],
[101.84004968, 26.0859968692659]
]
Expand Down Expand Up @@ -70,7 +69,7 @@ const fakeMapServiceResult = {
[
[
[101.84004968, 26.0859968692659],

[181.95654423, 26.0888446242659],
[101.95654423, 26.0888446242659],
[101.84004968, 26.0859968692659]
]
Expand Down

0 comments on commit b85b5cb

Please sign in to comment.