up labourage

This commit is contained in:
Tykayn 2025-06-30 22:27:00 +02:00 committed by tykayn
parent 7cde6a56aa
commit 1c24ae1fea
4 changed files with 32 additions and 18 deletions

View file

@ -485,7 +485,7 @@
center: geojsonData.features[0].geometry.coordinates,
zoom: 14
});
window.mapInstance = map;
map.on('load', function() {
map_is_loaded = true;
document.getElementById('maploader').style.display = 'none';
@ -814,8 +814,10 @@ if(dc ){
document.addEventListener('DOMContentLoaded', function() {
const btn = document.getElementById('btn-geolocate');
btn && btn.addEventListener('click', function() {
console.log('[GEOLOC] Bouton cliqué');
if (!navigator.geolocation) {
alert('La géolocalisation n\'est pas supportée par ce navigateur.');
console.error('[GEOLOC] navigator.geolocation non supporté');
return;
}
btn.disabled = true;
@ -823,7 +825,9 @@ if(dc ){
navigator.geolocation.getCurrentPosition(function(pos) {
const lat = pos.coords.latitude;
const lon = pos.coords.longitude;
console.log('[GEOLOC] Position obtenue', lat, lon);
// MapLibre
console.log('[GEOLOC] mapInstance', window.mapInstance);
if (window.mapInstance && typeof window.mapInstance.flyTo === 'function') {
window.mapInstance.flyTo({center: [lon, lat], zoom: 15});
if (window._geoMarker) window.mapInstance.removeLayer('geo-marker');
@ -840,15 +844,14 @@ if(dc ){
});
window._geoMarker = true;
window._geoMarkerSource = true;
} else if (window.L && window.map) { // Leaflet
window.map.setView([lat, lon], 15);
if (window._geoMarker) window.map.removeLayer(window._geoMarker);
window._geoMarker = window.L.marker([lat, lon], {icon: window.L.icon({iconUrl: 'https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/icons/geo-alt-fill.svg', iconSize: [32,32]})}).addTo(window.map);
} else {
console.error('[GEOLOC] mapInstance non défini ou flyTo non disponible', window.mapInstance);
}
btn.disabled = false;
btn.innerHTML = '<i class="bi bi-geo-alt"></i> Me localiser';
}, function(err) {
alert('Impossible de vous localiser : ' + err.message);
console.error('[GEOLOC] Erreur de géolocalisation', err);
btn.disabled = false;
btn.innerHTML = '<i class="bi bi-geo-alt"></i> Me localiser';
});