Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toggle baseGroups legends in the same way as overlayGroups in addLayersControl #895

Open
mkoohafkan opened this issue Nov 30, 2023 · 1 comment

Comments

@mkoohafkan
Copy link

mkoohafkan commented Nov 30, 2023

Currently, legends associated with layers in overlayGroups will toggle on/off via the layer selection, but legends associated with layers in baseGroups are always shown, regardless of which basegroup layer is selected. Not sure if this is a bug.

Reprex:

library(sf)
library(spData)
library(leaflet)

layers = split(us_states, us_states$REGION)
region_pal = colorFactor("Dark2", names(layers))

mp <- leaflet() %>%
  addTiles() 
  
for (region in names(layers)) {
    mp <- mp %>%
      addPolygons(data = layers[[region]], group = region,
        color = region_pal(region)) |>
      addLegend(pal = region_pal, values = region)
}

mp %>%
  addLayersControl(baseGroups = names(layers))

image

Expected behavior: Only the legend of the selected layer is shown.

Actual behavior: all legends for all layers are shown, regardless of selection.

Workaround: use overlayGroups instead of baseGroups in addLayersControl(), although this is suboptimal for cases where only one layer in the group should be selectable.

See also #654

@monteirojaf
Copy link

Any news on that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants