4

Is there a way with Leaflet in R to have layer controls unchecked by default? I've got an addCircleMarkers layer that I want unchecked when the map loads. Here's the code snippet (I know it's not reproducible, but I'm hoping there's a simple way to do this that doesn't require running all the code).

  mymap%>%addCircleMarkers(data=mydata, weight = 1,color="red",radius = ~sqrt(DataPoint),group="NewLayer")%>%
  addLayersControl(overlayGroups = c("NewLayer"),options = layersControlOptions(collapsed = FALSE))

I found this posting that describes it using leaflet directly in js, but I'm not an expert coder in js and am relying on the R interface: Check/uncheck overlays in groupedlayercontrol.js

2
  • 2
    I've never used R in my life, but docs can be helpful (sometimes). Have a look at rstudio.github.io/leaflet/showhide.html and try mymap %>% hideGroup("NewLayer")
    – TomazicM
    Commented Apr 16, 2020 at 17:06
  • duh. Thanks. If you put it as a response I'll mark as answered. Commented Apr 16, 2020 at 17:48

1 Answer 1

9

Layer in Leaflet control is unchecked when it's hidden (not shown on map). If you look at the official docs of Leaflet for R at http://rstudio.github.io/leaflet/showhide.html , you will notice it's possible to hide a layer with a simple call:

mymap %>% hideGroup("NewLayer")

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.