find closest to dragged

This commit is contained in:
vcoppe
2024-04-25 19:13:53 +02:00
parent fec275574c
commit e9278fab57

View File

@@ -170,14 +170,16 @@ export class RoutingControls {
// and transfer the marker to that point
if (previousAnchor && nextAnchor) {
let minDistance = Number.MAX_VALUE;
let minIndex = 0;
for (let i = 1; i < response.length - 1; i++) {
let dist = distance(response[i].getCoordinates(), anchor.point.getCoordinates());
let dist = distance(response[i].getCoordinates(), coordinates);
if (dist < minDistance) {
minDistance = dist;
anchor.zoom = 0;
anchor.point = response[i];
minIndex = i;
}
}
anchor.zoom = 0;
anchor.point = response[minIndex];
}
marker.setLngLat(anchor.point.getCoordinates());