From 5457057bb23df0838977077591159643340db6c4 Mon Sep 17 00:00:00 2001 From: Flomp Date: Mon, 20 Apr 2026 21:04:32 +0200 Subject: [PATCH] Add metadata to exported waypoints in GPX (#919) * initial commit * consider wpt.sym as icon * fix icons typing --------- Co-authored-by: Christian Beutel <> --- web/src/lib/util/gpx_util.ts | 14 +++++++++++--- web/src/lib/util/icon_util.ts | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/web/src/lib/util/gpx_util.ts b/web/src/lib/util/gpx_util.ts index 9aa87569..8b10ca6c 100644 --- a/web/src/lib/util/gpx_util.ts +++ b/web/src/lib/util/gpx_util.ts @@ -15,6 +15,7 @@ import type { Feature, FeatureCollection, GeoJsonProperties, Position } from 'ge import JSZip from "jszip"; import type { AuthRecord } from "pocketbase"; import { handleFromRecordWithIRI } from "./activitypub_util"; +import { icons } from "./icon_util"; export async function gpx2trail(gpxString: string, fallbackName?: string, correctElevation: boolean = false, f: (url: RequestInfo | URL, config?: RequestInit) => Promise = fetch) { @@ -44,6 +45,9 @@ export async function gpx2trail(gpxString: string, fallbackName?: string, correc wp.id = cryptoRandomString({ length: 15 }); wp.name = wpt.name ?? "" wp.description = wpt.desc; + if(wpt.sym && icons.includes(wpt.sym as typeof icons[number])) { + wp.icon = wpt.sym as typeof icons[number]; + } trail.expand!.waypoints_via_trail?.push(wp); } @@ -112,15 +116,19 @@ export async function trail2gpx(trail: Trail, user?: AuthRecord) { } for (const wp of gpxTrail.expand!.waypoints_via_trail ?? []) { - const gpxWpt = gpx.wpt.find((w) => w.$.lat == wp.lat && w.$.lon == wp.lon) + let gpxWpt = gpx.wpt.find((w) => w.$.lat == wp.lat && w.$.lon == wp.lon) if (!gpxWpt) { - gpx.wpt.push(new GPXWaypoint({ + gpxWpt = new GPXWaypoint({ $: { lat: wp.lat, lon: wp.lon } - })) + }) + gpx.wpt.push(gpxWpt) } + gpxWpt.desc = wp.description + gpxWpt.name = wp.name + gpxWpt.sym = wp.icon } return gpx.toString(); diff --git a/web/src/lib/util/icon_util.ts b/web/src/lib/util/icon_util.ts index 3cc13c0e..ee075177 100644 --- a/web/src/lib/util/icon_util.ts +++ b/web/src/lib/util/icon_util.ts @@ -1530,7 +1530,7 @@ export function getIconForLocation(l: LocationSearchResult): typeof icons[number case "hamlet": return "building" } - } else if(l.category === "historic") { + } else if (l.category === "historic") { return "eye" } switch (l.category) {