find closest to dragged
This commit is contained in:
parent
fec275574c
commit
e9278fab57
1 changed files with 5 additions and 3 deletions
|
@ -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;
|
||||||
anchor.zoom = 0;
|
minIndex = i;
|
||||||
anchor.point = response[i];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
anchor.zoom = 0;
|
||||||
|
anchor.point = response[minIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
marker.setLngLat(anchor.point.getCoordinates());
|
marker.setLngLat(anchor.point.getCoordinates());
|
||||||
|
|
Loading…
Reference in a new issue