From cd443faf614821355e74ee1cc4dbc57704f6500a Mon Sep 17 00:00:00 2001 From: vcoppe Date: Wed, 19 Nov 2025 22:28:40 +0100 Subject: [PATCH] cancel drag on click --- .../src/lib/components/map/gpx-layer/gpx-layer.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/website/src/lib/components/map/gpx-layer/gpx-layer.ts b/website/src/lib/components/map/gpx-layer/gpx-layer.ts index 417c804c6..c70be90ae 100644 --- a/website/src/lib/components/map/gpx-layer/gpx-layer.ts +++ b/website/src/lib/components/map/gpx-layer/gpx-layer.ts @@ -90,6 +90,7 @@ export class GPXLayer { selected: boolean = false; currentWaypointData: GeoJSON.FeatureCollection | null = null; draggedWaypointIndex: number | null = null; + draggingStartingPosition: mapboxgl.Point = new mapboxgl.Point(0, 0); unsubscribe: Function[] = []; updateBinded: () => void = this.update.bind(this); @@ -544,7 +545,7 @@ export class GPXLayer { } } - waypointLayerOnMouseDown(e: mapboxgl.MapMouseEvent | mapboxgl.MapTouchEvent) { + waypointLayerOnMouseDown(e: mapboxgl.MapMouseEvent) { if (get(currentTool) !== Tool.WAYPOINT || !this.selected) { return; } @@ -556,6 +557,7 @@ export class GPXLayer { e.preventDefault(); this.draggedWaypointIndex = e.features![0].properties!.waypointIndex; + this.draggingStartingPosition = e.point; waypointPopup?.hide(); _map.on('mousemove', this.waypointLayerOnMouseMoveBinded); @@ -574,7 +576,7 @@ export class GPXLayer { return; } - let features = _map.queryRenderedFeatures(e.points[0], { + let features = _map.queryRenderedFeatures(e.point, { layers: [this.fileId + '-waypoints'], }); if (features.length === 0) { @@ -582,6 +584,7 @@ export class GPXLayer { } this.draggedWaypointIndex = features[0].properties!.waypointIndex; + this.draggingStartingPosition = e.point; waypointPopup?.hide(); e.preventDefault(); @@ -591,7 +594,7 @@ export class GPXLayer { } waypointLayerOnMouseMove(e: mapboxgl.MapMouseEvent | mapboxgl.MapTouchEvent) { - if (!this.draggedWaypointIndex) { + if (!this.draggedWaypointIndex || e.point.equals(this.draggingStartingPosition)) { return; } @@ -618,6 +621,10 @@ export class GPXLayer { if (this.draggedWaypointIndex === null) { return; } + if (e.point.equals(this.draggingStartingPosition)) { + this.draggedWaypointIndex = null; + return; + } getElevation([ {