I have a custom scaled circle legend I am using to indicate values associated with circle marker size in leaflet but I would like to be able to show/hide the circles as well as the legend with the group control feature.
The group arg is available in the addLegend function but not with addControl. Would it be possible to add this feature? I know this is achievable using workarounds in shiny (https://stackoverflow.com/questions/50373497/r-leaflet-show-hide-addcontrol-element-with-group-layers) but I am I not using shiny in this case.
Something like this:
leaflet(data) %>%
addCircleMarkers(lng = ~lon, lat = ~lat, radius = ~radius, group = "Circles") %>%
addControl(html, group = "Circles") %>%
addLayersControl(baseGroups = c("Circles"))
Thanks!
I worked out how to do this. Integrated into a new addCustomLegend function so let me know if you want a PR!
But now I've ran into issue #477 in that legend layer control only works with overlayGroups. I think allowing legends to be part of baseGroups would be super useful so +1 for finding a solution to that.
Thanks.
Have you already figured out a solution working for baseGroups?
Most helpful comment
I worked out how to do this. Integrated into a new
addCustomLegendfunction so let me know if you want a PR!But now I've ran into issue #477 in that legend layer control only works with
overlayGroups. I think allowing legends to be part ofbaseGroupswould be super useful so +1 for finding a solution to that.Thanks.