Files
better-mreso/app/stores/mreso.ts
T
2026-07-18 12:01:53 +02:00

56 lines
1.6 KiB
TypeScript

import type {
Feature,
FeatureCollection,
LineString,
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>,
selectedLines: [] as Feature<
LineString | MultiLineString,
LineProperties
>[],
}),
actions: {
async fetchData(options: { signal?: AbortSignal } = {}) {
[this.routes, this.lines, this.clusters, this.stops] = await Promise.all([
$fetch<Route[]>("/routes.json", options),
$fetch<FeatureCollection<MultiLineString>>("/lines.json", options),
// $fetch<FeatureCollection<MultiLineString>>(
// "/trajets presque clean.geojson",
// options,
// ),
$fetch<FeatureCollection<Point>>("/clusters.json", options),
$fetch<FeatureCollection<Point>>("/stops.json", options),
]);
},
},
getters: {
routesById(state): { [id: string]: Route } {
return Object.fromEntries(state.routes.map((r) => [r.id, r]));
},
linesById(state): { [id: string]: Feature<MultiLineString> } {
if (!("features" in state.lines)) {
return {};
}
return Object.fromEntries(
state.lines.features.map((l) => [l.properties!.id, l]),
);
},
clustersByCode(state): { [id: string]: Feature<Point> } {
if (!("features" in state.clusters)) {
return {};
}
return Object.fromEntries(
state.clusters.features.map((l) => [l.properties!.code, l]),
);
},
},
});