routing progress

This commit is contained in:
vcoppe
2024-04-25 19:02:34 +02:00
parent 7ef19adf53
commit fec275574c
5 changed files with 182 additions and 47 deletions

View File

@@ -1,7 +1,7 @@
import { writable, get, type Writable } from 'svelte/store';
import mapboxgl from 'mapbox-gl';
import { GPXFile, buildGPX, parseGPX } from 'gpx';
import { GPXFile, buildGPX, parseGPX, type AnyGPXTreeElement } from 'gpx';
export const map = writable<mapboxgl.Map | null>(null);
export const files = writable<Writable<GPXFile>[]>([]);
@@ -26,6 +26,16 @@ export function getFileIndex(file: GPXFile): number {
return get(files).findIndex(store => get(store) === file);
}
export function applyToFileElement<T extends AnyGPXTreeElement>(store: Writable<GPXFile>, element: T, callback: (element: T) => void, updateSelected: boolean) {
store.update($file => {
callback(element);
return $file;
});
if (updateSelected) {
selectedFiles.update($selected => $selected);
}
}
export function applyToFile(file: GPXFile, callback: (file: GPXFile) => void, updateSelected: boolean) {
let store = getFileStore(file);
applyToFileStore(store, callback, updateSelected);