From 1b4d54679a256536e359654603400b55c36cce6c Mon Sep 17 00:00:00 2001 From: Alexis <35.alexis.pele@gmail.com> Date: Mon, 11 Dec 2023 22:39:39 +0100 Subject: [PATCH] Map padding --- src/components/maps/WorldMap.astro | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/components/maps/WorldMap.astro b/src/components/maps/WorldMap.astro index d25e3c17..892cc8c4 100644 --- a/src/components/maps/WorldMap.astro +++ b/src/components/maps/WorldMap.astro @@ -39,6 +39,10 @@ const mobileZoomLevels = { maxZoom: 6.7 } +const inertiaDeceleration = 1500 +const maxBoundsPadding = 10 +const maxBoundsViscosity = .75 + // Initializes the map const map = L.map('world', { crs: L.CRS.Simple, @@ -47,6 +51,8 @@ const map = L.map('world', { zoom: minZoom, zoomSnap: 0, zoomControl: false, + inertiaDeceleration, + maxBoundsViscosity }) /** @@ -268,6 +274,19 @@ const rulerOptions = { const measureControl = L.control.measure(rulerOptions) measureControl.addTo(map) +map.setMaxBounds( + [ + [ + baseTileLayer.getBounds().getSouth() - maxBoundsPadding, + baseTileLayer.getBounds().getWest() - maxBoundsPadding + ], + [ + baseTileLayer.getBounds().getNorth() + maxBoundsPadding, + baseTileLayer.getBounds().getEast() + maxBoundsPadding + ] + ] +) + /** * SVG LAYERS */