|
|
|
@ -6,7 +6,7 @@ import * as L from 'leaflet';
|
|
|
|
|
import 'leaflet/dist/leaflet.css';
|
|
|
|
|
import { Pin } from '../../model/Pin';
|
|
|
|
|
import { AutocompleteService } from '../../services/auto-complete/auto-complete.service';
|
|
|
|
|
import { MapReloadService } from '../../services/map-reload/map-reload.service'; // Assurez-vous d'importer le service de rechargement de la carte
|
|
|
|
|
import { MapReloadService } from '../../services/map-reload/map-reload.service';
|
|
|
|
|
import { PinService } from '../../services/pin/pin.service';
|
|
|
|
|
import { PinMarkerComponent } from '../pin-marker/pin-marker.component';
|
|
|
|
|
|
|
|
|
@ -33,7 +33,7 @@ export class LeafletMapComponent implements OnInit {
|
|
|
|
|
private autocompleteService: AutocompleteService,
|
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
|
private router: Router,
|
|
|
|
|
private mapReloadService: MapReloadService // Assurez-vous d'importer le service de rechargement de la carte
|
|
|
|
|
private mapReloadService: MapReloadService
|
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
@ -74,34 +74,38 @@ export class LeafletMapComponent implements OnInit {
|
|
|
|
|
this.allPins = pins;
|
|
|
|
|
this.extractPersons(pins);
|
|
|
|
|
|
|
|
|
|
const countrySet = new Set<string>();
|
|
|
|
|
const requests = pins.map((pin) =>
|
|
|
|
|
this.autocompleteService
|
|
|
|
|
.getAddressFromCoordinates(pin.location[0], pin.location[1])
|
|
|
|
|
.toPromise()
|
|
|
|
|
.then((res: any) => {
|
|
|
|
|
const address = res?.address;
|
|
|
|
|
const country =
|
|
|
|
|
address?.country ||
|
|
|
|
|
this.extractLastFromDisplayName(res?.display_name);
|
|
|
|
|
if (country) {
|
|
|
|
|
this.pinCountries[pin.id] = country;
|
|
|
|
|
countrySet.add(country);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch((err: any) => {
|
|
|
|
|
console.error(
|
|
|
|
|
'Erreur lors de la récupération du pays pour le pin',
|
|
|
|
|
pin.id,
|
|
|
|
|
err
|
|
|
|
|
);
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Promise.all(requests).then(() => {
|
|
|
|
|
this.availableCountries = Array.from(countrySet).sort();
|
|
|
|
|
this.renderPins();
|
|
|
|
|
});
|
|
|
|
|
this.renderPins(); // Afficher d'abord les pins sans les filtres
|
|
|
|
|
this.loadCountriesForFiltrers(pins); // Ensuite, charger les pays en arrière-plan
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private loadCountriesForFiltrers(pins: Pin[]): void {
|
|
|
|
|
const countrySet = new Set<string>();
|
|
|
|
|
const requests = pins.map((pin) =>
|
|
|
|
|
this.autocompleteService
|
|
|
|
|
.getAddressFromCoordinates(pin.location[0], pin.location[1])
|
|
|
|
|
.toPromise()
|
|
|
|
|
.then((res: any) => {
|
|
|
|
|
const address = res?.address;
|
|
|
|
|
const country =
|
|
|
|
|
address?.country ||
|
|
|
|
|
this.extractLastFromDisplayName(res?.display_name);
|
|
|
|
|
if (country) {
|
|
|
|
|
this.pinCountries[pin.id] = country;
|
|
|
|
|
countrySet.add(country);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch((err: any) => {
|
|
|
|
|
console.error(
|
|
|
|
|
'Erreur lors de la récupération du pays pour le pin',
|
|
|
|
|
pin.id,
|
|
|
|
|
err
|
|
|
|
|
);
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Promise.all(requests).then(() => {
|
|
|
|
|
this.availableCountries = Array.from(countrySet).sort();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -221,35 +225,9 @@ export class LeafletMapComponent implements OnInit {
|
|
|
|
|
this.pinsService.getPins().subscribe((pins: Pin[]) => {
|
|
|
|
|
this.allPins = pins;
|
|
|
|
|
this.extractPersons(pins);
|
|
|
|
|
this.renderPins(); // Afficher d'abord les pins sans les filtres
|
|
|
|
|
|
|
|
|
|
const countrySet = new Set<string>();
|
|
|
|
|
const requests = pins.map((pin) =>
|
|
|
|
|
this.autocompleteService
|
|
|
|
|
.getAddressFromCoordinates(pin.location[0], pin.location[1])
|
|
|
|
|
.toPromise()
|
|
|
|
|
.then((res: any) => {
|
|
|
|
|
const address = res?.address;
|
|
|
|
|
const country =
|
|
|
|
|
address?.country ||
|
|
|
|
|
this.extractLastFromDisplayName(res?.display_name);
|
|
|
|
|
if (country) {
|
|
|
|
|
this.pinCountries[pin.id] = country;
|
|
|
|
|
countrySet.add(country);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch((err: any) => {
|
|
|
|
|
console.error(
|
|
|
|
|
'Erreur lors de la récupération du pays pour le pin',
|
|
|
|
|
pin.id,
|
|
|
|
|
err
|
|
|
|
|
);
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Promise.all(requests).then(() => {
|
|
|
|
|
this.availableCountries = Array.from(countrySet).sort();
|
|
|
|
|
this.renderPins();
|
|
|
|
|
});
|
|
|
|
|
this.loadCountriesForFiltrers(pins); // Ensuite, charger les pays en arrière-plan
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|