From d6c0e403f91f9e47ae4b4f90fd727f07a5d5f7a0 Mon Sep 17 00:00:00 2001 From: vcoppe Date: Thu, 18 Jul 2024 10:43:38 +0200 Subject: [PATCH] fix time with routing issue --- gpx/src/gpx.ts | 2 +- .../toolbar/tools/routing/RoutingControls.ts | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/gpx/src/gpx.ts b/gpx/src/gpx.ts index 2d73999c..957420fa 100644 --- a/gpx/src/gpx.ts +++ b/gpx/src/gpx.ts @@ -799,7 +799,7 @@ export class TrackSegment extends GPXTreeLeaf { if (trkpt[end + 1].time === undefined) { trkpt.splice(end + 1, 0, ...withTimestamps(trkpt.splice(end + 1), speed, last, startTime)); } else if (last !== undefined && trkpt[end + 1].time < last.time) { - points = withShiftedAndCompressedTimestamps(points, speed, 1, last); + trkpt.splice(end + 1, 0, ...withShiftedAndCompressedTimestamps(trkpt.splice(end + 1), speed, 1, last)); } } } diff --git a/website/src/lib/components/toolbar/tools/routing/RoutingControls.ts b/website/src/lib/components/toolbar/tools/routing/RoutingControls.ts index 1236fb38..8bc791d7 100644 --- a/website/src/lib/components/toolbar/tools/routing/RoutingControls.ts +++ b/website/src/lib/components/toolbar/tools/routing/RoutingControls.ts @@ -501,18 +501,16 @@ export class RoutingControls { } if (anchors[0].point._data.index === 0) { // First anchor is the first point of the segment - response[0]._data.index = 0; - response[0].time = anchors[0].point.time; anchors[0].point = response[0]; // replace the first anchor + anchors[0].point._data.index = 0; } else { anchors[0].point = anchors[0].point.clone(); // Clone the anchor to assign new properties response.splice(0, 0, anchors[0].point); // Insert it in the response to keep it } if (anchors[anchors.length - 1].point._data.index === segment.trkpt.length - 1) { // Last anchor is the last point of the segment - response[response.length - 1]._data.index = segment.trkpt.length - 1; - response[response.length - 1].time = anchors[anchors.length - 1].point.time; anchors[anchors.length - 1].point = response[response.length - 1]; // replace the last anchor + anchors[anchors.length - 1].point._data.index = segment.trkpt.length - 1; } else { anchors[anchors.length - 1].point = anchors[anchors.length - 1].point.clone(); // Clone the anchor to assign new properties response.push(anchors[anchors.length - 1].point); // Insert it in the response to keep it @@ -556,6 +554,11 @@ export class RoutingControls { let replacingTime = newTime - remainingTime; speed = replacingDistance / replacingTime * 3600; + + if (startTime === undefined) { // Replacing the first point + let endIndex = anchors[anchors.length - 1].point._data.index; + startTime = new Date((segment.trkpt[endIndex].time?.getTime() ?? 0) - (replacingTime + stats.local.time.total[endIndex] - stats.local.time.moving[endIndex]) * 1000); + } } dbUtils.applyToFile(this.fileId, (file) => file.replaceTrackPoints(anchors[0].trackIndex, anchors[0].segmentIndex, anchors[0].point._data.index, anchors[anchors.length - 1].point._data.index, response, speed, startTime));