Files
better-mreso/app/stores/mreso.ts
T
2026-07-05 16:25:54 +02:00

47 lines
1.3 KiB
TypeScript

import type { Feature, FeatureCollection, MultiLineString, Point } from "geojson";
export const useMresoStore = defineStore("mresoStore", {
state: () => ({
routes: [] as Route[],
lines: {} as FeatureCollection<MultiLineString>,
clusters: {} as FeatureCollection<Point>,
stops: {} as FeatureCollection<Point>,
selectedRoutesId: [] as string[]
}),
actions: {
async fetch() {
// const infos = await $fetch("https://api.nuxt.com/modules/pinia");
// this.name = infos.name;
// this.description = infos.description;
},
},
getters: {
routesById(state) {
return Object.fromEntries(state.routes.map((r)=>[r.id, r]))
},
linesById(state) {
return Object.fromEntries(state.lines.features.map((l)=>[l.properties!.id, l]))
},
shownLines() {
const shownLines: { route: Route; line: Feature<MultiLineString> }[] = [];
for (const routeId of this.selectedRoutesId) {
const route = this.routesById[routeId];
if (!route) {
continue;
}
const line = this.linesById[routeId.replace(":","_")]
if (!line) {
continue;
}
shownLines.push({
route,
line,
});
}
return shownLines;
},
}
}
});