R Leaflet layer control fails when using clusterOptions

50 Views Asked by At

Layers control in this map work well:

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 (by uncommenting # clusterOptions = markerClusterOptions()) prevents layers control to work adequately.

How can addLayersControl and clusterOptions work together?

1

There are 1 best solutions below

2
On

I think the issue is that you aren't defining stations as a single overlay layer, this changing it to a single group name fixes the issue.

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 = "Stations")