adds route edit menu

This commit is contained in:
Christian Beutel
2025-07-19 19:40:11 +02:00
parent 6a908a3ace
commit ef1571c54e
23 changed files with 791 additions and 386 deletions

View File

@@ -1,6 +1,5 @@
import GPX from "$lib/models/gpx/gpx";
import { Trail } from "$lib/models/trail";
import { Waypoint } from "$lib/models/waypoint";
import { gpx, kml, tcx } from "$lib/vendor/toGeoJSON/toGeoJSON";
import cryptoRandomString from "crypto-random-string";
//@ts-ignore
@@ -16,6 +15,7 @@ import * as xmldom from 'xmldom';
import { bbox, splitMultiLineStringToLineStrings } from "./geojson_util";
import { trails_show } from "$lib/stores/trail_store";
import { handleFromRecordWithIRI } from "./activitypub_util";
import { Waypoint } from "$lib/models/waypoint";
export async function gpx2trail(gpxString: string, fallbackName?: string, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch) {
@@ -25,11 +25,11 @@ export async function gpx2trail(gpxString: string, fallbackName?: string, f: (ur
if (gpx instanceof Error) {
throw gpx;
}
try {
await gpx.correctElevation(f)
} catch(e) {
console.warn("Unable to correct elevation: " + e)
}
// try {
// await gpx.correctElevation(f)
// } catch(e) {
// console.warn("Unable to correct elevation: " + e)
// }
const trail = new Trail("");
@@ -86,7 +86,7 @@ export async function trail2gpx(trail: Trail, user?: AuthRecord) {
gpxTrail = response;
}
}
const gpx = await GPX.parse(gpxTrail.expand!.gpx_data!) as GPX;
if (gpx instanceof Error) {
@@ -359,4 +359,46 @@ export function toGeoJson(gpxData: string) {
geojson = splitMultiLineStringToLineStrings(geojson);
geojson.bbox = bbox(geojson)
return geojson
}
export function cropGPX(start: GPXWaypoint, end: GPXWaypoint, gpx: GPX): GPX {
let foundStart = false;
let done = false;
const croppedTrk = gpx.trk?.map(track => {
const croppedSegments: TrackSegment[] = [];
track.trkseg?.forEach(seg => {
const newPoints: GPXWaypoint[] = [];
for (const pt of seg.trkpt ?? []) {
if (!foundStart) {
if (pt === start) {
foundStart = true;
newPoints.push(pt);
}
continue;
}
if (foundStart && !done) {
newPoints.push(pt);
if (pt === end) {
done = true;
break;
}
}
}
if (newPoints.length > 0) {
croppedSegments.push({ trkpt: newPoints });
}
});
return {
...track,
trkseg: croppedSegments,
};
}).filter(track => track.trkseg.length > 0);
return new GPX({ ...gpx, trk: croppedTrk ?? [], })
}

View File

@@ -13,9 +13,9 @@ import { formatDistance, formatElevation, formatTimeHHMM } from "./format_util";
import { icons } from "./icon_util";
export class FontawesomeMarker extends M.Marker {
constructor(options: { icon: string, fontSize?: string, width?: number, backgroundColor?: string, fontColor?: string, id?: string }, markerOptions?: M.MarkerOptions) {
constructor(options: { icon: string, fontSize?: string, width?: number, backgroundColor?: string, fontColor?: string, style?: string, id?: string }, markerOptions?: M.MarkerOptions) {
const element = document.createElement('div')
element.className = `cursor-pointer flex items-center justify-center w-${options.width ?? 7} aspect-square ${options.backgroundColor ?? "bg-gray-500"} rounded-full text-${options.fontSize ?? "normal"}`
element.className = `cursor-pointer flex items-center justify-center w-${options.width ?? 7} aspect-square ${options.backgroundColor ?? "bg-gray-500"} rounded-full text-${options.fontSize ?? "normal"} ${options.style ?? ""}`
element.id = options.id ?? "";
super({ element: element, ...markerOptions });