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

fix: call to _buildLocations when setting exclude_locations #32

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/valhalla/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ export class Valhalla implements BaseRouter {
])
}
})
params.exclude_locations = avoidLocations
params.exclude_locations = this._buildLocations(avoidLocations);
}

if (directionsOpts.avoidPolygons) {
Expand Down
2 changes: 1 addition & 1 deletion packages/valhalla/parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ interface ValhallaRequestParams {
* minimum each avoid location must include latitude and longitude. The avoid_locations are
* mapped to the closest road or roads and these roads are excluded from the route path computation.
*/
exclude_locations?: [number, number][]
exclude_locations?: [number, number][] | ValhallaLocation[]
/**
* One or multiple exterior rings of polygons in the form of nested JSON arrays, e.g.
* [[[lon1, lat1], [lon2,lat2]],[[lon1,lat1],[lon2,lat2]]]. Roads intersecting these rings
Expand Down
20 changes: 20 additions & 0 deletions packages/valhalla/valhalla.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,26 @@ describe("Valhalla returns responses", () => {
})
})

it("gets a directions response when passing exclude_locations", async () => {
await v
.directions(
[
[-33.3844596, 148.0080975],
[-33.8346839, 148.6911799],
],
"auto",
{
avoidLocations: [[-33.4023733, 148.0193885]],
}
)
.then((d) => {
expect(d.raw).toBeDefined()
expect(d.raw?.trip?.status_message).toBe(
"Found route between points"
)
})
})

it("gets an isochrone response", async () => {
await v
.reachability([42.50823, 1.52601], "pedestrian", [30, 90])
Expand Down