gpt4 book ai didi

r - Leaflet R中的分组图层控制

转载 作者:行者123 更新时间:2023-12-04 10:16:51 24 4
gpt4 key购买 nike

Leaflet JS 有一个插件,允许在图层控件中对图层进行分组。 https://github.com/ismyrnow/Leaflet.groupedlayercontrol

这个插件似乎不存在于 Leaflet R 但我发现这个帖子说有一种方法可以在 Leaflet R 中使用仲裁 Leaflet JS 插件。
https://gist.github.com/jcheng5/c084a59717f18e947a17955007dc5f92

我尝试将此方法应用于 Leaflet.groupedlayercontrol 插件但没有成功。你知道我怎么可能使用这个插件或任何其他方式在 Leaflet R 生成的 layercontrol 中对我的图层进行分组吗?谢谢你。

最佳答案

你绝对可以在leafletR中进行图层控制。如果您的版本没有它,那么您需要更新,可能是从最新的 GITHUB 版本。

我现在正在制作具有图层控件的 map ,请参阅照片。这是实现它的代码。正如您所看到的每个 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",
popup=countyPoly@data$NAME,
weight = 2)%>%
addPolygons(data = townPoly,
fillColor = "transparent",
color = "#000000", #this is an outline color
fillOpacity = 0.8,
group="Town",
weight = .8,
popup=townPoly@data$TOWN)%>%
addPolygons(data = rphnPoly,
fillColor = "transparent",
color = "#000000", #this is an 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)

这是它的样子:
ACS Social Vulnerability Index Made on R & LEaflet

您还可以添加其他控件,请在此处查看:

Leaflet R Hidden Layers

关于r - Leaflet R中的分组图层控制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38701359/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com