0

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 Answer 1

0

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")
Sign up to request clarification or add additional context in comments.

2 Comments

Your answer allows me to show/hide all markers at once. However, I need to show/hide specific stations. My sample code allows me to do this, but I need it to work even when clustering is active.
I see, I don't have a good solution then, I would guess it causes problems because multiple groups are within the same cluster.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.