我正在制作美国社区调查数据地图。目前我有一个主层(见下面plotMerge$incomePerCapita
)。它运作良好,有一个完全充实的弹出窗口,图像和所有。当我添加第二层时,为了提供县和区域边界,短程边界变得不可点击,看起来被新层掩盖。Leaflet Map - 第二个Polygon使第一层不可点击
如果我交换图层顺序,区域边界变得不可见。
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以显示边界而不强加功能晦涩的图层吗?
UPDATE:
我固定的错误,并交换了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))
感谢您的期待!
没有数据很难测试,但也许你可以使用显示/隐藏层来访问这两个层(https://rstudio.github.io/leaflet/showhide.html) – MLavoie