routingjs icon indicating copy to clipboard operation
routingjs copied to clipboard

Valhalla: avoid locations/polygons incorrectly formatted in Directions request

Open nospi opened this issue 2 years ago • 2 comments

The avoidLocations and avoidPolygons DirectionsOptions are not formatted as Valhalla expects them to be.

image

When running with dryRun: true in order to see what's going on:

image

I dug into the built code; the issue is here:

image

The Valhalla API expects the avoid locations parameters to be formatted identically to the directions location parameters (object with lat/lon properties). https://github.com/valhalla/valhalla-docs/blob/master/turn-by-turn/api-reference.md

I am passing an array, so I've edited only the top portion of this segment of code:

image

Or perhaps something more general:

params.exclude_locations = avoidLocations.map(([lat, lon]) => ({ lat, lon }));

That fixed the issue for me (for avoidLocations only; would also need the same in avoidPolygons). Dry run result:

image

And the final success from the valhalla public server:

image

I wanted to write a PR but I'm not sure how this would be handled from the typescript/interfaces perspective; but please let me me know if you'd like me to have a go at it.

Cheers!

EDIT: just saw the _buildLocations function.

nospi avatar Jun 04 '23 03:06 nospi

Oops, yeah that’s the „kids diseases“:) We’d be happy with a PR, as you wish. FWIW, avoid polygons does not take location objects but a plain array of coordinates (essentially a open/closed ring), as that’s not supposed to snap to road segments but describe polygons.

nilsnolde avatar Jun 04 '23 09:06 nilsnolde

I've made the changes on a local branch but I'm afraid I've not submitted a PR before. Do I need to fork the repo in order to push to a branch for comparison and PR creation?

EDIT: all done, submitted a PR from a fork.

nospi avatar Jun 04 '23 11:06 nospi