Skip to content

Commit

Permalink
Fixes geosolutions-it#1179: zoom to extent improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarto committed Oct 19, 2016
1 parent d757ced commit 628265e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
5 changes: 3 additions & 2 deletions web/client/actions/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ function panTo(center) {
};
}

function zoomToExtent(extent, crs) {
function zoomToExtent(extent, crs, minZoom) {
return {
type: ZOOM_TO_EXTENT,
extent,
crs
crs,
minZoom
};
}

Expand Down
25 changes: 25 additions & 0 deletions web/client/reducers/__tests__/map-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,31 @@ describe('Test the map reducer', () => {
expect(state.zoom).toBe(2);

});

it('zoom to extent edge cases', () => {
const action = {
type: 'ZOOM_TO_EXTENT',
extent: [160, 44, -170, 46],
crs: "EPSG:4326"
};

const action2 = {
type: 'ZOOM_TO_EXTENT',
extent: [-190, -100, 190, 100],
crs: "EPSG:4326",
minZoom: 3
};

var state = mapConfig({projection: "EPSG:4326", size: {width: 400, height: 400}}, action);
expect(state.mapStateSource).toBe(undefined);
expect(state.center.x).toBe(-5);
expect(state.center.y).toBe(45);
expect(state.zoom).toBe(17);

state = mapConfig({projection: "EPSG:4326", size: {width: 400, height: 400}}, action2);
expect(state.zoom).toBe(3);
});

it('change map style', () => {
const action = {
type: 'CHANGE_MAP_STYLE',
Expand Down
9 changes: 4 additions & 5 deletions web/client/reducers/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,13 @@ 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) {
// center by the max. extent defined in the map's config
let center = MapUtils.getCenterForExtent(wgs84BBox, "EPSG:4326");

if (bbox) {
let center = CoordinatesUtils.reproject(MapUtils.getCenterForExtent(action.extent, action.crs), action.crs, '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;
zoom = action.minZoom || 2;
} else {
let mapBBox = CoordinatesUtils.reprojectBbox(action.extent, action.crs, state.projection || "EPSG:4326");
// NOTE: STATE should contain size !!!
Expand Down
7 changes: 6 additions & 1 deletion web/client/utils/CatalogUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ const getWMSBBox = (record) => {
northBoundLatitude: 90.0
};
}
return bbox;
return {
westBoundLongitude: parseFloat(bbox.westBoundLongitude),
southBoundLatitude: parseFloat(bbox.southBoundLatitude),
eastBoundLongitude: parseFloat(bbox.eastBoundLongitude),
northBoundLatitude: parseFloat(bbox.northBoundLatitude)
};
};

const converters = {
Expand Down

0 comments on commit 628265e

Please sign in to comment.