Skip to content
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
2 changes: 1 addition & 1 deletion src/reducers/src/map-state-updaters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ function updateViewportBasedOnBounds(state: MapState, newMapState: MapState) {
if (!booleanWithin(viewportBoundsPolygon, maxBoundsPolygon)) {
const {latitude, longitude, zoom} = fitBounds({
width: newMapState.width,
height: newMapState.width,
height: newMapState.height,
bounds: [
[newStateMaxBounds[0], newStateMaxBounds[1]],
[newStateMaxBounds[2], newStateMaxBounds[3]]
Expand Down
13 changes: 11 additions & 2 deletions src/utils/src/projection-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,27 @@ export function getCenterAndZoomFromBounds(bounds, {width, height}) {
}

// viewport(bounds, dimensions, minzoom, maxzoom, tileSize, allowFloat)
const {zoom} = geoViewport.viewport(
let {zoom} = geoViewport.viewport(
bounds,
[width, height],
undefined,
undefined,
MAPBOX_TILE_SIZE
MAPBOX_TILE_SIZE,
true
);
// 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
const center = [(bounds[0] + bounds[2]) / 2, (bounds[1] + bounds[3]) / 2];

// NOTE: this logic is used in deck.gl normalizeViewportProps
// This is required in order to prevent projection matrix mismatch between basemap and layers
const minZoom = Math.log2(height / MAPBOX_TILE_SIZE);
if (zoom <= minZoom) {
zoom = minZoom;
center[1] = 0;
Comment thread
igorDykhta marked this conversation as resolved.
}

return {zoom, center};
}

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 @@ -190,7 +190,7 @@ test('GeocoderPanel - render', t => {

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

Expand All @@ -201,7 +201,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: 11},
{latitude: 55, longitude: 1, zoom: 11.655698543267773},
'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 @@ -90,6 +90,6 @@ test('PlotContainer -> mount -> imageSize', t => {
-45.57105275929253,
'should set longitude when center: true'
);
t.equal(map.props.mapState.zoom, 1, 'should set zoom when center: true');
t.equal(map.props.mapState.zoom, 1.8721094288367688, '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 @@ -346,7 +346,7 @@ test('#mapStateReducer -> FIT_BOUNDS', t => {

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

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