Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Loading