shorter URL with flex polyline and compressed names/custom_model#453
Open
karussell wants to merge 5 commits into
Open
shorter URL with flex polyline and compressed names/custom_model#453karussell wants to merge 5 commits into
karussell wants to merge 5 commits into
Conversation
…er layer parameter New URL params: `fpolyline=` for routes with 4+ waypoints, `cnames=` for waypoint names, `cmodel=` for the custom model, and `l=<shortCode>` for the map layer. Legacy `point=`, `custom_model=`, `layer=`, and `vehicle=` URLs still parse. flexPolyline.ts vendored from heremaps/flexible-polyline (MIT); see NOTICE.md. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR reduces GraphHopper Maps share URL length by introducing compact encoding for waypoints, point names, and custom models. It adds a new fpolyline parameter (HERE flexible polyline) for waypoint coordinates (used from 4 points onward), compresses waypoint names via cnames, compresses custom models via cmodel, and switches map layer URLs to a short l=<code> format while keeping legacy parsing support.
Changes:
- Add flexible polyline encoding/decoding utilities and use them in
NavBarto emit/parsefpolyline. - Add CompressionStream-based deflate/base64url helpers and use them to emit/parse
cnamesandcmodel. - Introduce
StyleOption.shortNameand emitl=<shortName>while still accepting legacylayer=<fullName>.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/NavBar.ts |
Emits/reads the new compact URL params (fpolyline, cnames, cmodel, l) with legacy fallback. |
src/stores/MapOptionsStore.ts |
Adds shortName for styles and allows selecting by either full name or short code. |
src/util/flexPolyline.ts |
Vendored flexible polyline implementation + Coordinate wrappers for encoding/decoding waypoints. |
src/util/urlCompress.ts |
CompressionStream-based deflate-raw + base64url helpers for URL-safe compression. |
test/NavBar.test.ts |
Expands URL sync/parse tests to cover new params and legacy compatibility. |
test/flexPolyline.test.ts |
Validates encoding/decoding against canonical upstream vectors + URL-safe output. |
test/urlCompress.test.ts |
Validates compression feature detection and roundtrips (incl. non-ASCII). |
NOTICE.md |
Adds attribution note for the vendored flexible polyline code. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
46
to
52
| async startSyncingUrlWithAppState() { | ||
| // our first history entry shall be the one that we end up with when the app loads for the first time | ||
| window.history.replaceState(null, '', this.createUrlFromState()) | ||
| const url = await this.createUrlFromState() | ||
| window.history.replaceState(null, '', url) | ||
| this.queryStore.register(() => this.updateUrlFromState()) | ||
| this.mapStore.register(() => this.updateUrlFromState()) | ||
| } |
Comment on lines
258
to
+273
|
|
||
| const parsedLayer = NavBar.parseLayer(url) | ||
| if (parsedLayer) Dispatcher.dispatch(new SelectMapLayer(parsedLayer)) | ||
|
|
||
| const customModelParam = url.searchParams.get('custom_model') | ||
| if (customModelParam != null) Dispatcher.dispatch(new SetCustomModel(customModelParam, false)) | ||
| else Dispatcher.dispatch(new DisableCustomModel()) | ||
| const customModelStr = await NavBar.parseCustomModel(url) | ||
| if (customModelStr) { | ||
| // Pretty-print so the editor shows readable JSON (URL form is minified). | ||
| // Mirrors QueryStore.getInitialState behaviour for the initial-load case. | ||
| let prettyStr = customModelStr | ||
| try { | ||
| prettyStr = customModel2prettyString(JSON.parse(customModelStr)) | ||
| } catch {} | ||
| Dispatcher.dispatch(new SetCustomModel(prettyStr, true)) | ||
| } else { | ||
| Dispatcher.dispatch(new DisableCustomModel()) | ||
| } |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Try here.
Especially for many way points or with a
custom_modelthe URL length can get very long. This change uses the flex polyline algorithm from HERE to reduce length forpoint=(starting with 4 points) and creates a new parameterfpolyline. It also compresses the text of the points and the custom model parameter.E.g. with 7 points the following URL with 147 characters:
is equivalent to this URL with 283 characters:
Or here for a simple custom model that uses an area (210 vs. 444 chars):
For smaller custom models that just exclude the motorway it is still a nice improvement (95 vs. 122):
Note that the polyline encoding is used without additional compression as it does not seem to reduce the length further and also polyline encoding is nearly always more compact than generic compression. Furthermore flex polyline encoding seems to give 10-10% more compact results compared to standard polyline encoding. Also note that the flex polyline website says it is 'lossy' but this applies only for coordinates with higher than specified (1e-6) precision.
Also note that we use
CompressionStreaminstead of an external library like lz-string or pako because it is often more compact for our use case and also keeps the dependency list small.Minor: have also reduced the length a bit via using l=osm instead of layer=OpenStreetMap etc.
TODO: should be possible to disable the compression for e.g. debugging purposes via the settings?