R Leaflet-在baseGroups之间切换时,折线位于多边形下方

时间:2018-11-30 21:13:44

标签: r leaflet

首先,很抱歉,我没有包含可行的数据集。我是R的新手,让我的工作成为可能已经花了我很多时间。希望您仍然可以提供帮助。

我用传单制作了一张地图,效果很好。这是一个有拉链边界和地区边界的城市。然后,我想在地图上添加其他图层。这也很好。但是这些区域的边界,折线消失了,并进入了多边形下面。因此,折线必须始终处于最顶端。

在寻找解决方案时,我发现了addMapPane:

leaflet() %>%
    addMapPane("polygon", zIndex = 420) %>%
    addMapPane("polyline", zIndex = 420) %>%
[...]
  addPolylines(data = shapes_district,
               fillColor = "transparent",
               color = "#000000",
               stroke = TRUE,
               weight = 1.5,
               smoothFactor = 1,
               group = "district")
               options = pathOptions(pane = "polyline")%>%

对于多边形,则为“ options = pathOptions(pane =“ polygon”)%>%“。 但这给了我一个错误:

  

dispatch(地图,方法,传单= {:地图参数无效

我的代码没有addMapPane。抱歉,没有可用的数据集,但我希望你们有个好主意。

library("leaflet")

leaflet() %>%
  addProviderTiles("CartoDB.Positron") %>%
  addTiles()%>%

  addPolygons(data=shapes,
              stroke=FALSE,
              smoothFactor = 1,
              fillOpacity = 0.8,
              color= shapes$vec1,
              group = "overall")%>%

  addPolygons(data=shapes,
              stroke=FALSE,
              smoothFactor = 1,
              fillOpacity = 0.8,
              color= shapes$vec2),
              group = "male")%>%

  addPolygons(data=shapes,
              stroke=FALSE,
              smoothFactor = 1,
              fillOpacity = 0.8,
              color= shapes$vec3,
              group = "female")%>%

  addPolylines(data = shapes_county,
               fillColor = "transparent",
               color = "#000000",
               stroke = TRUE,
               weight = 1.5,
               smoothFactor = 1,
               group = "county")%>%

  addLayersControl(
    baseGroups = c("overall", "male", "female"),
    position = "topright",
    options = layersControlOptions(collapsed = FALSE)
  )

0 个答案:

没有答案