fix: corrección de errores en mapa y filtros de horarios

This commit is contained in:
2026-02-27 21:24:26 -05:00
parent d33c4c4ab1
commit 8084032f25
4 changed files with 108 additions and 153 deletions

View File

@ -27,9 +27,9 @@ const mapStore = useMapStore();
const busStopStore = useBusStopStore();
const couponStore = useCouponStore();
const { map, isLoaded, error: mapsError, initMap, addCleanMarker, addHtmlMarker, setCenter, setZoom, addMarker, clearAllOverlays } = useGoogleMaps();
const { map, isLoaded, error: mapsError, initMap, addCleanMarker, addHtmlMarker, setCenter, setZoom, addMarker } = useGoogleMaps();
const { estasCargando: estasCargandoRuta, errorRuta } = useDirectionsRoute();
const { encontrarParadaCercana, limpiarCaminata, paradaCercana, distanciaMetros, duracionCaminata } = useParadaCercana();
const { encontrarParadaCercana, paradaCercana, distanciaMetros, duracionCaminata } = useParadaCercana();
const { calcularETA, busesActivos, cargando: etaCargando } = useETA();
const { procesarSeleccionDeRuta } = useFlujoPrincipal();
@ -107,7 +107,7 @@ function closeUberSearch() {
}
async function clearAllMapData() {
console.log('🤖 JARVIS: Iniciando PURGA nuclear...');
console.log('🤖 JARVIS: Iniciando PURGA nuclear centralizada...');
// 1. UI inmediata
showUberSearch.value = false;
@ -124,85 +124,23 @@ async function clearAllMapData() {
routeStore.clearSelection();
lastProcessedRouteId.value = null;
// 4. Limpiar markers locales
const sweep = (arrayRef: any) => {
if (!arrayRef.value) return;
arrayRef.value.forEach((m: any) => {
try { if (m && m.setMap) m.setMap(null); } catch (e) {}
});
arrayRef.value = [];
};
sweep(markers);
sweep(promoMarkers);
// Limpiar unidades de transporte
if (unitMarkers.value) {
unitMarkers.value.forEach((m: any) => {
try { if (m && m.setMap) m.setMap(null); } catch (e) {}
});
unitMarkers.value.clear();
}
// 5. Limpiar polilíneas (CORREGIDO: agregar walkingPolylineBorder)
if (polyline.value) {
polyline.value.setMap(null);
polyline.value = null;
}
if (walkingPolyline.value) {
walkingPolyline.value.setMap(null);
walkingPolyline.value = null;
}
// ✅ NUEVO: limpiar el borde blanco de la ruta caminando
if (walkingPolylineBorder.value) {
walkingPolylineBorder.value.setMap(null);
walkingPolylineBorder.value = null;
}
// 6. Limpiar pulso de parada óptima (CORREGIDO)
if (optimalStopPulse.value) {
try {
// Intentar setMap primero
if (typeof optimalStopPulse.value.setMap === 'function') {
optimalStopPulse.value.setMap(null);
}
// Si es un overlay HTML, también intentar remove()
if (typeof optimalStopPulse.value.remove === 'function') {
optimalStopPulse.value.remove();
}
// Si tiene onRemove (OverlayView pattern)
if (typeof optimalStopPulse.value.onRemove === 'function') {
optimalStopPulse.value.onRemove();
}
} catch(e) {
console.warn('SIBU | No se pudo limpiar optimalStopPulse:', e);
}
optimalStopPulse.value = null;
}
// 7. Limpiar composables
limpiarCaminata();
// 8. Barrido profundo de Google Maps overlays
if (typeof clearAllOverlays === 'function') {
try { clearAllOverlays(); } catch (e) {}
}
// 9. Purgación centralizada (useMapState)
// 4. LIMPIEZA CENTRALIZADA (useMapState)
// Esto limpia markers, renderers, polylines, overlays HTML, etc.
limpiarTodoCentralizado();
// 10. Restaurar SOLO el marcador del usuario
// 5. Limpiar referencias locales del componente (aunque no tengan mapa asignado ya)
markers.value = [];
promoMarkers.value = [];
unitMarkers.value.clear();
polyline.value = null;
walkingPolyline.value = null;
walkingPolylineBorder.value = null;
optimalStopPulse.value = null;
// 6. Restaurar SOLO el marcador del usuario si tenemos ubicación
await nextTick();
if (userCoords.value) {
const { lat, lng } = userCoords.value;
// Limpiar marcador anterior del usuario
if (userMarker.value) {
try {
if (userMarker.value.setMap) userMarker.value.setMap(null);
if (userMarker.value.remove) userMarker.value.remove();
} catch(e) {}
}
// Redibujar solo el sonar del usuario
userMarker.value = addHtmlMarker(
{ lat, lng },
sonarHtml,
@ -210,7 +148,7 @@ async function clearAllMapData() {
);
}
console.log('🤖 JARVIS: Purga completada. Solo queda el usuario ✓');
console.log('🤖 JARVIS: Purga completada ✓');
} catch (err) {
console.error('❌ JARVIS: Error en purga:', err);
}
@ -758,6 +696,8 @@ function calculateWalkingPath(origin: { lat: number, lng: number }, targetStop:
if (walkingPolyline.value) walkingPolyline.value.setMap(null);
if (walkingPolylineBorder.value) walkingPolylineBorder.value.setMap(null);
const { registrarPolyline: regPoly } = useMapState();
// CAPA 1: Borde blanco (Para dar contraste estilo Google Maps)
walkingPolylineBorder.value = new google.maps.Polyline({
path: route.overview_path,
@ -768,6 +708,7 @@ function calculateWalkingPath(origin: { lat: number, lng: number }, targetStop:
map: map.value,
zIndex: 5
});
regPoly(walkingPolylineBorder.value);
// CAPA 2: Línea Indigo Central (La ruta principal)
walkingPolyline.value = new google.maps.Polyline({
@ -779,6 +720,7 @@ function calculateWalkingPath(origin: { lat: number, lng: number }, targetStop:
map: map.value,
zIndex: 10
});
regPoly(walkingPolyline.value);
// Ajustar zoom para mostrar toda la ruta de caminata
if (map.value) {

View File

@ -39,42 +39,69 @@ function getBusStatus(timeStr: string): 'departing' | 'ontime' | 'upcoming' | 'p
return 'upcoming'
}
// ── Calcular si el horario es "hoy" o "mañana" según tipo de día
// ── Calcular si el horario es "hoy" o "mañana" según tipo de día
function getScheduleDay(schedule: any): 'today' | 'tomorrow' | 'other' {
const now = new Date()
const dow = now.getDay() // 0=Dom, 6=Sab
const isWeekend = dow === 0 || dow === 6
const isTomorrow = (!isWeekend && schedule.schedule_type === 'weekend') ||
(isWeekend && schedule.schedule_type === 'weekday')
const tomorrow = new Date(now)
tomorrow.setDate(now.getDate() + 1)
const getDayType = (date: Date) => {
const dow = date.getDay() // 0=Dom, 6=Sab
return (dow === 0 || dow === 6) ? 'weekend' : 'weekday'
}
const todayType = getDayType(now)
const tomorrowType = getDayType(tomorrow)
// Comparar con el tipo del horario
// Nota: Si el horario es 'todos', cuenta para hoy y mañana (pero priorizamos hoy si pides hoy)
const type = schedule.schedule_type || 'todos'
const isToday = type === todayType || type === 'todos'
const isTomorrow = type === tomorrowType || type === 'todos'
if (isToday) return 'today'
if (isTomorrow) return 'tomorrow'
if (schedule.schedule_type === 'holiday') return 'other'
return 'today'
if (type === 'holiday') return 'other'
return 'other'
}
function getDayLabel(schedule: any): string {
const d = getScheduleDay(schedule)
if (d === 'today') return 'Hoy'
if (d === 'tomorrow') return 'Mañana'
return 'Próximo'
const type = schedule.schedule_type || 'todos'
const now = new Date()
const todayType = (now.getDay() === 0 || now.getDay() === 6) ? 'weekend' : 'weekday'
if (type === 'todos') return 'Diario'
if (type === todayType) return 'Hoy'
return 'Mañana'
}
// ── Filtrado de horarios
const filteredSchedules = computed(() => {
const now = new Date()
const hhmmAhora = now.getHours() * 100 + now.getMinutes()
return scheduleStore.schedules.filter(s => {
const d = getScheduleDay(s)
const status = getBusStatus(s.departure_time)
const [hStr, mStr] = (s.departure_time || '00:00').split(':')
const h = parseInt(hStr || '0')
const m = parseInt(mStr || '0')
const hhmmSched = h * 100 + m
const isPassed = hhmmSched < hhmmAhora - 2 // margen de 2 min
// Filtro Hoy: Solo buses de hoy que NO han pasado
// Filtro Hoy: Es hoy Y no ha pasado (o es de los que dice salir en este rango)
if (dayFilter.value === 'today') {
return d === 'today' && status !== 'passed'
return d === 'today' && !isPassed
}
// Filtro Mañana: Solo buses de mañana
// Filtro Mañana: Es mañana
if (dayFilter.value === 'tomorrow') {
return d === 'tomorrow'
}
// Filtro Todos: Mostrar todo
// Filtro Todos: Mostrar todo sin importar si pasó o es otro día
return true
})
})