传单中的可点击覆盖图层

时间:2016-12-12 16:33:32

标签: r shiny leaflet

我在R中使用传单+闪亮。我在区域地图中显示邻域以及区域的边界(即fillColor = "transparent")。每个区域包含几个邻域,因此层重叠(邻域在后台)。我努力使邻居可以点击(例如调用弹出窗口)。你能告诉我怎么做吗?

我使用的代码如下所示:

leaflet()  %>%
  addPolygons (data = neighborhood.shp, #displaying variables
              stroke = TRUE,
              fillColor = ~fillVar,
              color = "#000000",
              popup = "click"
              weight=1) %>% 
  addPolygons (data = region.shp, #showing borders
              color = "#FFFFFF",
              weight=5,                                                     
              fillOpacity = 0,
              fillColor = "transparent")

谢谢!

1 个答案:

答案 0 :(得分:1)

在第二次fill = FALSE调用中设置addPolygons会使基础多边形图层可查询/可点击:

leaflet()  %>%
  addPolygons (data = neighborhood.shp, #displaying variables
              stroke = TRUE,
              fillColor = ~fillVar,
              color = "#000000",
              popup = "click"
              weight=1) %>% 
  addPolygons (data = region.shp, #showing borders
              color = "#FFFFFF",
              weight=5,
              fill = FALSE)