|
|
|
@ -10,11 +10,11 @@ import { FormsModule } from '@angular/forms';
|
|
|
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
|
|
|
|
import * as L from 'leaflet';
|
|
|
|
|
import { Pin } from '../../model/Pin';
|
|
|
|
|
import { AutocompleteService } from '../../services/auto-complete/auto-complete.service';
|
|
|
|
|
import { MapReloadService } from '../../services/map-reload/map-reload.service';
|
|
|
|
|
import { ModalService } from '../../services/modal/modal.service';
|
|
|
|
|
import { PinService } from '../../services/pin/pin.service';
|
|
|
|
|
import { PinMarkerComponent } from '../pin-marker/pin-marker.component';
|
|
|
|
|
import { AutocompleteService } from '../../services/auto-complete/auto-complete.service';
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-leaflet-map',
|
|
|
|
@ -112,11 +112,13 @@ export class LeafletMapComponent implements OnInit {
|
|
|
|
|
|
|
|
|
|
// Créer le contenu du menu contextuel
|
|
|
|
|
const menuContent = document.createElement('div');
|
|
|
|
|
menuContent.className = 'bg-white dark:bg-gray-800 rounded-lg shadow-lg overflow-hidden';
|
|
|
|
|
|
|
|
|
|
menuContent.className =
|
|
|
|
|
'bg-white dark:bg-gray-800 rounded-lg shadow-lg overflow-hidden';
|
|
|
|
|
|
|
|
|
|
const addPinButton = document.createElement('button');
|
|
|
|
|
addPinButton.className = 'w-full px-4 py-2.5 text-sm font-medium text-gray-900 dark:text-white hover:bg-gray-100 dark:hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-blue-500 dark:focus:ring-blue-600 flex items-center gap-2';
|
|
|
|
|
|
|
|
|
|
addPinButton.className =
|
|
|
|
|
'w-full px-4 py-2.5 text-sm font-medium text-gray-900 dark:text-white hover:bg-gray-100 dark:hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-blue-500 dark:focus:ring-blue-600 flex items-center gap-2';
|
|
|
|
|
|
|
|
|
|
// Ajouter l'icône de pin
|
|
|
|
|
const pinIcon = document.createElement('span');
|
|
|
|
|
pinIcon.innerHTML = `
|
|
|
|
@ -125,13 +127,13 @@ export class LeafletMapComponent implements OnInit {
|
|
|
|
|
<path stroke-linecap="round" stroke-linejoin="round" d="M19.5 10.5c0 7.142-7.5 11.25-7.5 11.25S4.5 17.642 4.5 10.5a7.5 7.5 0 1 1 15 0Z" />
|
|
|
|
|
</svg>
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const buttonText = document.createElement('span');
|
|
|
|
|
buttonText.textContent = 'Ajouter un pin ici';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addPinButton.appendChild(pinIcon);
|
|
|
|
|
addPinButton.appendChild(buttonText);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addPinButton.onclick = () => {
|
|
|
|
|
this.addPinAtLocation(latlng);
|
|
|
|
|
if (this.contextMenu) {
|
|
|
|
@ -147,7 +149,7 @@ export class LeafletMapComponent implements OnInit {
|
|
|
|
|
closeButton: false,
|
|
|
|
|
className: 'context-menu-popup',
|
|
|
|
|
maxWidth: 200,
|
|
|
|
|
offset: [0, -10]
|
|
|
|
|
offset: [0, -10],
|
|
|
|
|
})
|
|
|
|
|
.setLatLng(latlng)
|
|
|
|
|
.setContent(menuContent)
|
|
|
|
@ -165,15 +167,15 @@ export class LeafletMapComponent implements OnInit {
|
|
|
|
|
this.modalService.openModal('add-pin-modal', [], {
|
|
|
|
|
location: address?.display_name || '',
|
|
|
|
|
complete_address: address?.display_name || '',
|
|
|
|
|
coordinates: [latlng.lat, latlng.lng]
|
|
|
|
|
coordinates: [latlng.lat, latlng.lng],
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Erreur lors de la récupération de l\'adresse:', error);
|
|
|
|
|
console.error("Erreur lors de la récupération de l'adresse:", error);
|
|
|
|
|
// En cas d'erreur, ouvrir la modal avec juste les coordonnées
|
|
|
|
|
this.modalService.openModal('add-pin-modal', [], {
|
|
|
|
|
location: `${latlng.lat}, ${latlng.lng}`,
|
|
|
|
|
complete_address: `${latlng.lat}, ${latlng.lng}`,
|
|
|
|
|
coordinates: [latlng.lat, latlng.lng]
|
|
|
|
|
coordinates: [latlng.lat, latlng.lng],
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -201,15 +203,18 @@ export class LeafletMapComponent implements OnInit {
|
|
|
|
|
|
|
|
|
|
private extractPersons(pins: Pin[]): void {
|
|
|
|
|
const personsSet = new Set<string>();
|
|
|
|
|
const regex = /@(\w+)/g;
|
|
|
|
|
|
|
|
|
|
// Pour chaque pin, récupérer ses partages
|
|
|
|
|
pins.forEach((pin) => {
|
|
|
|
|
const desc = pin.description || '';
|
|
|
|
|
let match;
|
|
|
|
|
while ((match = regex.exec(desc)) !== null) {
|
|
|
|
|
personsSet.add(match[1]);
|
|
|
|
|
}
|
|
|
|
|
this.pinsService.getPinShares(pin.id).subscribe((response: any) => {
|
|
|
|
|
if (response && response.shares) {
|
|
|
|
|
response.shares.forEach((share: any) => {
|
|
|
|
|
personsSet.add(share.username);
|
|
|
|
|
});
|
|
|
|
|
this.availablePersons = Array.from(personsSet).sort();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
this.availablePersons = Array.from(personsSet).sort();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onCountryChange(country: string) {
|
|
|
|
@ -288,8 +293,8 @@ export class LeafletMapComponent implements OnInit {
|
|
|
|
|
const zoom = this.map.getZoom();
|
|
|
|
|
const offsetLat = 0.05 / Math.pow(2, zoom - 10);
|
|
|
|
|
this.map.setView(
|
|
|
|
|
L.latLng(latlng.lat + offsetLat, latlng.lng),
|
|
|
|
|
zoom
|
|
|
|
|
L.latLng(latlng.lat + offsetLat, latlng.lng),
|
|
|
|
|
zoom
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -311,7 +316,9 @@ export class LeafletMapComponent implements OnInit {
|
|
|
|
|
public loadPins(): void {
|
|
|
|
|
this.pinsService.getPins().subscribe((pins: Pin[]) => {
|
|
|
|
|
// Supprimer du body toutes les divs confirm-modal-* / share-modal-* / edit-pin-popup-*
|
|
|
|
|
const modals = document.querySelectorAll('div[id^="confirm-modal-"], div[id^="share-modal-"], div[id^="edit-pin-popup-"]');
|
|
|
|
|
const modals = document.querySelectorAll(
|
|
|
|
|
'div[id^="confirm-modal-"], div[id^="share-modal-"], div[id^="edit-pin-popup-"]'
|
|
|
|
|
);
|
|
|
|
|
modals.forEach((modal) => {
|
|
|
|
|
modal.remove();
|
|
|
|
|
});
|
|
|
|
|