gpt4 book ai didi

r - Leaflet Map - 第二个多边形使第一层不可点击

转载 作者:行者123 更新时间:2023-12-02 04:33:58 28 4
gpt4 key购买 nike

我正在制作美国社区调查数据 map 。目前我有一个主要层(如下所示 plotMerge$venuePerCapita)。它运作良好,有一个完全充实的弹出窗口、图像等等。当我添加第二层以提供县和地区边界时,区域边界变得不可单击,似乎被新层掩盖了。

如果我交换图层顺序,区域边界就会变得不可见。

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))

感谢您的浏览!

最佳答案

如果您正在使用 sp 处理适当的空间对象,你可以强制你的countyPoly进入SpatialLines(DataFrame) :

countyLines <- as(countyPoly, "SpatialLinesDataFrame")

然后您应该能够单击下面的多边形图层,同时在顶部显示线条。

编辑:作为可重现的示例,您可以尝试:

library(mapview)
library(sp)

pol <- as(gadmCHE, "SpatialPolygons")
ln <- as(gadmCHE, "SpatialLines")

mapview(gadmCHE, color = "blue") + pol # not clickable
mapview(gadmCHE, color = "blue") + ln # clickable

关于r - Leaflet Map - 第二个多边形使第一层不可点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37217985/

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