-
-
-
-
Buscando satélites...
-
+
+
+
+
+
+
En ruta hacia tu domicilio
+
¡Técnico en camino!
+
Prepárate, el técnico está a punto de llegar a tu ubicación.
`;
- mapsToInit.push(srv.id);
}
else if (srv.status_name === 'En Reparación') {
statusHtml = `
@@ -262,56 +254,8 @@
setTimeout(() => {
document.getElementById('loader').classList.add('hidden');
document.getElementById('mainContent').classList.remove('hidden');
-
- mapsToInit.forEach(id => initLiveMap(id));
}, 300);
}
-
- function initLiveMap(serviceId) {
- if(!document.getElementById(`liveMap-${serviceId}`)) return;
-
- 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]);
-
- 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});
-
- fetchWorkerLocation(serviceId);
- setInterval(() => fetchWorkerLocation(serviceId), 10000);
- }
-
- async function fetchWorkerLocation(serviceId) {
- try {
- const res = await fetch(`${API_URL}/public/portal/${urlToken}/location/${serviceId}`);
- const data = await res.json();
-
- if (data.ok && data.location) {
- const loader = document.getElementById(`map-loader-${serviceId}`);
- if(loader) loader.classList.add('hidden');
-
- const lat = parseFloat(data.location.lat);
- const lng = parseFloat(data.location.lng);
-
- if (!liveMaps[serviceId].hasLayer(liveMarkers[serviceId])) {
- liveMarkers[serviceId].addTo(liveMaps[serviceId]);
- liveMaps[serviceId].setView([lat, lng], 15);
- } else {
- liveMarkers[serviceId].setLatLng([lat, lng]);
- liveMaps[serviceId].flyTo([lat, lng], 16, { animate: true, duration: 1.5 });
- }
- } else {
- // MEJORA: Mensaje claro si el técnico no ha encendido su GPS todavía
- const p = document.querySelector(`#map-loader-${serviceId} p`);
- if(p) p.innerText = "ESPERANDO SEÑAL GPS DEL TÉCNICO...";
- }
- } catch(e) {}
- }