fixes split gpx function

This commit is contained in:
Christian Beutel
2025-07-20 13:40:18 +02:00
parent 634c34ce65
commit 353e52b0f6
3 changed files with 19 additions and 12 deletions

View File

@@ -178,14 +178,16 @@ export async function splitSegment(index: number, pos: LngLat) {
if (dist < minDistance) { if (dist < minDistance) {
bestSplitIndex = i bestSplitIndex = i
minDistance = dist
} }
} }
const firstSegmentPoints = [...points.slice(0, index)]; const intersectionPoint = new Waypoint({ $: { lat: pos.lat, lon: pos.lng}, ele: points[bestSplitIndex].ele });
const secondSegmentPoints = [...points.slice(index)]; const firstSegmentPoints = [...points.slice(0, bestSplitIndex), intersectionPoint];
const secondSegmentPoints = [intersectionPoint, ...points.slice(bestSplitIndex)];
seg.trkpt = firstSegmentPoints; editRoute(index, firstSegmentPoints)
insertIntoRoute(secondSegmentPoints, index) insertIntoRoute(secondSegmentPoints, index + 1)
} }
export function normalizeRouteTime() { export function normalizeRouteTime() {

View File

@@ -75,7 +75,7 @@ export class LayerManager {
private async updateOverpassLayer(newState: MapState) { private async updateOverpassLayer(newState: MapState) {
const overpassLayer = this.layers.overpass; const overpassLayer = this.layers.overpass;
if (overpassLayer) { if (overpassLayer && this.map.getSource('overpass')) {
const castedOverpassLayer = overpassLayer as OverpassLayer; const castedOverpassLayer = overpassLayer as OverpassLayer;
overpassLayer.filter = await castedOverpassLayer.updateLayerIfNeeded(newState, this.map.getBounds()); overpassLayer.filter = await castedOverpassLayer.updateLayerIfNeeded(newState, this.map.getBounds());
(this.map.getSource('overpass') as M.GeoJSONSource).setData(castedOverpassLayer.data); (this.map.getSource('overpass') as M.GeoJSONSource).setData(castedOverpassLayer.data);

View File

@@ -429,7 +429,7 @@
id: "crop-start-marker", id: "crop-start-marker",
icon: "fa-regular fa-circle", icon: "fa-regular fa-circle",
fontSize: "xs", fontSize: "xs",
style: "z-10 w-6", style: "w-6",
width: 4, width: 4,
backgroundColor: "bg-primary", backgroundColor: "bg-primary",
fontColor: "white", fontColor: "white",
@@ -441,7 +441,7 @@
id: "crop-end-marker", id: "crop-end-marker",
icon: "fa fa-flag-checkered", icon: "fa fa-flag-checkered",
fontSize: "xs", fontSize: "xs",
style: "z-10 w-6", style: "w-6",
width: 4, width: 4,
backgroundColor: "bg-primary", backgroundColor: "bg-primary",
fontColor: "white", fontColor: "white",
@@ -731,12 +731,16 @@
if (!drawingActive) { if (!drawingActive) {
return; return;
} }
const position = marker.getLngLat(); const anchorIndex = valhallaStore.anchors.findIndex(
anchor.lat = position.lat; (a) => a.id == anchor.id,
anchor.lon = position.lng;
await recalculateRoute(
valhallaStore.anchors.findIndex((a) => a.id == anchor.id),
); );
const thisAnchor = valhallaStore.anchors[anchorIndex];
const position = marker.getLngLat();
thisAnchor.lat = position.lat;
thisAnchor.lon = position.lng;
await recalculateRoute(anchorIndex);
draggingMarker = false; draggingMarker = false;
}, },
); );
@@ -943,6 +947,7 @@
splitSegment(data.segment, data.event.lngLat); splitSegment(data.segment, data.event.lngLat);
updateFollowingAnchors(data.segment); updateFollowingAnchors(data.segment);
updateTrailWithRouteData();
} }
function reverseTrail() { function reverseTrail() {