【发布时间】:2016-09-10 02:55:31
【问题描述】:
我正在绘制美国社区调查数据的地图。目前我有一个主层(见下文plotMerge$incomePerCapita)。它运行良好,具有完全充实的弹出窗口、图像和所有内容。当我添加第二层以提供县和区域边界时,区域边界变得不可点击,似乎被新层掩盖了。
如果我交换图层顺序,区域边界将变得不可见。
map1<-leaflet()%>%
addTiles()%>%
addPolygons(data = plotMerge,
fillColor = ~pal(plotMerge$incomePerCapita),
color = "#000000", #this is an outline color
fillOpacity = 0.8,
weight = 0.2,
popup=popup)%>%
addPolygons(data = countyPoly,
fillColor = "transparent",
color = "#000000",
stroke = TRUE,
weight = 1,
smoothFactor = 0.5,
group = "Counties")%>%
addLegend(pal = pal,
values = plotMerge$incomePerCapita,
position = "bottomright",
title = "State-wide Income Percentiles",
labFormat = labelFormat(digits=1))
saveas(map1, "map1.html")
map1
有没有办法在第二层中只显示边界的轮廓,而保持前一层的全部功能不变?
我是否应该以不同的方式编写 addPolygons 脚本以显示边界而不强加功能上晦涩的图层?
更新:
我修复了一个错误并交换了addPolygons 代码以使图层按正确的顺序排列。
map1<-leaflet()%>%
addTiles()%>%
addPolygons(data = countyPoly,
fillColor = "transparent",
color = "#000000",
stroke = TRUE,
weight = 1,
smoothFactor = 0.5,
group = "Counties")%>%
addPolygons(data = plotMerge,
fillColor = ~pal(plotMerge$incomePerCapita),
color = "#000000", #this is an outline color
fillOpacity = 0.8,
weight = 0.2,
popup=popup)%>%
addLegend(pal = pal,
values = plotMerge$incomePerCapita,
position = "bottomright",
title = "State-wide Income Percentiles",
labFormat = labelFormat(digits=1))
感谢收看!
【问题讨论】:
-
没有难以测试的数据,但也许您可以使用显示/隐藏图层来访问两个图层 (rstudio.github.io/leaflet/showhide.html)
标签: r popup leaflet layer polyline