Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Valhalla: avoid locations/polygons incorrectly formatted in Directions request #31

Open
nospi opened this issue Jun 4, 2023 · 2 comments

Comments

@nospi
Copy link

nospi commented Jun 4, 2023

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.

@nilsnolde
Copy link
Owner

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.

@nospi
Copy link
Author

nospi commented Jun 4, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants