Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bbox format in ZOOM_TO_EXTENT reducer #1277

Merged
merged 1 commit into from
Nov 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions web/client/reducers/__tests__/map-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,20 @@ describe('Test the map reducer', () => {
expect(state.mapStateSource).toBe(undefined);
expect(state.center.x).toBe(11);
expect(state.center.y).toBe(45);
expect(state.bbox).toExist();
expect(state.bbox.bounds).toExist();
expect(state.bbox.bounds.minx).toExist();
expect(state.bbox.bounds.miny).toExist();
expect(state.bbox.bounds.maxx).toExist();
expect(state.bbox.bounds.maxy).toExist();
state = mapConfig({projection: "EPSG:900913"}, action2);
expect(state.zoom).toBe(2);
expect(state.bbox).toExist();
expect(state.bbox.bounds).toExist();
expect(state.bbox.bounds.minx).toExist();
expect(state.bbox.bounds.miny).toExist();
expect(state.bbox.bounds.maxx).toExist();
expect(state.bbox.bounds.maxy).toExist();

});
it('change map style', () => {
Expand Down
16 changes: 9 additions & 7 deletions web/client/reducers/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,27 @@ function mapConfig(state = null, action) {
});
case ZOOM_TO_EXTENT: {
let zoom = 0;
let bbox = CoordinatesUtils.reprojectBbox(action.extent, action.crs, state.bbox && state.bbox.crs || "EPSG:4326");
let wgs84BBox = CoordinatesUtils.reprojectBbox(action.extent, action.crs, "EPSG:4326");
if (bbox && wgs84BBox) {
let bounds = CoordinatesUtils.reprojectBbox(action.extent, action.crs, state.bbox && state.bbox.crs || "EPSG:4326");
let wgs84BBounds = CoordinatesUtils.reprojectBbox(action.extent, action.crs, "EPSG:4326");
if (bounds && wgs84BBounds) {
// center by the max. extent defined in the map's config
let center = MapUtils.getCenterForExtent(wgs84BBox, "EPSG:4326");
let center = MapUtils.getCenterForExtent(wgs84BBounds, "EPSG:4326");
// workaround to get zoom 0 for -180 -90... - TODO do it better
let full = action.crs === "EPSG:4326" && action.extent && action.extent[0] <= -180 && action.extent[1] <= -90 && action.extent[2] >= 180 && action.extent[3] >= 90;
if ( full ) {
zoom = 2;
} else {
let mapBBox = CoordinatesUtils.reprojectBbox(action.extent, action.crs, state.projection || "EPSG:4326");
let mapBBounds = CoordinatesUtils.reprojectBbox(action.extent, action.crs, state.projection || "EPSG:4326");
// NOTE: STATE should contain size !!!
zoom = MapUtils.getZoomForExtent(mapBBox, state.size, 0, 21, null);
zoom = MapUtils.getZoomForExtent(mapBBounds, state.size, 0, 21, null);
}
let newbounds = {minx: bounds[0], miny: bounds[1], maxx: bounds[2], maxy: bounds[3]};
let newbbox = assign({}, state.bbox, {bounds: newbounds});
return assign({}, state, {
center,
zoom,
mapStateSource: action.mapStateSource,
bbox: bbox
bbox: newbbox
});
}
return state;
Expand Down