diff --git a/web/src/lib/stores/valhalla_store.ts b/web/src/lib/stores/valhalla_store.ts index dc79bb85..765ce205 100644 --- a/web/src/lib/stores/valhalla_store.ts +++ b/web/src/lib/stores/valhalla_store.ts @@ -93,11 +93,29 @@ export async function editRoute(index: number, waypoints: Waypoint[]) { segment.trkpt = waypoints } route.features = route.getTotals(); - } export function deleteFromRoute(index: number) { route.trk?.at(0)?.trkseg?.splice(index, 1); route.features = route.getTotals(); +} +export function normalizeRouteTime() { + let currentTime = new Date(); + + for (const seg of route.trk?.at(0)?.trkseg ?? []) { + + if (!seg.trkpt?.length) { + continue + } + const baseTime = seg.trkpt[0].time?.getTime() ?? 0; + for (let i = 0; i < seg.trkpt.length; i++) { + const wp = seg.trkpt![i]; + const offset = (wp.time?.getTime() ?? 0) - baseTime; + const adjustedTime = new Date(currentTime.getTime() + offset); + + wp.time = adjustedTime + } + currentTime = new Date(seg.trkpt[seg.trkpt.length - 1].time!.getTime()); + } } \ No newline at end of file diff --git a/web/src/lib/util/geojson_util.ts b/web/src/lib/util/geojson_util.ts index 7d458f99..60215c9d 100644 --- a/web/src/lib/util/geojson_util.ts +++ b/web/src/lib/util/geojson_util.ts @@ -24,7 +24,7 @@ export function bbox( result[3] = coord[1]; } }); - + return result; } @@ -52,9 +52,9 @@ export function findStartAndEndPoints(geojson: GeoJsonObject): Position[] { export function splitMultiLineStringToLineStrings(geojson: GeoJsonObject): FeatureCollection { const features: Feature[] = []; - (geojson as any).features.forEach((feature: any) => { if (feature.geometry.type === "MultiLineString") { + feature.geometry.coordinates.forEach((lineString: any, lineIndex: number) => { features.push({ type: "Feature", @@ -64,6 +64,10 @@ export function splitMultiLineStringToLineStrings(geojson: GeoJsonObject): Featu }, properties: { ...feature.properties, + coordinateProperties: { + ...feature.properties.coordinateProperties, + times: feature.properties.coordinateProperties.times[lineIndex] + }, featureId: features.length, segmentId: lineIndex, }, diff --git a/web/src/lib/vendor/maplibre-elevation-profile/elevationprofile.ts b/web/src/lib/vendor/maplibre-elevation-profile/elevationprofile.ts index e67c433e..9e0500e0 100644 --- a/web/src/lib/vendor/maplibre-elevation-profile/elevationprofile.ts +++ b/web/src/lib/vendor/maplibre-elevation-profile/elevationprofile.ts @@ -648,7 +648,7 @@ export class ElevationProfile { if (this.settings.tooltipDisplaySpeed && this.speed.length) { tooltipInfo.push(`Speed: ${this.speed[ tooltipItem.dataIndex - ].toFixed(2)} ${distanceUnit}/h` + ]?.toFixed(2)} ${distanceUnit}/h` ); } diff --git a/web/src/routes/trail/edit/[id]/+page.svelte b/web/src/routes/trail/edit/[id]/+page.svelte index a7807eef..db4f3130 100644 --- a/web/src/routes/trail/edit/[id]/+page.svelte +++ b/web/src/routes/trail/edit/[id]/+page.svelte @@ -41,6 +41,7 @@ deleteFromRoute, editRoute, insertIntoRoute, + normalizeRouteTime, route, setRoute, } from "$lib/stores/valhalla_store"; @@ -603,6 +604,7 @@ ); insertIntoRoute(routeWaypoints); updateTrailWithRouteData(); + normalizeRouteTime() } catch (e) { console.error(e); show_toast({ @@ -766,6 +768,7 @@ if ($formData.expand?.gpx_data) { updateTrailWithRouteData(); } + normalizeRouteTime() } catch (e) { console.error(e); show_toast({ @@ -827,6 +830,7 @@ editRoute(data.segment, previousRouteSegment); insertIntoRoute(nextRouteSegment, data.segment + 1); + normalizeRouteTime() updateTrailWithRouteData(); } catch (e) { console.error(e); @@ -940,11 +944,14 @@ wp._photos = [file]; saveWaypoint(wp); } else { - show_toast({ - type: "warning", - icon: "warning", - text: `${file.name}: ${$_("no-gps-data-in-image")}`, - }, 10000); + show_toast( + { + type: "warning", + icon: "warning", + text: `${file.name}: ${$_("no-gps-data-in-image")}`, + }, + 10000, + ); } } }