r-spatial / leafem

leaflet extensions for mapview
https://r-spatial.github.io/leafem/
Other
108 stars 29 forks source link

allow pmtiles styles to map aesthetics to data properties? #76

Open cboettig opened 6 months ago

cboettig commented 6 months ago

the examples in PMTiles here show aesthetics like fill color as literal hex color values in the style, rather than being mapped to data columns:

paintRules(
  layer,
  fillColor = "#0033ff66",
  color = "#0033ffcc",

Some pmtiles rendering tools seem to support an additional syntax to map attributes to columns, e.g. https://maplibre.org/maplibre-style-spec/expressions/#get, as seen in this example https://maplibre.org/maplibre-gl-js/docs/examples/data-driven-lines/. Is it possible to support this?

tim-salabim commented 6 months ago

It certainly should be. I will try to find some time to make it work

cboettig commented 6 months ago

Awesome, thanks!

Just exploring the maplibre docs a bit more and I realize they have a really rich syntax for these operations, not just specifying literal colors in a data-column, but expressing abstract color ramps from the data values (for both discrete and continuous data).

It may be possible to cover some of the most common cases in a familiar R syntax, but might be simpler to expose an 'escape hatch' of letting users provide literal style json blobs. Consider this beautifully rich set of paint rules from another example in their docs:

 'paint': {
                'fill-color': [
                    'let',
                    'density',
                    ['/', ['get', 'population'], ['get', 'sq-km']],
                    [
                        'interpolate',
                        ['linear'],
                        ['zoom'],
                        8,
                        [
                            'interpolate',
                            ['linear'],
                            ['var', 'density'],
                            274,
                            ['to-color', '#edf8e9'],
                            1551,
                            ['to-color', '#006d2c']
                        ],
                        10,
                        [
                            'interpolate',
                            ['linear'],
                            ['var', 'density'],
                            274,
                            ['to-color', '#eff3ff'],
                            1551,
                            ['to-color', '#08519c']
                        ]
                    ]
                ],
                'fill-opacity': 0.7
            }