From e0c23402f71d0554a2ab7afaa8434d41e2827726 Mon Sep 17 00:00:00 2001 From: ISA Date: Wed, 14 Aug 2024 15:43:53 +0200 Subject: [PATCH] Adjust zoom conditions: zoomIn only if zoom < 14, zoomOut only if zoom > 7 --- utils/zoomAndCenterUtils.js | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/utils/zoomAndCenterUtils.js b/utils/zoomAndCenterUtils.js index 4d1e46c4b..5bd87b9e2 100644 --- a/utils/zoomAndCenterUtils.js +++ b/utils/zoomAndCenterUtils.js @@ -14,9 +14,14 @@ export const zoomIn = (e, map) => { console.error("map is not defined in zoomIn"); return; } - map.flyTo(e.latlng, 12); - localStorage.setItem("mapZoom", map.getZoom()); - localStorage.setItem("mapCenter", JSON.stringify(map.getCenter())); + + const currentZoom = map.getZoom(); + + if (currentZoom < 14) { + map.flyTo(e.latlng, 14); + localStorage.setItem("mapZoom", 16); + localStorage.setItem("mapCenter", JSON.stringify(map.getCenter())); + } }; export const zoomOut = (map) => { @@ -24,14 +29,18 @@ export const zoomOut = (map) => { console.error("map is not defined in zoomOut"); return; } - const x = 51.41321407879154; - const y = 7.739617925303934; - const zoom = 7; - //console.log("map"); - //console.log(map); - map.flyTo([x, y], zoom); - localStorage.setItem("mapZoom", map.getZoom()); - localStorage.setItem("mapCenter", JSON.stringify(map.getCenter())); + + const currentZoom = map.getZoom(); + + if (currentZoom > 7) { + const x = 51.41321407879154; + const y = 7.739617925303934; + const zoom = 7; + + map.flyTo([x, y], zoom); + localStorage.setItem("mapZoom", zoom); + localStorage.setItem("mapCenter", JSON.stringify(map.getCenter())); + } }; export const centerHere = (e, map) => {