From 79942bb99ec2fa485bff4162ac44f60152db77df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ullrich=20Sch=C3=A4fer?= Date: Thu, 2 Apr 2026 20:40:11 +0100 Subject: [PATCH] Extract start/end from track when GPX has no waypoints The planner's GPX import only used elements, which many GPX files don't have. Now falls back to the first and last track point, giving the planner two endpoints to route between. Co-Authored-By: Claude Opus 4.6 (1M context) --- apps/planner/app/routes/new.tsx | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/apps/planner/app/routes/new.tsx b/apps/planner/app/routes/new.tsx index 8a9f948..aa01380 100644 --- a/apps/planner/app/routes/new.tsx +++ b/apps/planner/app/routes/new.tsx @@ -36,7 +36,31 @@ export async function loader({ request }: Route.LoaderArgs) { try { const gpx = decodeURIComponent(gpxEncoded); const gpxData = await parseGpxAsync(gpx); - initializeSessionWithWaypoints(session.id, gpxData.waypoints); + // Use explicit waypoints if present, otherwise extract from track segments + let waypoints = gpxData.waypoints; + if (waypoints.length === 0 && gpxData.tracks.length > 0) { + const extracted: Array<{ lat: number; lon: number }> = []; + for (const seg of gpxData.tracks) { + if (seg.length === 0) continue; + const first = seg[0]!; + // Deduplicate: skip if same as previous waypoint + const prev = extracted[extracted.length - 1]; + if (!prev || prev.lat !== first.lat || prev.lon !== first.lon) { + extracted.push({ lat: first.lat, lon: first.lon }); + } + } + // Add the end of the last segment + const lastSeg = gpxData.tracks[gpxData.tracks.length - 1]!; + if (lastSeg.length > 0) { + const last = lastSeg[lastSeg.length - 1]!; + const prev = extracted[extracted.length - 1]; + if (!prev || prev.lat !== last.lat || prev.lon !== last.lon) { + extracted.push({ lat: last.lat, lon: last.lon }); + } + } + waypoints = extracted; + } + initializeSessionWithWaypoints(session.id, waypoints); } catch { // Continue with empty session if GPX is invalid }