mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-09-02 16:52:31 +00:00
routing off with elevation
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import type { Coordinates } from "gpx";
|
||||
import { TrackPoint } from "gpx";
|
||||
import { TrackPoint, distance } from "gpx";
|
||||
import { get, writable } from "svelte/store";
|
||||
import { settings } from "$lib/db";
|
||||
import { _ } from "svelte-i18n";
|
||||
import { map } from "$lib/stores";
|
||||
|
||||
const { routing, routingProfile, privateRoads } = settings;
|
||||
|
||||
@@ -38,14 +39,7 @@ export function route(points: Coordinates[]): Promise<TrackPoint[]> {
|
||||
if (get(routing)) {
|
||||
return getRoute(points, brouterProfiles[get(routingProfile)], get(privateRoads));
|
||||
} else {
|
||||
return new Promise((resolve) => {
|
||||
resolve(points.map(point => new TrackPoint({
|
||||
attributes: {
|
||||
lat: point.lat,
|
||||
lon: point.lon
|
||||
}
|
||||
})));
|
||||
});
|
||||
return getIntermediatePoints(points);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,4 +95,37 @@ function getSurface(message: string): string {
|
||||
return fields[i].substring(8);
|
||||
}
|
||||
return "unknown";
|
||||
};
|
||||
};
|
||||
|
||||
function getIntermediatePoints(points: Coordinates[]): Promise<TrackPoint[]> {
|
||||
let route: TrackPoint[] = [];
|
||||
let step = 0.05;
|
||||
|
||||
for (let i = 0; i < points.length - 1; i++) { // Add intermediate points between each pair of points
|
||||
let dist = distance(points[i], points[i + 1]) / 1000;
|
||||
for (let d = 0; d < dist; d += step) {
|
||||
let lat = points[i].lat + d / dist * (points[i + 1].lat - points[i].lat);
|
||||
let lon = points[i].lon + d / dist * (points[i + 1].lon - points[i].lon);
|
||||
route.push(new TrackPoint({
|
||||
attributes: {
|
||||
lat: lat,
|
||||
lon: lon
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
route.push(new TrackPoint({
|
||||
attributes: {
|
||||
lat: points[points.length - 1].lat,
|
||||
lon: points[points.length - 1].lon
|
||||
}
|
||||
}));
|
||||
|
||||
route.forEach((point) => {
|
||||
point.setSurface("unknown");
|
||||
point.ele = get(map)?.queryTerrainElevation(point.getCoordinates()) ?? undefined;
|
||||
});
|
||||
|
||||
return new Promise((resolve) => resolve(route));
|
||||
}
|
Reference in New Issue
Block a user