Skip to content

feat: add ?dst and ?src URL params for address-based deep-linking#405

Merged
DennisOSRM merged 2 commits into
gh-pagesfrom
feature/url-address-params
Apr 10, 2026
Merged

feat: add ?dst and ?src URL params for address-based deep-linking#405
DennisOSRM merged 2 commits into
gh-pagesfrom
feature/url-address-params

Conversation

@DennisOSRM
Copy link
Copy Markdown
Contributor

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

Param Description
?dst=<address> Destination address, geocoded on page load
?src=<address> Origin address, geocoded on page load (optional)

Examples:

https://map.project-osrm.org/?dst=Berlin
https://map.project-osrm.org/?src=Paris&dst=Berlin

How it works

  1. links.js parses ?src/?dst into originAddress/destinationAddress in the options object
  2. On page load, index.js checks for these values; if present and no loc= coordinate waypoints exist, it geocodes the addresses via Nominatim and calls lrmControl.setWaypoints()
  3. The existing state machinery then replaces the URL with 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 via loc=, the address params are ignored (existing sessions are unaffected).

Changes

  • src/links.js — parse q.src/q.dst in parseLink(); not included in formatLink()
  • src/index.js — geocode address params after LRM init and set waypoints
  • test/links.test.js — 10 new unit tests (68 total, all passing)

Copilot AI review requested due to automatic review settings April 10, 2026 19:19
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>
@DennisOSRM DennisOSRM force-pushed the feature/url-address-params branch from 79e215e to 01f7b66 Compare April 10, 2026 19:21
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/dst query params into originAddress/destinationAddress in src/links.js.
  • In src/index.js, geocode originAddress/destinationAddress after LRM initialization and call lrmControl.setWaypoints() when no coordinate waypoints exist.
  • Add Jest unit tests verifying parsing behavior and ensuring format() does not serialize src/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.

Comment thread src/links.js
Comment on lines +83 to +84
parsedValues.originAddress = q.src;
parsedValues.destinationAddress = q.dst;
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@DennisOSRM DennisOSRM enabled auto-merge (squash) April 10, 2026 19:26
@DennisOSRM DennisOSRM disabled auto-merge April 10, 2026 19:26
@DennisOSRM DennisOSRM merged commit f39fd15 into gh-pages Apr 10, 2026
3 checks passed
@DennisOSRM DennisOSRM deleted the feature/url-address-params branch April 10, 2026 19:26
@DennisOSRM DennisOSRM mentioned this pull request Apr 11, 2026
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

Successfully merging this pull request may close these issues.

Provide URL Parameter to set destination address

2 participants