From cbff358bc5dd24a07f46471fb93c6d9e5fa6871b Mon Sep 17 00:00:00 2001 From: Alix JEUDI--LEMOINE Date: Wed, 8 Jan 2025 08:43:08 +0100 Subject: [PATCH] :sparkles: Prevent zooming out too much & prevent dragging the map out of bound --- src/app/components/leaflet-map/leaflet-map.component.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/app/components/leaflet-map/leaflet-map.component.ts b/src/app/components/leaflet-map/leaflet-map.component.ts index 9c2f936..4c0dd38 100644 --- a/src/app/components/leaflet-map/leaflet-map.component.ts +++ b/src/app/components/leaflet-map/leaflet-map.component.ts @@ -19,7 +19,14 @@ export class LeafletMapComponent implements OnInit { private initializeMap(): void { // Initialize the map - this.map = L.map('map').setView([46.603354, 1.888334], 6); + this.map = L.map('map', { + maxBounds: L.latLngBounds( + L.latLng(-90, -180), // South-West + L.latLng(90, 180) // North-East + ), + maxBoundsViscosity: 1.0, // Prevent dragging the map out of bounds + minZoom: 2, // Prevent zooming out too much + }).setView([46.603354, 1.888334], 6); // Add OpenStreetMap tiles L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {