feat: add ?dst and ?src URL params for address-based deep-linking#405
Conversation
Allow third-party sites to link to the OSRM frontend with a pre-set destination (and optionally an origin) by address string, without needing to look up coordinates first. New URL parameters: ?dst=<address> destination address (geocoded on load) ?src=<address> origin address (geocoded on load, optional) These are one-time deep-link parameters. On page load they are resolved via Nominatim and replaced in the URL by loc= coordinate pairs through the existing state machinery. They are ignored when loc= waypoints are already present, so existing sessions are not affected. Example usage: https://map.project-osrm.org/?dst=Berlin https://map.project-osrm.org/?src=Paris&dst=Berlin Changes: - src/links.js: parse q.src/q.dst → originAddress/destinationAddress - src/index.js: geocode address params after LRM init, set waypoints - test/links.test.js: 10 new unit tests for parse/format behaviour Closes #337 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
79e215e to
01f7b66
Compare
There was a problem hiding this comment.
Pull request overview
Adds support for one-time address-based deep-linking into the OSRM frontend via ?dst=<address> and optional ?src=<address>, geocoding them on initial page load (only when no loc= waypoint coordinates are present) and then letting the existing state/URL machinery take over.
Changes:
- Parse
src/dstquery params intooriginAddress/destinationAddressinsrc/links.js. - In
src/index.js, geocodeoriginAddress/destinationAddressafter LRM initialization and calllrmControl.setWaypoints()when no coordinate waypoints exist. - Add Jest unit tests verifying parsing behavior and ensuring
format()does not serializesrc/dst.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
test/links.test.js |
Adds unit tests for parsing src/dst and ensuring they aren’t serialized back into URLs. |
src/links.js |
Extends link parsing to capture originAddress/destinationAddress from query params. |
src/index.js |
Applies parsed address params by geocoding and setting waypoints when loc= isn’t provided. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| parsedValues.originAddress = q.src; | ||
| parsedValues.destinationAddress = q.dst; |
There was a problem hiding this comment.
qs.parse can return arrays/objects for repeated or nested query params (e.g. ?dst=a&dst=b => q.dst is an array). Assigning q.src/q.dst directly means originAddress/destinationAddress may be non-strings, which can later break geocoding (expects a string). Consider normalizing these to a single string (e.g., first element) or explicitly coercing/validating type before storing them in parsedValues.
Summary
Closes #337
Allows third-party sites to deep-link into the OSRM frontend with a pre-set destination (and optionally an origin) by address string — no coordinate lookup required.
New URL parameters
?dst=<address>?src=<address>Examples:
How it works
links.jsparses?src/?dstintooriginAddress/destinationAddressin the options objectindex.jschecks for these values; if present and noloc=coordinate waypoints exist, it geocodes the addresses via Nominatim and callslrmControl.setWaypoints()loc=coordinate params — so the one-time address params are not persisted in the URL after the first load?loc=coordinate params take priority: if waypoints were already set vialoc=, the address params are ignored (existing sessions are unaffected).Changes
src/links.js— parseq.src/q.dstinparseLink(); not included informatLink()src/index.js— geocode address params after LRM init and set waypointstest/links.test.js— 10 new unit tests (68 total, all passing)