rstudio / leaflet

R Interface to Leaflet Maps
http://rstudio.github.io/leaflet/
Other
805 stars 508 forks source link

Layer control fails when using clusterOptions #889

Open gtalavera opened 11 months ago

gtalavera commented 11 months ago

I am building a map that shows several markers that I want to be able to switch on/off according to a value, and at the same time I want to cluster markers that are close to each other. Layer control works fine without clustering, but once clusterOptions is activated, layer control stops working. No answers yet on my question in SO

In my reprex (using quakes), this works fine:

library(leaflet)
mini_quakes <- head(quakes, 10)
mini_quakes$stations <- as.character(mini_quakes$stations)
leaflet(mini_quakes) %>% 
  addTiles() %>% 
  addMarkers(
    group = ~stations #, 
    # clusterOptions = markerClusterOptions()
    ) %>% 
  addLayersControl(overlayGroups = mini_quakes$stations)

However, activating clusterOptions prevents layers control to work adequately.

I guess it might be solved by using addMarkers for each group, but that might be cumbersome.

Is it possible to have addLayersControl and clusterOptions working together?