Skip to content

Commit

Permalink
Fixed route line building
Browse files Browse the repository at this point in the history
  • Loading branch information
Fsss126 committed Jan 12, 2024
1 parent 06efe25 commit 6c98cf9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/directions/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,17 +207,21 @@ export function buildRoutelines(

// indices of coordinate pairs that match existing snappoints (except for the first one)
const snappointsCoordinatesIndices = snappointsCoordinates
.map((snappointLngLat) => {
.map((snappointLngLat, index) => {
// use the currentIndex to start the search from the place where the last snappoint's coordinate was found
const waypointCoordinatesIndex = coordinates.slice(currentIndex).findIndex((lngLat) => {
// there might be an error in 0.00001 degree between snappoint and decoded coordinate when using the
// "polyline" geometries. The comparator neglects that
return coordinatesComparator(requestOptions, lngLat, snappointLngLat as [number, number]);
});

const isLast = index === snappointsCoordinates.length - 1;

// update the current index if something's found
if (waypointCoordinatesIndex !== -1) {
currentIndex += waypointCoordinatesIndex;
} else if (isLast) {
return coordinates.length - 1;
}

return currentIndex;
Expand Down

0 comments on commit 6c98cf9

Please sign in to comment.