You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support interactive legends for match_expr()-based layers in add_legend() #197
add_legend(interactive = TRUE) currently requires classification to be a mapgl_classification object. This prevents interactive legends when a layer is styled with match_expr(), even though match_expr() is a common and valid way to map feature IDs to colors.
I prepared a reproducible example to show what I mean. The code is available here, with an interactive report here.
Thanks for the detailed example! Interactive legends do already work with match_expr(). The key is passing filter_column to tell the legend which column in the source data to filter on.
Your example works when the source has the category field as a vector layer, but not when a static source is used.
Unfortunately, this does not work in my case.
In the example I used a precompiled PMTiles file based on commonly used tiles in geospatial research in Brazil, sourced from the geobr R package (see the PMTilesBR project). Using a standard, precompiled tile source is very useful because it allows you to build lightweight applications without the need to serve your own tiles on the web.
In this case, the hosted file does not have the category field as a vector layer. The styling is done by assigning a value (in this case, a hex color) to each hex address, so adding a filter_column does not work: the classification is not part of the source tile.
ok I see what you're saying - right now the implementation requires that you have a pre-defined column to filter on. I'll think that through as it'll take a bit more infrastructure work to hook that up.
Activity
walkerke commentedon Apr 13, 2026
Thanks for the detailed example! Interactive legends do already work with
match_expr(). The key is passing filter_column to tell the legend which column in the source data to filter on.Here's a minimal example:
As of right now, we don't have a classification helper for match expressions, so that argument won't apply in this case.
danielvartan commentedon Apr 13, 2026
Thank you for the example.
Your example works when the source has the category field as a vector layer, but not when a static source is used.
Unfortunately, this does not work in my case.
In the example I used a precompiled PMTiles file based on commonly used tiles in geospatial research in Brazil, sourced from the
geobrR package (see the PMTilesBR project). Using a standard, precompiled tile source is very useful because it allows you to build lightweight applications without the need to serve your own tiles on the web.In this case, the hosted file does not have the category field as a vector layer. The styling is done by assigning a value (in this case, a hex color) to each hex address, so adding a
filter_columndoes not work: the classification is not part of the source tile.walkerke commentedon Apr 14, 2026
ok I see what you're saying - right now the implementation requires that you have a pre-defined column to filter on. I'll think that through as it'll take a bit more infrastructure work to hook that up.