Design Proposal: Add 'polyline' as a supported source type #696
Replies: 7 comments 14 replies
-
Love the proposal here. ❤️ The size of the library may not be a significant concern if this can be implemented as a plugin. Users have the flexibility to install and use the plugin when needed. Regarding the Polyline spec, assuming MapLibre settles on one specific version to maintain, it is unlikely that there will be extensive changes or even any notable alterations. I personally think, if MapLibre takes this journey, it should pick 1 variant keeping the door open to support others by the MapLibre users. |
Beta Was this translation helpful? Give feedback.
-
Consider reaching out to the developers of Turf.js to get their opinion as well. From what I’ve seen, MapLibre GL JS + Turf.js is a very popular combination, and something similar happens to a lesser extent on mobile platforms. Not every use case for Polyline geometry encoding or decoding involves an interactive map, so maybe putting this functionality in Turf would result in a more versatile overall experience for developers. Coordination between these projects would head off potential conflicts, such as differing default precision values, or other ergonomic issues. |
Beta Was this translation helpful? Give feedback.
-
I’m curious about the choice to define For comparison, there are existing source types for |
Beta Was this translation helpful? Give feedback.
-
Thanks for taking the time to open this design proposal! You have summarized the discussion on slack well and I believe you covered most of what was mentioned there, thanks again. I have also suggested to solve this by simply documenting the solution you have suggested by highlighting the relevant libraries for decoding etc. When I look at the concept of style spec and the fact that this compression is mostly used for routing I believe it should not be part of this library. My perspective is that if you already need to code the routing request, adding the conversion to geojson is not a complicated task. To summarize my main concern: a static polyline source is cumbersome. |
Beta Was this translation helpful? Give feedback.
-
Here are my 2 cents on a few points. Note that I'll try to highlight the native perspective, since all discussion so far has been about JS. TL;DR I'd be in favor of having polyline decoding directly in MapLibre. I'm neutral on whether we need to add it as a first-class style spec thing. I think that a utility function would suffice. PluginsI love the idea. But MapLibre only sorta has a plugin architecture on the JS side. If there was a good plugin story, then I'd say a plugin could add a new layer type. This would make the job of the developer building a user-facing app slightly easier. But they would still have to grab a plugin ;) My opinion is that the Google encoded polyline format is so ubiquitous that it's probably worth keeping in the core, and it should be quite light. This is actually the first time I've heard of the HERE flexible polyline, but if it's not much to add, then that's also fine. Maintenance and sizeBoth specs are stable and have been for a very long time. There will not be any changes to it; only perhaps "superseding" specs (like flexible polyline) off the same principle. The implementation probably shouldn't need to depend on a GeoJSON generator library, so size should be very small. All you need is a list of coordinates to draw the polyline in MapLibre, at least on mobile. Maybe there is some reason I'm missing to convert to GeoJSON specifically, but this would be like... idk only one line of actual code? It's so simple and mechanical; you just need the boilerplate structure, and the geometry is just the list of coordinates (the output of the decode function) mapped into an array, ensuring the correct coordinate order. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the proposal @mbalfour-amzn. To me it looks like the effect you would like to have for your users could be done with a more convenient polyline wrapper outside of MapLibre GL JS: We could do... const testPolyline = "ccq~FpxzuO_GewBjMa{@br@}ZvcAgCtlAvo@~E`{@u{AppAarBzK";
myPolylineWrapper.addSourceToMap(map, "route", testPolyline, 5); ...where function addSourceToMap(map, source, data, encoding) {
var polylineJson = polyline.toGeoJSON(data, encoding);
map.addSource(source, {
type: "geojson",
data: {
type: "Feature",
properties: {},
geometry: polylineJson,
},
});
} What do you think? |
Beta Was this translation helpful? Give feedback.
-
As one of the GraphHopper maintainers I would recommend to not put this into maplibre and just stick to geojson. E.g. Google uses precision=5 but often this is not sufficient and some services like ours support also a higher precision (as mentioned above valhalla does so too). Also the lat,lon could be expanded by another third dimension (elevation) like we do if explicitly requested, so I would keep this and the associated hassle out of the core library :) |
Beta Was this translation helpful? Give feedback.
-
Summary
This proposal is to add 'polyline' as a first-class supported source type with MapLibre (for both GL JS and Native) so that compressed polyline data can be passed in directly as a source.
Introduction
Various map service providers - Google, Mapbox, HERE, Stadia Maps, OSRM, Valhalla, etc - have routing APIs that return geometry in a compressed polyline format. There are two general patterns that map renderers use for handling these responses:
Since MapLibre isn't tied to a specific service API, developers using MapLibre currently need to follow pattern 2. While this isn't terribly burdensome, it's an extremely common pattern that developers need to follow, and it requires them to spend some time learning about compressed polylines, finding the right library dependency for decoding, and adding it to their project.
Proposal
This proposal is to add 'polyline' as a first-class supported source type with MapLibre (for both GL JS and Native) so that compressed polyline data can be passed in directly as a source. All of the examples above use one of the following compressed polyline variations:
Both variants come from the same underlying algorithm - Encoded Polyline Algorithm Format.
Without polyline support, users' code currently looks like this:
With 'polyline' as a source, the usage simplifies to the following:
With this proposal, we would support all 2 (or 3?) known variations via the
encoding
parameter. The choice of anencoding
parameter is aligned with the current "raster-dem" source type that uses an encoding field to distinguish between Mapbox and Terrarium encodings. This also opens the door to adding more encodings over time if necessary.Benefits
The primary benefit is to lower the developer friction of using API calls that return compressed polylines with MapLibre. Specifically:
Concerns
This proposal has been informally brought up to the community to get initial feedback. These are the concerns that have been raised so far:
I am raising this as a formal proposal to see if the community feels the Benefits outweigh the Concerns.
Opinions
My opinions about the concerns:
image
(a single image) could be considered a lower-level subset ofraster
(a TileJSON set of images). If supporting this level of data is beneficial to developers, I would encourage us to consider it.Beta Was this translation helpful? Give feedback.
All reactions