Leaflet: add group arg to addControl function

Created on 13 Oct 2019  路  2Comments  路  Source: rstudio/leaflet

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!

Most helpful comment

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.

All 2 comments

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?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

behrman picture behrman  路  4Comments

hadley picture hadley  路  5Comments

loerasg picture loerasg  路  6Comments

simon-tarr picture simon-tarr  路  4Comments

sl4269 picture sl4269  路  4Comments