Apply track-segment waypoint extraction to sessions API
Same fix as new.tsx — the journal→planner handoff also only used <wpt> elements from GPX. Now both code paths extract waypoints from track segments when no explicit waypoints exist. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
79942bb99e
commit
e0f7c5b806
1 changed files with 23 additions and 1 deletions
|
|
@ -23,7 +23,29 @@ export async function action({ request }: Route.ActionArgs) {
|
|||
if (gpx) {
|
||||
try {
|
||||
const gpxData = await parseGpxAsync(gpx);
|
||||
initialWaypoints = gpxData.waypoints;
|
||||
// Use explicit waypoints if present, otherwise extract from track segments
|
||||
if (gpxData.waypoints.length > 0) {
|
||||
initialWaypoints = gpxData.waypoints;
|
||||
} else if (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]!;
|
||||
const prev = extracted[extracted.length - 1];
|
||||
if (!prev || prev.lat !== first.lat || prev.lon !== first.lon) {
|
||||
extracted.push({ lat: first.lat, lon: first.lon });
|
||||
}
|
||||
}
|
||||
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 });
|
||||
}
|
||||
}
|
||||
initialWaypoints = extracted;
|
||||
}
|
||||
} catch {
|
||||
// Continue with empty session if GPX is invalid
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue