Fix: map singleton state, schedules view sync, and carousel image error handling

This commit is contained in:
2026-02-28 22:38:59 -05:00
parent 1dd250ca42
commit 91ef07b3ed
3 changed files with 31 additions and 24 deletions

View File

@ -1,10 +1,11 @@
import { ref } from 'vue'
// Registro global de todo lo que está en el mapa
const markers = ref<google.maps.Marker[]>([])
const polylines = ref<google.maps.Polyline[]>([])
const infoWindows = ref<google.maps.InfoWindow[]>([])
const circles = ref<google.maps.Circle[]>([])
// Callback para sincronización externa (ej. useGoogleMaps globalOverlays)
const onLimpiarCallback = ref<(() => void) | null>(null)
// Singleton pattern using composable
export const useMapState = () => {
@ -14,8 +15,6 @@ export const useMapState = () => {
return marker
}
// Registrar una polyline
const registrarPolyline = (polyline: google.maps.Polyline) => {
if (polyline) polylines.value.push(polyline)
@ -34,9 +33,6 @@ export const useMapState = () => {
return infoWindow
}
// Callback para sincronización externa (ej. useGoogleMaps globalOverlays)
const onLimpiarCallback = ref<(() => void) | null>(null)
const registrarCallbackLimpieza = (fn: () => void) => {
onLimpiarCallback.value = fn
}
@ -46,14 +42,15 @@ export const useMapState = () => {
console.log(`SIBU | Iniciando limpieza de ${markers.value.length} markers, ${polylines.value.length} polylines...`)
// Eliminar markers y overlays HTML
markers.value.forEach(m => {
markers.value.forEach((m: any) => {
try {
if (m) {
if (typeof m.setMap === 'function') m.setMap(null);
if (typeof (m as any).remove === 'function') (m as any).remove();
if (typeof (m as any).onRemove === 'function') (m as any).onRemove();
if (google?.maps?.event?.clearInstanceListeners) {
google.maps.event.clearInstanceListeners(m);
if (typeof m.remove === 'function') m.remove();
if (typeof m.onRemove === 'function') m.onRemove();
if (typeof (window as any).google !== 'undefined' && (window as any).google.maps?.event?.clearInstanceListeners) {
(window as any).google.maps.event.clearInstanceListeners(m);
}
}
} catch (e) {
@ -62,10 +59,8 @@ export const useMapState = () => {
})
markers.value = []
// Eliminar polylines
polylines.value.forEach(p => {
polylines.value.forEach((p: any) => {
try {
if (p && typeof p.setMap === 'function') p.setMap(null)
} catch (e) {
@ -75,7 +70,7 @@ export const useMapState = () => {
polylines.value = []
// Cerrar y limpiar infoWindows
infoWindows.value.forEach(iw => {
infoWindows.value.forEach((iw: any) => {
try {
if (iw && typeof iw.close === 'function') iw.close()
} catch (e) {
@ -85,10 +80,10 @@ export const useMapState = () => {
infoWindows.value = []
// Eliminar circles
circles.value.forEach(c => {
circles.value.forEach((c: any) => {
try {
if (c && typeof c.setMap === 'function') c.setMap(null)
if (c && typeof (c as any).remove === 'function') (c as any).remove()
if (c && typeof c.remove === 'function') c.remove()
} catch (e) {
console.warn('Error limpiando circle', e)
}