你肯定可以在小冊子R中做層控制。如果你的版本沒有它,那麼你需要更新,可能來自最近的GITHUB版本。
我現在在地圖上有圖層控件,請看照片。這是實現它的代碼。正如你所看到的,每個addPolygons
都有一個group = " A Name"
這是您在圖像上的複選框中標識圖層的位置。
map<-leaflet()%>%
addTiles()%>%
addPolygons(data = plotMerge,
fillColor = ~pal(plotMerge$incomePerCapita),
color = "#000000", #this is an outline color
fillOpacity = 0.8,
group="Tract",
weight = 0.2,
popup=popup)%>%
addPolygons(data = countyPoly,
fillColor = "transparent",
color = "#000000", #this is an outline color
fillOpacity = 0.8,
group="County",
[email protected]$NAME,
weight = 2)%>%
addPolygons(data = townPoly,
fillColor = "transparent",
color = "#000000", #this is an outline color
fillOpacity = 0.8,
group="Town",
weight = .8,
[email protected]$TOWN)%>%
addPolygons(data = rphnPoly,
fillColor = "transparent",
color = "#000000", #this is an outline color
fillOpacity = 0.8,
group="Public Health Region",
weight = .8,
[email protected]$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)
這裏是什麼樣子:
您還可以添加其他控件看看這裏:
Leaflet R Hidden Layers
謝謝您的答覆。但是,這不是我正在尋找的。我正在尋找一種方法將多個圖層放入同一個類別,並且能夠在圖例中顯示該圖例的名稱,如下所示:https://github.com/ismyrnow/Leaflet.groupedlayercontrol – CYC
這是同樣的事情,我從來沒有使用覆蓋層上的單選按鈕,只在基礎層上使用。但您可以創建一個縣,並將其分配到1,2,3,4層線,多邊形或標記,並且它們都將由一個複選框控制。這就像在html中創建一個類或id來控制它與CSS或JavaScript。那個盒子不是傳說,它是選擇工具。通過對圖例代碼編程來查看數據的方式進行配置的圖例中,可能需要在傳單之外進行操作,以使傳入圖例的信息反映您的組。 – sconfluentus
CYC,你可以發佈你寫的代碼來試用Leaflet.groupedlayercontrol插件嗎? – YGS