diff --git a/index.html b/index.html
index 932fc48..9b59a52 100644
--- a/index.html
+++ b/index.html
@@ -266,6 +266,32 @@
setInterval(() => fetchWorkerLocation(serviceId), 10000);
}
+ // ==========================================
+ // LÓGICA DE MAPA EN TIEMPO REAL (CORREGIDA)
+ // ==========================================
+ function initLiveMap(serviceId) {
+ // CORRECCIÓN: El ID correcto es liveMap- (no map-)
+ if(!document.getElementById(`liveMap-${serviceId}`)) return;
+
+ // 1. Configuramos el mapa de Leaflet
+ liveMaps[serviceId] = L.map(`liveMap-${serviceId}`, { zoomControl: false, attributionControl: false }).setView([40.416775, -3.703790], 6);
+ L.tileLayer('https://{s}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}{r}.png').addTo(liveMaps[serviceId]);
+
+ // 2. Creamos un icono HTML personalizado (un puntito azul que brilla)
+ const carIcon = L.divIcon({
+ className: 'custom-div-icon',
+ html: `
`,
+ iconSize: [20, 20],
+ iconAnchor: [10, 10]
+ });
+
+ liveMarkers[serviceId] = L.marker([40.416775, -3.703790], {icon: carIcon});
+
+ // 3. Ejecutamos la búsqueda de coordenadas cada 10 segundos
+ fetchWorkerLocation(serviceId);
+ setInterval(() => fetchWorkerLocation(serviceId), 10000);
+ }
+
async function fetchWorkerLocation(serviceId) {
try {
const res = await fetch(`${API_URL}/public/portal/${urlToken}/location/${serviceId}`);
@@ -273,7 +299,7 @@
if (data.ok && data.location) {
const loader = document.getElementById(`map-loader-${serviceId}`);
- if(loader) loader.classList.add('hidden'); // Ocultar pantalla de "Buscando satélites"
+ if(loader) loader.classList.add('hidden'); // Ocultar pantalla de carga
const lat = parseFloat(data.location.lat);
const lng = parseFloat(data.location.lng);
@@ -287,6 +313,10 @@
liveMarkers[serviceId].setLatLng([lat, lng]);
liveMaps[serviceId].flyTo([lat, lng], 16, { animate: true, duration: 1.5 });
}
+ } else {
+ // Si el técnico aún no ha mandado su ubicación, avisamos al cliente
+ const p = document.querySelector(`#map-loader-${serviceId} p`);
+ if(p) p.innerText = "ESPERANDO SEÑAL GPS DEL TÉCNICO...";
}
} catch(e) {}
}