From 69434d00695faa0df1344b00be77a70f9c63e9e9 Mon Sep 17 00:00:00 2001 From: Tom Hicks Date: Thu, 21 Mar 2024 20:32:30 +0100 Subject: [PATCH] Fix changing zoom and center at once Previously, if you wanted to zoom in and pan the map in the same viewport operation, it would get "stuck" at certain latitudes. If you're zoomed right out such that the equator is at the center of your viewport, and want to zoom in to a point at a much higher zoom level away from the equator, because the center change is handled first, the center change is constrained, so the latitude doesn't change. Then the zoom happens, and you end up at the wrong place. By changing the order to zoom first, we ensure that the constraining that happens during the center change happens with the correct available center range. --- src/utils/transform.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/utils/transform.ts b/src/utils/transform.ts index 5f5cefe37..3d35def1a 100644 --- a/src/utils/transform.ts +++ b/src/utils/transform.ts @@ -57,17 +57,17 @@ export function applyViewStateToTransform(tr: Transform, props: MapboxProps): bo const v: Partial = props.viewState || props; let changed = false; + if ('zoom' in v) { + const zoom = tr.zoom; + tr.zoom = v.zoom; + changed = changed || zoom !== tr.zoom; + } if ('longitude' in v && 'latitude' in v) { const center = tr.center; // @ts-ignore tr.center = new center.constructor(v.longitude, v.latitude); changed = changed || center !== tr.center; } - if ('zoom' in v) { - const zoom = tr.zoom; - tr.zoom = v.zoom; - changed = changed || zoom !== tr.zoom; - } if ('bearing' in v) { const bearing = tr.bearing; tr.bearing = v.bearing;