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 }