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 segment.trkpt = waypoints
} }
route.features = route.getTotals(); route.features = route.getTotals();
} }
export function deleteFromRoute(index: number) { export function deleteFromRoute(index: number) {
route.trk?.at(0)?.trkseg?.splice(index, 1); route.trk?.at(0)?.trkseg?.splice(index, 1);
route.features = route.getTotals(); 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

@@ -24,7 +24,7 @@ export function bbox(
result[3] = coord[1]; result[3] = coord[1];
} }
}); });
return result; return result;
} }
@@ -52,9 +52,9 @@ export function findStartAndEndPoints(geojson: GeoJsonObject): Position[] {
export function splitMultiLineStringToLineStrings(geojson: GeoJsonObject): FeatureCollection { export function splitMultiLineStringToLineStrings(geojson: GeoJsonObject): FeatureCollection {
const features: Feature[] = []; const features: Feature[] = [];
(geojson as any).features.forEach((feature: any) => { (geojson as any).features.forEach((feature: any) => {
if (feature.geometry.type === "MultiLineString") { if (feature.geometry.type === "MultiLineString") {
feature.geometry.coordinates.forEach((lineString: any, lineIndex: number) => { feature.geometry.coordinates.forEach((lineString: any, lineIndex: number) => {
features.push({ features.push({
type: "Feature", type: "Feature",
@@ -64,6 +64,10 @@ export function splitMultiLineStringToLineStrings(geojson: GeoJsonObject): Featu
}, },
properties: { properties: {
...feature.properties, ...feature.properties,
coordinateProperties: {
...feature.properties.coordinateProperties,
times: feature.properties.coordinateProperties.times[lineIndex]
},
featureId: features.length, featureId: features.length,
segmentId: lineIndex, segmentId: lineIndex,
}, },

View File

@@ -648,7 +648,7 @@ export class ElevationProfile {
if (this.settings.tooltipDisplaySpeed && this.speed.length) { if (this.settings.tooltipDisplaySpeed && this.speed.length) {
tooltipInfo.push(`Speed: ${this.speed[ tooltipInfo.push(`Speed: ${this.speed[
tooltipItem.dataIndex tooltipItem.dataIndex
].toFixed(2)} ${distanceUnit}/h` ]?.toFixed(2)} ${distanceUnit}/h`
); );
} }

View File

@@ -41,6 +41,7 @@
deleteFromRoute, deleteFromRoute,
editRoute, editRoute,
insertIntoRoute, insertIntoRoute,
normalizeRouteTime,
route, route,
setRoute, setRoute,
} from "$lib/stores/valhalla_store"; } from "$lib/stores/valhalla_store";
@@ -603,6 +604,7 @@
); );
insertIntoRoute(routeWaypoints); insertIntoRoute(routeWaypoints);
updateTrailWithRouteData(); updateTrailWithRouteData();
normalizeRouteTime()
} catch (e) { } catch (e) {
console.error(e); console.error(e);
show_toast({ show_toast({
@@ -766,6 +768,7 @@
if ($formData.expand?.gpx_data) { if ($formData.expand?.gpx_data) {
updateTrailWithRouteData(); updateTrailWithRouteData();
} }
normalizeRouteTime()
} catch (e) { } catch (e) {
console.error(e); console.error(e);
show_toast({ show_toast({
@@ -827,6 +830,7 @@
editRoute(data.segment, previousRouteSegment); editRoute(data.segment, previousRouteSegment);
insertIntoRoute(nextRouteSegment, data.segment + 1); insertIntoRoute(nextRouteSegment, data.segment + 1);
normalizeRouteTime()
updateTrailWithRouteData(); updateTrailWithRouteData();
} catch (e) { } catch (e) {
console.error(e); console.error(e);
@@ -940,11 +944,14 @@
wp._photos = [file]; wp._photos = [file];
saveWaypoint(wp); saveWaypoint(wp);
} else { } else {
show_toast({ show_toast(
type: "warning", {
icon: "warning", type: "warning",
text: `${file.name}: ${$_("no-gps-data-in-image")}`, icon: "warning",
}, 10000); text: `${file.name}: ${$_("no-gps-data-in-image")}`,
},
10000,
);
} }
} }
} }