Grouped layer control in Leaflet R -


there plug-in leaflet js allows group layers in layer control. https://github.com/ismyrnow/leaflet.groupedlayercontrol

this plug-in not seem exist leaflet r found post saying there way use arbitraty leaflet js plug-in in leaflet r. https://gist.github.com/jcheng5/c084a59717f18e947a17955007dc5f92

i tried apply method leaflet.groupedlayercontrol plug-in did not succeed. have idea how can possibly use plug-in or other way group layers in layercontrol generated leaflet r? thank you.

you can layer control in leafletr. if version not have it, need update, recent github version.

i working on map right has layer controls, see photograph. here code makes happen. can see each of addpolygons has group = " name" identify layers in check boxes on image.

map<-leaflet()%>% addtiles()%>% addpolygons(data = plotmerge,             fillcolor = ~pal(plotmerge$incomepercapita),             color = "#000000", #this outline color             fillopacity = 0.8,             group="tract",             weight = 0.2,             popup=popup)%>% addpolygons(data = countypoly,             fillcolor = "transparent",             color = "#000000", #this outline color             fillopacity = 0.8,             group="county",             popup=countypoly@data$name,             weight = 2)%>% addpolygons(data = townpoly,             fillcolor = "transparent",             color = "#000000", #this outline color             fillopacity = 0.8,             group="town",             weight = .8,             popup=townpoly@data$town)%>% addpolygons(data = rphnpoly,             fillcolor = "transparent",             color = "#000000", #this outline color             fillopacity = 0.8,             group="public health region",             weight = .8,             popup=rphnpoly@data$phn)%>% addlegend(pal = pal,           values  = plotmerge$incomepercapita,           position = "bottomright",           title = "state-wide income percentiles",           labformat = labelformat(digits=1))%>% addlayerscontrol(           overlaygroups =c("county", "town", "public health region", "tract"),           options = layerscontroloptions(collapsed=false)           ) savewidget(map, file="map1.html", selfcontained=false) 

here looks like: acs social vulnerability index made on r & leaflet

you can add other controls check out here:

leaflet r hidden layers


Comments