54 lines
1.6 KiB
TypeScript
54 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>,
|
|
selectedRouteIds: [] as string[],
|
|
selectedTrips: [] as Feature<LineString>[],
|
|
}),
|
|
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]),
|
|
);
|
|
},
|
|
},
|
|
});
|