mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-09-02 16:52:31 +00:00
find closest to dragged
This commit is contained in:
@@ -170,14 +170,16 @@ export class RoutingControls {
|
|||||||
// and transfer the marker to that point
|
// and transfer the marker to that point
|
||||||
if (previousAnchor && nextAnchor) {
|
if (previousAnchor && nextAnchor) {
|
||||||
let minDistance = Number.MAX_VALUE;
|
let minDistance = Number.MAX_VALUE;
|
||||||
|
let minIndex = 0;
|
||||||
for (let i = 1; i < response.length - 1; i++) {
|
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) {
|
if (dist < minDistance) {
|
||||||
minDistance = dist;
|
minDistance = dist;
|
||||||
|
minIndex = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
anchor.zoom = 0;
|
anchor.zoom = 0;
|
||||||
anchor.point = response[i];
|
anchor.point = response[minIndex];
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
marker.setLngLat(anchor.point.getCoordinates());
|
marker.setLngLat(anchor.point.getCoordinates());
|
||||||
|
Reference in New Issue
Block a user