diff --git a/src/assets/paradaAzul.png b/src/assets/paradaAzul.png new file mode 100644 index 0000000..90b3109 Binary files /dev/null and b/src/assets/paradaAzul.png differ diff --git a/src/pages/gtfs_archivo/Admin.svelte b/src/pages/gtfs_archivo/Admin.svelte index 8ae8d54..e62281c 100644 --- a/src/pages/gtfs_archivo/Admin.svelte +++ b/src/pages/gtfs_archivo/Admin.svelte @@ -1,5 +1,6 @@ @@ -106,33 +131,39 @@ {#if ordering === '-id_gtfs'}{/if} --> - onOrderBy('nombre_red')}>Archivo - {#if ordering === 'archivo'}{/if} - {#if ordering === '-archivo'}{/if} + onOrderBy('id_gtfs')}>ID + + + + + onOrderBy('archivo')}>Archivo + onOrderBy('created')}>Creado el - {#if ordering === 'created'}{/if} - {#if ordering === '-created'}{/if} + onOrderBy('status')}>Estado - {#if ordering === 'status'}{/if} - {#if ordering === '-status'}{/if} + onOrderBy('valid_from')}>Inico Vigencia - {#if ordering === 'status'}{/if} - {#if ordering === '-status'}{/if} + onOrderBy('vigente')}>Vigente - {#if ordering === 'vigente'}{/if} - {#if ordering === '-vigente'}{/if} + @@ -140,7 +171,7 @@ {#each lista_gtfs as app, index} {offset + index + 1} - + {app.id_gtfs} {#if !loading} onDownload(app)}>{app.archivo} @@ -148,7 +179,7 @@ {app.archivo} {/if} - {app.created} + {adjustDateTimeByOffset(app.created)} {app.status} {app.valid_from} {app.vigente ? '✅':'🚫'} diff --git a/src/pages/mapas/Paraderos.svelte b/src/pages/mapas/Paraderos.svelte index 5a46886..8c79550 100644 --- a/src/pages/mapas/Paraderos.svelte +++ b/src/pages/mapas/Paraderos.svelte @@ -7,12 +7,15 @@ // services import { getRegiones } from "$/services/regiones" import { getComunas } from "$/services/comunas" - import { getMarcasParaderos } from "$/services/mapas" + import { getMarcasParaderos, getCoordenadasIniciales } from "$/services/mapas" // libs import { storeParaderos } from "$/stores/global" import imagenParada from '$/assets/parada.png' + import imagenParadaAzul from '$/assets/paradaAzul.png' import { onMount } from "svelte"; + import { getDispositivos } from "../../services/dispositivos"; + let myMap = null let elMap = null @@ -22,6 +25,7 @@ let comunas_x_region = [] let L = null let iconParada = null + let iconParadaAzul = null let markers = [] let form = {} let parada = null @@ -30,10 +34,22 @@ $: myMap && crear_marcadores_por_criterio() + + let center = { lat: 0, lng: 0 }; + let dispositivosConTotem + //dispositivosConTotem = totemAsignado(); + onMount(() => { - if(globalThis.L) create_map(); - cargar_paraderos_todos($storeParaderos) - }) + obtieneCorrdenadas(); + // No es necesario llamar a create_map() , la lógica se maneja a través de la reactividad de center + }); + + // Reacciona a los cambios en center + $: if(center && globalThis.L) { + create_map(); + cargar_paraderos_todos($storeParaderos); + + }; function create_map() { if (!elMap || !globalThis.L) return; @@ -46,6 +62,14 @@ popupAnchor: [0, -16] }) } + if (!iconParadaAzul) { + iconParadaAzul = L.icon({ + iconUrl: imagenParadaAzul, + iconSize: [32, 32], + iconAnchor: [16, 32], + popupAnchor: [0, -16] + }) + } if (!myMap) { myMap = L.map(elMap) L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', @@ -55,13 +79,19 @@ // obtener coordenadas actuales // centrar mapa en coordenadas del navegador - navigator.geolocation.getCurrentPosition( + /* navigator.geolocation.getCurrentPosition( ({ coords }) => { const { latitude, longitude } = coords; myMap.setView([latitude, longitude], 16) }, (error) => console.log({ error }) - ) + )*/ + + + + // Configurar la vista del mapa en la ubicación de Concepción con un nivel de zoom, por ejemplo, 16 + myMap.setView(center, 15); + } @@ -74,6 +104,20 @@ } } + + async function obtieneCorrdenadas () { + try { + const data = await getCoordenadasIniciales('?'); + center.lat = parseFloat(data.initialLat); + center.lng = parseFloat(data.initialLng); + console.log("Coordenadas de inicio:", data); + } + catch (error) { + console.error('Error al obtener las coordenadas iniciales :', error); + } + } + + async function cargar_paraderos_todos(data_default) { try { loading = true @@ -118,11 +162,18 @@ // filtro coincide a criterio return true }) - + + + + + // 3. crear marcadores for (let mark of paraderos) { + + const tieneTotem = false // dispositivosConTotem.some(dispositivo => dispositivo.id_paradero === mark.id_paradero); + const { lat, lng } = mark.position - const marker = L.marker([lat, lng], { icon: iconParada }).addTo(myMap) + const marker = L.marker([lat, lng], {icon: tieneTotem ? iconParadaAzul : iconParada }).addTo(myMap) const { title, location } = mark; const html = `${title}
${location}` @@ -149,6 +200,22 @@ form.time_search && clearTimeout(form.time_search) form.time_search = setTimeout(() => crear_marcadores_por_criterio(), 1000) } + + + async function totemAsignado( ) { + try { + + const dispTotem = await getDispositivos({ id_tipo_dispositivo: 1 }); + return dispTotem + } catch (error) { + console.log({ error }); + return []; + } +} + + + + diff --git a/src/pages/mapas/Rutas.svelte b/src/pages/mapas/Rutas.svelte index 9cd3022..5b93d5d 100644 --- a/src/pages/mapas/Rutas.svelte +++ b/src/pages/mapas/Rutas.svelte @@ -9,7 +9,7 @@ import { onMount } from "svelte"; // servicios - import { getRutas } from "$/services/mapas"; + import { getRutas,getCoordenadasIniciales } from "$/services/mapas"; import ModalLetreroLUR from "./ModalLetreroLUR.svelte"; import FiltroRutas from "./FiltroRutas.svelte"; import { getBusesLinea, getParaderosLinea } from "$/services/lineas"; @@ -39,15 +39,22 @@ let timeInterval = null let fileproto = null let loading_proto = false + let center = { lat: 0, lng: 0 }; + onMount(() => { - create_map() - + //create_map() + obtieneCorrdenadas(); return () => { timeInterval && globalThis.clearInterval(timeInterval) } }) + // Reacciona a los cambios en center + $: if(center && globalThis.L) { + create_map(); + }; + function create_map() { if (!elMap || !globalThis.L) return; if (!L) L = globalThis.L; @@ -96,15 +103,27 @@ // obtener coordenadas actuales // centrar mapa en coordenadas del navegador - navigator.geolocation.getCurrentPosition( + /*navigator.geolocation.getCurrentPosition( ({ coords }) => { const { latitude, longitude } = coords; myMap.setView([latitude, longitude], 16); }, (error) => console.log({ error }) - ) - } + )*/ + myMap.setView(center, 14); + } + async function obtieneCorrdenadas () { + try { + const data = await getCoordenadasIniciales('?'); + center.lat = parseFloat(data.initialLat); + center.lng = parseFloat(data.initialLng); + console.log("Coordenadas de inicio:", data); + } + catch (error) { + console.error('Error al obtener las coordenadas iniciales :', error); + } + } async function onMostrarRuta(id_operador, id_linea) { try { loading = true diff --git a/src/services/mapas.js b/src/services/mapas.js index c8812a0..e7d1ed0 100644 --- a/src/services/mapas.js +++ b/src/services/mapas.js @@ -17,4 +17,13 @@ export async function getRutas(params) { }) if (!res.ok) throw await res.text() return res.json() +} + +export async function getCoordenadasIniciales(params) { + const query = !params ? '' : '?' + (new URLSearchParams(params).toString()); + const res = await fetch(`${base}/mapas/coordenadas/${query}`, { + headers: { "Authorization": `Bearer ${getToken()}`, "Content-Type": "application/json" } + }) + if (!res.ok) throw await res.text( ) + return res.json() } \ No newline at end of file