From 685c2bb54150e455e6c14f57b3367995ba47fcd8 Mon Sep 17 00:00:00 2001 From: vcoppe Date: Wed, 17 Apr 2024 16:46:51 +0200 Subject: [PATCH] load and display gpx --- gpx/src/gpx.ts | 16 +- gpx/test-data/with_style.gpx | 4 +- website/src/lib/components/Data.svelte | 266 +------------------ website/src/lib/components/GPX.svelte | 97 +++++-- website/src/lib/components/Menu.svelte | 18 +- website/src/lib/components/tools/Load.svelte | 38 +++ website/src/lib/stores.ts | 4 +- 7 files changed, 141 insertions(+), 302 deletions(-) create mode 100644 website/src/lib/components/tools/Load.svelte diff --git a/gpx/src/gpx.ts b/gpx/src/gpx.ts index a5f11199..ba9a9919 100644 --- a/gpx/src/gpx.ts +++ b/gpx/src/gpx.ts @@ -123,7 +123,21 @@ export class Track extends GPXTreeNode { } toGeoJSON(): any { - return this.getChildren().map((child) => child.toGeoJSON()); + return this.getChildren().map((child) => { + let geoJSON = child.toGeoJSON(); + if (this.extensions && this.extensions['gpx_style:line']) { + if (this.extensions['gpx_style:line'].color) { + geoJSON.properties['color'] = this.extensions['gpx_style:line'].color; + } + if (this.extensions['gpx_style:line'].opacity) { + geoJSON.properties['opacity'] = this.extensions['gpx_style:line'].opacity; + } + if (this.extensions['gpx_style:line'].weight) { + geoJSON.properties['weight'] = this.extensions['gpx_style:line'].weight; + } + } + return geoJSON; + }); } }; diff --git a/gpx/test-data/with_style.gpx b/gpx/test-data/with_style.gpx index f34ebfdb..6422b44f 100644 --- a/gpx/test-data/with_style.gpx +++ b/gpx/test-data/with_style.gpx @@ -16,9 +16,9 @@ Cycling - 2d3ee9 + #2d3ee9 0.5 - 5 + 6 diff --git a/website/src/lib/components/Data.svelte b/website/src/lib/components/Data.svelte index d0a8e327..469bb33b 100644 --- a/website/src/lib/components/Data.svelte +++ b/website/src/lib/components/Data.svelte @@ -1,271 +1,9 @@ -{#each files as file} +{#each $files as file} {/each} diff --git a/website/src/lib/components/GPX.svelte b/website/src/lib/components/GPX.svelte index 32cf32d4..e3f9cb64 100644 --- a/website/src/lib/components/GPX.svelte +++ b/website/src/lib/components/GPX.svelte @@ -1,32 +1,91 @@ + + + + { + if (input) { + input.click(); + } + }} +> + Load from desktop... ⌘O + + + diff --git a/website/src/lib/stores.ts b/website/src/lib/stores.ts index 9b168917..6ac32010 100644 --- a/website/src/lib/stores.ts +++ b/website/src/lib/stores.ts @@ -1,5 +1,7 @@ import { writable } from 'svelte/store'; import mapboxgl from 'mapbox-gl'; +import { GPXFile } from 'gpx'; -export const map = writable(null); \ No newline at end of file +export const map = writable(null); +export const files = writable([]); \ No newline at end of file