Include better OTP results in walk/bike directions when available. #351
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Finally following through with something I observed back in January: https://mapstodon.space/@ikawe/111744706335291719
OTP seems to provide consistently better biking directions than valhalla, so I want to prefer OTP over Valhalla when possible.
Background
We have two route providing backends: Valhalla and OpenTripPlanner. These are independent projects, and both sit behind our bespoke routing frontend travelmux.
Valhalla is fast, lightweight, and capable of spanning the entire planet, but doesn't provide transit directions (though I see some work has been done to move that forward in the last year).
OpenTripPlanner support transit, but is not capable of covering the entire planet. Instead we have separate regions that support transit — each with its own OTP instance. You can read more about our setup at https://about.maps.earth/posts/2023/03/adding-transit-directions-to-maps.earth/.
Previously, travelmux would simply delegate all transit requests to OTP and everything else would go to Valhalla.
However, OTP provides (in my anecdotal experience, see above) consistently better biking directions than Valhalla.
With this PR, we'll query OTP for bike/walk directions if OTP is available for that region. Then we'll mix that result in with the Valhalla results. Note OTP will only provide one result for biking and walking.
Valhalla provides some nice amenities like narrative route directions ("Go north on Broadway for 1.3 miles"), whereas OTP only provides schematic maneuvers
{ direction: "North", street: "Broadway", distance_meters: 2092}
. There is an OTP frontend that builds some narration, but it's pretty simple (e.g. Unlike Valhalla, it doesn't consider previous steps for things like "Continue on the same street"), and it's in javascript. So part of this work was synthesizing narration. For now I've done a quick and crude job. There's not even any localization apart from km/miles. But I'd be happy to localize it if I get any feedback that anyone outside of en-US is using it. 🙃A nice milestone reached is that, with this integration, www no longer uses the raw valhalla response. For expediency, up until this point I've been cheating — although there was a travelmux response that intended to abstract the differences between OTP and Valhalla, as a pragmatic concession (read: quick hack), I've also been including the original valhalla/OTP responses, allowing me to slowly migrate things into the travelmux response. I think we're done with that now (for valhalla anyway, OTP is still TBD). Even though I'm not using it directly, the valhalla response will remain for a while - it's useful for debugging.