From 44f09794f34b3b7e6999783596b0182c4cc0aea8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Beye?= Date: Mon, 1 Jan 2024 16:27:32 +0100 Subject: [PATCH] fix(ui): Improve map zoom range clipping --- frontend/src/map/Map.tsx | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/frontend/src/map/Map.tsx b/frontend/src/map/Map.tsx index 87ea4709..e60b24ad 100644 --- a/frontend/src/map/Map.tsx +++ b/frontend/src/map/Map.tsx @@ -422,15 +422,14 @@ abstract class Map extends React.Component

{ const fullStep = evt.deltaY < 0 ? SCROLL_PARAMETERS.ZOOM_IN_MULTIPLIER : SCROLL_PARAMETERS.ZOOM_OUT_MULTIPLIER; - const factor = 1 - (fullStep * (evt.deltaY / SCROLL_PARAMETERS.PIXELS_PER_FULL_STEP)); + let factor = 1 - (fullStep * (evt.deltaY / SCROLL_PARAMETERS.PIXELS_PER_FULL_STEP)); const { scaleX: currentScaleFactor } = this.ctxWrapper.getScaleFactor(); - if ( - (factor * currentScaleFactor < 0.4 && factor < 1) || - (factor * currentScaleFactor > 150 && factor > 1) - ) { - return; + if (factor * currentScaleFactor < 0.4 && factor < 1) { + factor = 0.4 / currentScaleFactor; + } else if (factor * currentScaleFactor > 150 && factor > 1) { + factor = 150 / currentScaleFactor; } const pt = this.ctxWrapper.mapPointToCurrentTransform(evt.offsetX, evt.offsetY); @@ -537,12 +536,12 @@ abstract class Map extends React.Component

{ protected scalePinch(evt: PinchMoveTouchHandlerEvent) : any { const { scaleX: currentScaleFactor } = this.ctxWrapper.getScaleFactor(); - const factor = evt.scale / this.touchHandlingState.lastScaleFactor; + let factor = evt.scale / this.touchHandlingState.lastScaleFactor; if (factor * currentScaleFactor < 0.4 && factor < 1) { - return; + factor = 0.4 / currentScaleFactor; } else if (factor * currentScaleFactor > 150 && factor > 1) { - return; + factor = 150 / currentScaleFactor; } this.touchHandlingState.lastScaleFactor = evt.scale;