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

[Bug] Fix center map accuracy #1502

Merged
merged 4 commits into from
Jun 9, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/utils/projection-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import geoViewport from '@mapbox/geo-viewport';
import Console from 'global/console';

const MAPBOX_TILE_SIZE = 512;

function isLat(num) {
return Number.isFinite(num) && num <= 90 && num >= -90;
}
Expand Down Expand Up @@ -53,8 +55,14 @@ export function getCenterAndZoomFromBounds(bounds, {width, height}) {
return null;
}

const {zoom} = geoViewport.viewport(bounds, [width, height]);

// viewport(bounds, dimensions, minzoom, maxzoom, tileSize, allowFloat)
const {zoom} = geoViewport.viewport(
bounds,
[width, height],
undefined,
undefined,
MAPBOX_TILE_SIZE
);
// center being calculated by geo-vieweport.viewport has a complex logic that
// projects and then unprojects the coordinates to determine the center
// Calculating a simple average instead as that is the expected behavior in most of cases
Expand Down
4 changes: 2 additions & 2 deletions test/browser/components/geocoder-panel-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ test('GeocoderPanel - render', t => {

t.deepEqual(
{latitude: newVP.latitude, longitude: newVP.longitude, zoom: newVP.zoom},
{latitude: 57.5, longitude: 1.5, zoom: 5},
{latitude: 57.5, longitude: 1.5, zoom: 4},
'Should call updateMap action on onSelected w/ new viewport'
);

Expand All @@ -204,7 +204,7 @@ test('GeocoderPanel - render', t => {
const newVP2 = updateMap.args[1][0];
t.deepEqual(
{latitude: newVP2.latitude, longitude: newVP2.longitude, zoom: newVP2.zoom},
{latitude: 55, longitude: 1, zoom: 12},
{latitude: 55, longitude: 1, zoom: 11},
'Should call updateMapaction on onSelected w/o bbox'
);

Expand Down
2 changes: 1 addition & 1 deletion test/browser/components/plot-container-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,6 @@ test('PlotContainer -> mount -> imageSize', t => {
-45.57105275929253,
'should set longitude when center: true'
);
t.equal(map.props.mapState.zoom, 2, 'should set zoom when center: true');
t.equal(map.props.mapState.zoom, 1, 'should set zoom when center: true');
t.end();
});
2 changes: 1 addition & 1 deletion test/node/reducers/map-state-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ test('#mapStateReducer -> FIT_BOUNDS', t => {

const expected = {
center: [5.7604079999999955, 45.189756500000016],
zoom: 11
zoom: 10
};

const stateWidthMapDimension = reducer(undefined, updateMap(mapUpdate));
Expand Down