diff --git a/angular.json b/angular.json index d03186d..f7104ca 100644 --- a/angular.json +++ b/angular.json @@ -34,6 +34,8 @@ "src/styles.css", "node_modules/leaflet/dist/leaflet.css", "node_modules/intro.js/introjs.css", + "node_modules/leaflet.markercluster/dist/MarkerCluster.css", + "node_modules/leaflet.markercluster/dist/MarkerCluster.Default.css", "src/introjs-modern.css"], "scripts": [ "node_modules/flowbite/dist/flowbite.min.js", diff --git a/package-lock.json b/package-lock.json index 72bfd7b..616b566 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,6 +22,7 @@ "flowbite": "^2.5.2", "intro.js": "^7.2.0", "leaflet": "^1.9.4", + "leaflet.markercluster": "^1.5.3", "ngx-cookie-service": "^19.0.0", "rxjs": "~7.8.0", "tslib": "^2.3.0", @@ -33,6 +34,7 @@ "@angular/compiler-cli": "^19.0.0", "@types/jasmine": "~5.1.0", "@types/leaflet": "^1.9.15", + "@types/leaflet.markercluster": "^1.5.5", "autoprefixer": "^10.4.20", "jasmine-core": "~5.4.0", "karma": "~6.4.0", @@ -4672,6 +4674,16 @@ "@types/geojson": "*" } }, + "node_modules/@types/leaflet.markercluster": { + "version": "1.5.5", + "resolved": "https://registry.npmjs.org/@types/leaflet.markercluster/-/leaflet.markercluster-1.5.5.tgz", + "integrity": "sha512-TkWOhSHDM1ANxmLi+uK0PjsVcjIKBr8CLV2WoF16dIdeFmC0Cj5P5axkI3C1Xsi4+ht6EU8+BfEbbqEF9icPrg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/leaflet": "*" + } + }, "node_modules/@types/mime": { "version": "1.3.5", "resolved": "https://registry.npmjs.org/@types/mime/-/mime-1.3.5.tgz", @@ -8733,6 +8745,15 @@ "resolved": "https://registry.npmjs.org/leaflet/-/leaflet-1.9.4.tgz", "integrity": "sha512-nxS1ynzJOmOlHp+iL3FyWqK89GtNL8U8rvlMOsQdTTssxZwCXh8N2NB3GDQOL+YR3XnWyZAxwQixURb+FA74PA==" }, + "node_modules/leaflet.markercluster": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/leaflet.markercluster/-/leaflet.markercluster-1.5.3.tgz", + "integrity": "sha512-vPTw/Bndq7eQHjLBVlWpnGeLa3t+3zGiuM7fJwCkiMFq+nmRuG3RI3f7f4N4TDX7T4NpbAXpR2+NTRSEGfCSeA==", + "license": "MIT", + "peerDependencies": { + "leaflet": "^1.3.1" + } + }, "node_modules/less": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/less/-/less-4.2.0.tgz", diff --git a/package.json b/package.json index 2a70cc6..41db478 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "flowbite": "^2.5.2", "intro.js": "^7.2.0", "leaflet": "^1.9.4", + "leaflet.markercluster": "^1.5.3", "ngx-cookie-service": "^19.0.0", "rxjs": "~7.8.0", "tslib": "^2.3.0", @@ -36,6 +37,7 @@ "@angular/compiler-cli": "^19.0.0", "@types/jasmine": "~5.1.0", "@types/leaflet": "^1.9.15", + "@types/leaflet.markercluster": "^1.5.5", "autoprefixer": "^10.4.20", "jasmine-core": "~5.4.0", "karma": "~6.4.0", diff --git a/src/app/components/leaflet-map/leaflet-map.component.ts b/src/app/components/leaflet-map/leaflet-map.component.ts index 47b5eaf..75ff1d4 100644 --- a/src/app/components/leaflet-map/leaflet-map.component.ts +++ b/src/app/components/leaflet-map/leaflet-map.component.ts @@ -9,6 +9,7 @@ import { import { FormsModule } from '@angular/forms'; import { ActivatedRoute, Router } from '@angular/router'; import * as L from 'leaflet'; +import 'leaflet.markercluster'; import { Pin } from '../../model/Pin'; import { AutocompleteService } from '../../services/auto-complete/auto-complete.service'; import { MapReloadService } from '../../services/map-reload/map-reload.service'; @@ -26,6 +27,7 @@ import { IntroService } from '../../services/intro/intro.service'; export class LeafletMapComponent implements OnInit { private map!: L.Map; private markersMap: { [key: string]: L.Marker } = {}; + private markerClusterGroup!: L.MarkerClusterGroup; private allPins: Pin[] = []; private pinCountries: { [pinId: string]: string } = {}; private contextMenu: L.Popup | null = null; @@ -91,6 +93,10 @@ export class LeafletMapComponent implements OnInit { }).addTo(this.map); this.map.attributionControl.setPrefix(''); + // Initialiser le groupe de clusters + this.markerClusterGroup = L.markerClusterGroup(); + this.map.addLayer(this.markerClusterGroup); + // Ajouter l'événement de clic droit sur la carte this.map.on('contextmenu', (e: L.LeafletMouseEvent) => { e.originalEvent.preventDefault(); @@ -242,6 +248,7 @@ export class LeafletMapComponent implements OnInit { Object.values(this.markersMap).forEach((marker) => this.map.removeLayer(marker) ); + this.markerClusterGroup.clearLayers(); this.markersMap = {}; const visitedIcon = this.createDivIcon(` @@ -316,6 +323,7 @@ export class LeafletMapComponent implements OnInit { } }) .unsubscribe(); + this.markerClusterGroup.addLayer(marker); }); }