fixes time and speed in route planning

This commit is contained in:
Christian Beutel
2025-04-21 23:25:06 +02:00
parent 1ec6f66b38
commit 59051babed
4 changed files with 38 additions and 9 deletions

View File

@@ -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());
}
}

View File

@@ -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,
},

View File

@@ -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`
);
}

View File

@@ -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({
show_toast(
{
type: "warning",
icon: "warning",
text: `${file.name}: ${$_("no-gps-data-in-image")}`,
}, 10000);
},
10000,
);
}
}
}