This repository has been archived on 2025-11-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
trafficcue-client/src/lib/saved.svelte.ts
Jannik 8af4a623b3
Some checks failed
TrafficCue CI / check (push) Failing after 39s
TrafficCue CI / build (push) Failing after 38s
style: run eslint and prettier
2025-08-30 13:13:31 +02:00

21 lines
613 B
TypeScript

import { reverseGeocode } from "./services/Search";
export const saved: Record<string, WorldLocation> = $state(
JSON.parse(localStorage.getItem("saved") ?? "{}"),
);
export function saveLocations() {
localStorage.setItem("saved", JSON.stringify(saved));
}
export async function geocode(name: string) {
const loc = saved[name];
if (!loc) return;
const geocode = await reverseGeocode(loc);
if (geocode.length == 0) {
return;
}
const feature = geocode[0];
return `${feature.properties.street}${feature.properties.housenumber ? " " + feature.properties.housenumber : ""}, ${feature.properties.city}`;
}