From 2e5a9c20bcdb19e43fecb5a62c99027c8dcaf734 Mon Sep 17 00:00:00 2001 From: Vivia Nikolaidou Date: Sat, 28 Sep 2024 20:48:05 +0200 Subject: [PATCH] fix(ui): Fix zoom level after zooming in and back out again not ending up where it started --- frontend/src/map/Map.tsx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/frontend/src/map/Map.tsx b/frontend/src/map/Map.tsx index 93b2e9a581..64789a1745 100644 --- a/frontend/src/map/Map.tsx +++ b/frontend/src/map/Map.tsx @@ -48,8 +48,7 @@ export const MapContainer = styled(Box)({ }); const SCROLL_PARAMETERS = { - ZOOM_IN_MULTIPLIER: 4/3 - 1, - ZOOM_OUT_MULTIPLIER: 1 - 3/4, + ZOOM_MULTIPLIER: 1/4, PIXELS_PER_FULL_STEP: 100 }; @@ -476,9 +475,13 @@ abstract class Map extends React.Component

{ } }, 250); - - const fullStep = evt.deltaY < 0 ? SCROLL_PARAMETERS.ZOOM_IN_MULTIPLIER : SCROLL_PARAMETERS.ZOOM_OUT_MULTIPLIER; - let factor = 1 - (fullStep * (evt.deltaY / SCROLL_PARAMETERS.PIXELS_PER_FULL_STEP)); + const scaledPixels = evt.deltaY * (SCROLL_PARAMETERS.ZOOM_MULTIPLIER / SCROLL_PARAMETERS.PIXELS_PER_FULL_STEP); + let factor; + if (evt.deltaY < 0) { + factor = 1 / (1 + scaledPixels); + } else { + factor = 1 - scaledPixels; + } const { scaleX: currentScaleFactor } = this.ctxWrapper.getScaleFactor();