From 11934e58256a5f05de22297edc407a30239b5f2c Mon Sep 17 00:00:00 2001 From: vcoppe Date: Tue, 1 Oct 2024 13:17:39 +0200 Subject: [PATCH] option to remove time gaps when merging --- gpx/src/gpx.ts | 17 ++++++++++++++++- .../lib/components/toolbar/tools/Merge.svelte | 18 +++++++++++++++--- website/src/lib/db.ts | 6 +++--- website/src/locales/en.json | 1 + 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/gpx/src/gpx.ts b/gpx/src/gpx.ts index 2a8c871a..a5b5df29 100644 --- a/gpx/src/gpx.ts +++ b/gpx/src/gpx.ts @@ -890,7 +890,7 @@ export class TrackSegment extends GPXTreeLeaf { } // Producers - replaceTrackPoints(start: number, end: number, points: TrackPoint[], speed?: number, startTime?: Date) { + replaceTrackPoints(start: number, end: number, points: TrackPoint[], speed?: number, startTime?: Date, removeGaps?: boolean) { let og = getOriginal(this); // Read as much as possible from the original object because it is faster let trkpt = og.trkpt.slice(); @@ -909,6 +909,21 @@ export class TrackSegment extends GPXTreeLeaf { } else if (last !== undefined && points[0].time < last.time) { // Adapt timestamps of the new points because they are too early points = withShiftedAndCompressedTimestamps(points, speed, 1, last); + } else if (last !== undefined && removeGaps) { + // Remove gaps between the new points and the previous point + if (last.getLatitude() === points[0].getLatitude() && last.getLongitude() === points[0].getLongitude()) { + // Same point, make the new points start at its timestamp and remove the first point + if (points[0].time > last.time) { + points = withShiftedAndCompressedTimestamps(points, speed, 1, last).slice(1); + } + } else { + // Different points, make the new points start one second after the previous point + if (points[0].time.getTime() - last.time.getTime() > 1000) { + let artificialLast = points[0].clone(); + artificialLast.time = new Date(last.time.getTime() + 1000); + points = withShiftedAndCompressedTimestamps(points, speed, 1, artificialLast); + } + } } } if (end < trkpt.length - 1) { diff --git a/website/src/lib/components/toolbar/tools/Merge.svelte b/website/src/lib/components/toolbar/tools/Merge.svelte index 57c2c901..d38c701c 100644 --- a/website/src/lib/components/toolbar/tools/Merge.svelte +++ b/website/src/lib/components/toolbar/tools/Merge.svelte @@ -11,15 +11,18 @@ import { selection } from '$lib/components/file-list/Selection'; import { Button } from '$lib/components/ui/button'; import { Label } from '$lib/components/ui/label/index.js'; + import { Checkbox } from '$lib/components/ui/checkbox'; import * as RadioGroup from '$lib/components/ui/radio-group'; import { _, locale } from 'svelte-i18n'; import { dbUtils, getFile } from '$lib/db'; import { Group } from 'lucide-svelte'; import { getURLForLanguage } from '$lib/utils'; import Shortcut from '$lib/components/Shortcut.svelte'; + import { gpxStatistics } from '$lib/stores'; let canMergeTraces = false; let canMergeContents = false; + let removeGaps = false; $: if ($selection.size > 1) { canMergeTraces = true; @@ -56,22 +59,31 @@
- + {#if mergeType === MergeType.TRACES && $gpxStatistics.global.time.total > 0} +
+ + +
+ {/if}