fix: correct Routes API service usage and fix bus stops missing markers
This commit is contained in:
@ -406,41 +406,44 @@ function clearMapMarkers() {
|
||||
}
|
||||
|
||||
async function updateMapMarkers() {
|
||||
if (!isLoaded.value || !map.value) return;
|
||||
if (!isLoaded.value || !map.value || isUpdatingMarkers.value) return;
|
||||
|
||||
isUpdatingMarkers.value = true;
|
||||
const currentRequestRouteId = routeStore.selectedRouteId;
|
||||
const stops = [...routeStore.selectedRouteStops];
|
||||
|
||||
if (!currentRequestRouteId || stops.length === 0) {
|
||||
clearMapMarkers();
|
||||
return;
|
||||
}
|
||||
|
||||
const selectedRouteObj = routeStore.allRoutes.find(r => r.id === currentRequestRouteId) || { id: currentRequestRouteId, short_name: currentRequestRouteId };
|
||||
|
||||
// Llamar al procesador de flujo principal, lo cual limpia el mapa y centra.
|
||||
await procesarSeleccionDeRuta(selectedRouteObj, stops as BusStop[], map.value);
|
||||
|
||||
// ⛔ ABORTAR SI EL USUARIO LIMPIÓ EL MAPA MIENTRAS DIBUJÁBAMOS
|
||||
if (routeStore.selectedRouteId !== currentRequestRouteId) {
|
||||
console.log('Abortando dibujado de paradas (la ruta fue limpiada o cambiada)');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (!currentRequestRouteId || stops.length === 0) {
|
||||
clearMapMarkers();
|
||||
return;
|
||||
}
|
||||
|
||||
const selectedRouteObj = routeStore.allRoutes.find(r => r.id === currentRequestRouteId) || { id: currentRequestRouteId, short_name: currentRequestRouteId };
|
||||
|
||||
// Llamar al procesador de flujo principal, lo cual limpia el mapa y centra.
|
||||
await procesarSeleccionDeRuta(selectedRouteObj, stops as BusStop[], map.value);
|
||||
|
||||
// ⛔ ABORTAR SI EL USUARIO LIMPIÓ EL MAPA MIENTRAS DIBUJÁBAMOS
|
||||
if (routeStore.selectedRouteId !== currentRequestRouteId) {
|
||||
console.log('Abortando dibujado de paradas (la ruta fue limpiada o cambiada)');
|
||||
return;
|
||||
}
|
||||
|
||||
// Agregar todos los stops como marcadores 'normales' para que se vean en el mapa
|
||||
const { paradaCercana } = useParadaCercana();
|
||||
|
||||
stops.forEach(stop => {
|
||||
// Evitar sobre dibujar si es la cercana (useFlujoPrincipal ya se encargó)
|
||||
if (paradaCercana.value && stop.id === paradaCercana.value.id) return;
|
||||
|
||||
addCleanMarker(
|
||||
{ lat: stop.latitude, lng: stop.longitude },
|
||||
stop.name,
|
||||
'normal',
|
||||
() => handleBusStopClick(stop)
|
||||
);
|
||||
});
|
||||
// Agregar todos los stops como marcadores 'normales' para que se vean en el mapa
|
||||
stops.forEach(stop => {
|
||||
// Evitar sobre dibujar si es la cercana (useFlujoPrincipal ya se encargó)
|
||||
if (paradaCercana.value && stop.id === paradaCercana.value.id) return;
|
||||
|
||||
addCleanMarker(
|
||||
{ lat: stop.latitude, lng: stop.longitude },
|
||||
stop.name,
|
||||
'normal',
|
||||
() => handleBusStopClick(stop)
|
||||
);
|
||||
});
|
||||
} finally {
|
||||
isUpdatingMarkers.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function updateMarkersStyles() {
|
||||
@ -679,8 +682,9 @@ async function calculateWalkingPath(origin: { lat: number, lng: number }, target
|
||||
|
||||
// 2. Trazar línea de puntos verde siguiendo RED VIAL PRINCIPAL
|
||||
try {
|
||||
const { Route } = await google.maps.importLibrary("routes") as any;
|
||||
const response = await Route.computeRoutes({
|
||||
const { RoutesService } = await google.maps.importLibrary("routes") as any;
|
||||
const routeService = new RoutesService();
|
||||
const response = await routeService.computeRoutes({
|
||||
origin: {
|
||||
location: {
|
||||
latLng: { latitude: origin.lat, longitude: origin.lng }
|
||||
|
||||
Reference in New Issue
Block a user