improve routing details

This commit is contained in:
vcoppe
2024-08-11 17:40:47 +02:00
parent 7e39634cdb
commit ad22ad8caa
2 changed files with 10 additions and 6 deletions

View File

@@ -5,7 +5,7 @@ export type SimplifiedTrackPoint = { point: TrackPoint, distance?: number };
const earthRadius = 6371008.8;
export function ramerDouglasPeucker(points: TrackPoint[], epsilon: number = 50, measure: (a: TrackPoint, b: TrackPoint, c: TrackPoint) => number = computeCrossarc): SimplifiedTrackPoint[] {
export function ramerDouglasPeucker(points: TrackPoint[], epsilon: number = 50, measure: (a: TrackPoint, b: TrackPoint, c: TrackPoint) => number = crossarcDistance): SimplifiedTrackPoint[] {
if (points.length == 0) {
return [];
} else if (points.length == 1) {
@@ -45,7 +45,7 @@ function ramerDouglasPeuckerRecursive(points: TrackPoint[], epsilon: number, mea
}
}
function computeCrossarc(point1: TrackPoint, point2: TrackPoint, point3: TrackPoint): number {
export function crossarcDistance(point1: TrackPoint, point2: TrackPoint, point3: TrackPoint): number {
return crossarc(point1.getCoordinates(), point2.getCoordinates(), point3.getCoordinates());
}

View File

@@ -1,4 +1,4 @@
import { distance, type Coordinates, TrackPoint, TrackSegment, Track } from "gpx";
import { distance, type Coordinates, TrackPoint, TrackSegment, Track, crossarcDistance } from "gpx";
import { get, writable, type Readable } from "svelte/store";
import mapboxgl from "mapbox-gl";
import { route } from "./Routing";
@@ -245,6 +245,10 @@ export class RoutingControls {
}
showTemporaryAnchor(e: any) {
if (this.temporaryAnchor.marker.getElement().classList.contains('cursor-grabbing')) { // Do not not change the source point if it is already being dragged
return;
}
if (get(streetViewEnabled)) {
return;
}
@@ -335,12 +339,12 @@ export class RoutingControls {
let minAnchor = this.temporaryAnchor as Anchor;
file?.forEachSegment((segment, trackIndex, segmentIndex) => {
if (get(selection).hasAnyParent(new ListTrackSegmentItem(this.fileId, trackIndex, segmentIndex))) {
for (let point of segment.trkpt) {
let dist = distance(point.getCoordinates(), this.temporaryAnchor.point.getCoordinates());
for (let i = 0; i < segment.trkpt.length - 1; i++) {
let dist = crossarcDistance(segment.trkpt[i], segment.trkpt[i + 1], this.temporaryAnchor.point);
if (dist < minDistance) {
minDistance = dist;
minAnchor = {
point,
point: segment.trkpt[i],
segment,
trackIndex,
segmentIndex,