Skip to content

feat: make the debug map link configurable per routing profile - #502

Open
DennisOSRM wants to merge 1 commit into
gh-pagesfrom
feat/per-profile-debug-map-link
Open

feat: make the debug map link configurable per routing profile#502
DennisOSRM wants to merge 1 commit into
gh-pagesfrom
feat/per-profile-debug-map-link

Conversation

@DennisOSRM

Copy link
Copy Markdown
Contributor

Problem

The "Open in Debug Map" tool button always opens the bundled debug map at debug/. That page has a single hardcoded vector tile source (router.project-osrm.org/tile/v1/car/…), so it can only ever match one profile. A deployment configured with car/bike/foot modes has no way to send each mode to its own debug view.

Change

Routing modes accept an optional debugUrl:

[
  {"name":"car","url":"http://localhost:5000","debugUrl":"debug-car/"},
  {"name":"bike","url":"http://localhost:5001","debugUrl":"https://debug.example.com/bike/"}
]
  • src/leaflet_options.jsparseModes() preserves debugUrl from the mode config (alongside path); buildServices() carries it onto the service descriptor.
  • src/tools.jsdebugUrl becomes a control option (default "debug/") with a setDebugUrl() setter. _openDebug() reads it and falls back to the bundled map if the URL is unparseable.
  • src/index.js — new applyDebugUrlForProfile(), called at startup and from both places a profile switch lands: the mode-selector change handler and the back/forward history restore. Without the second call the button goes stale after a browser back.

Relative URLs resolve against the frontend origin (debug-car/ under /osrm-frontend/ becomes /osrm-frontend/debug-car/), absolute URLs are used as-is, and the #zoom/lat/lng hash is appended either way. A mode without debugUrl keeps opening the bundled debug/, so existing deployments are unchanged.

Works the same for non-Docker deployments, where modes are set in the inline window.osrmConfig block in index.html.

Tests

Three cases in test/tools.test.js (absolute URL, relative URL under a subpath, fallback when a mode has no debug URL) and one in test/leaflet_options.test.js (debugUrl surfaces on the service, absent when unset). Full suite: 273 passed. Lint clean.

bundle.js / dist/ are not rebuilt here — npm run build also runs scripts/replace.js, which rewrites sources in place.

Follow-ups, not in this PR

  • The bundled debug/index.html could take its tile source from a query param, which would let one deployed debug map serve every profile.
  • buildServices() reads mode.label / mode.labelKey, but parseModes() drops those fields, so they can never arrive and labels always fall back to name. Pre-existing and unrelated.

🤖 Generated with Claude Code

The "Open in Debug Map" button always opened the bundled debug map at
`debug/`, whose tile source is hardcoded to a car profile. Deployments
with several profiles need one debug map per profile.

Routing modes now accept an optional `debugUrl` in `OSRM_MODES`, carried
through `parseModes()` and `buildServices()` onto the service descriptor.
The tools control exposes it as an option with a `setDebugUrl()` setter,
and the debug link is refreshed on every profile change — both from the
mode selector and from a back/forward history restore.

Relative URLs resolve against the frontend origin, absolute URLs are used
as-is, and the `#zoom/lat/lng` hash is appended in both cases. Modes
without `debugUrl` keep opening the bundled debug map.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 24, 2026 17:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

2 participants