mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-09-02 16:52:31 +00:00
use same routing function for all operations
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { distance, type Coordinates, type GPXFile, type TrackSegment } from "gpx";
|
import { distance, type Coordinates, type GPXFile, type TrackSegment, TrackPoint } from "gpx";
|
||||||
import { get, type Writable } from "svelte/store";
|
import { get, type Writable } from "svelte/store";
|
||||||
import { computeAnchorPoints, type SimplifiedTrackPoint } from "./Simplify";
|
import { computeAnchorPoints, type SimplifiedTrackPoint } from "./Simplify";
|
||||||
import mapboxgl from "mapbox-gl";
|
import mapboxgl from "mapbox-gl";
|
||||||
@@ -193,21 +193,22 @@ export class RoutingControls {
|
|||||||
let anchors = segment._data.anchors;
|
let anchors = segment._data.anchors;
|
||||||
let lastAnchor = anchors[anchors.length - 1];
|
let lastAnchor = anchors[anchors.length - 1];
|
||||||
|
|
||||||
let newPoint = {
|
let newPoint = new TrackPoint({
|
||||||
lon: e.lngLat.lng,
|
attributes: {
|
||||||
lat: e.lngLat.lat
|
lon: e.lngLat.lng,
|
||||||
};
|
lat: e.lngLat.lat
|
||||||
|
}
|
||||||
let response = await route([lastAnchor.point.getCoordinates(), newPoint]);
|
});
|
||||||
|
newPoint._data.index = segment.trkpt.length - 1; // Do as if the point was the last point in the segment
|
||||||
let anchor = {
|
newPoint._data.segment = segment;
|
||||||
point: response[response.length - 1],
|
let newAnchor = {
|
||||||
|
point: newPoint,
|
||||||
zoom: 0
|
zoom: 0
|
||||||
};
|
};
|
||||||
segment._data.anchors.push(anchor);
|
this.createMarker(newAnchor);
|
||||||
this.createMarker(anchor);
|
segment._data.anchors.push(newAnchor);
|
||||||
|
|
||||||
applyToFileStore(this.file, (f) => f.append(response), true);
|
this.routeBetweenAnchors([lastAnchor, newAnchor], [lastAnchor.point.getCoordinates(), newAnchor.point.getCoordinates()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
getNeighbouringAnchors(anchor: SimplifiedTrackPoint): [SimplifiedTrackPoint | null, SimplifiedTrackPoint | null] {
|
getNeighbouringAnchors(anchor: SimplifiedTrackPoint): [SimplifiedTrackPoint | null, SimplifiedTrackPoint | null] {
|
||||||
@@ -256,6 +257,7 @@ export class RoutingControls {
|
|||||||
if (anchors[anchors.length - 1].point._data.index === anchors[anchors.length - 1].point._data.segment.trkpt.length - 1) { // Last anchor is the last point of the segment
|
if (anchors[anchors.length - 1].point._data.index === anchors[anchors.length - 1].point._data.segment.trkpt.length - 1) { // Last anchor is the last point of the segment
|
||||||
anchors[anchors.length - 1].point = response[response.length - 1]; // Update the last anchor in case it was not on a road
|
anchors[anchors.length - 1].point = response[response.length - 1]; // Update the last anchor in case it was not on a road
|
||||||
end++; // Remove the original last point
|
end++; // Remove the original last point
|
||||||
|
console.log('end', end);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 1; i < anchors.length - 1; i++) {
|
for (let i = 1; i < anchors.length - 1; i++) {
|
||||||
|
Reference in New Issue
Block a user