在R的Leaflet中的图层控件中显示层次结构

时间:2019-10-11 13:45:14

标签: r leaflet r-leaflet

我正在使用Leaflet for R在地图上。我已经定义了图层,我想知道如何显示图层的层次结构。

这是我目前的状态:

library(leaflet)

map <- leaflet(options = leafletOptions(minZoom = 10, zoomControl = FALSE)) %>%
htmlwidgets::onRender("function(el, x) {
                    L.control.zoom({ position: 'topright' }).addTo(this)
                    }") %>%
addTiles() %>%
setView(lng = 7.7, lat = 52.05, zoom = 10) %>% 
addLegend(position = "bottomright", title = "Legend", 
        colors = c("green", "red"), 
        labels = c("yes", "no"),
        opacity = 1) %>% 
addLayersControl(position = "bottomright", options = layersControlOptions(collapsed = FALSE),
               baseGroups = c("Group A", "Group A1", "Group A2", "Group B", "Group B1"))
map

enter image description here

我想要的

我想指出A1组和A2组是A组的一部分,最好带有缩进,例如嵌套列表:

  • A组
    • A1组
    • A2组
  • B组
    • B1组

我尝试过的事情

我试图通过在组名中添加前导空格来实现组名的缩进,但是传单忽略了这些空白。

堆栈溢出示例

我在Leaflet: Grouped layers and accordion menu - How to implement?中看到了类似的内容,但是我不确定如何在R版本的传单中实现JavaScript。

会话信息

R version 3.5.0 (2018-04-23)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=Dutch_Netherlands.1252  LC_CTYPE=Dutch_Netherlands.1252   
[3] LC_MONETARY=Dutch_Netherlands.1252 LC_NUMERIC=C                      
[5] LC_TIME=Dutch_Netherlands.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] sp_1.3-1      leaflet_2.0.2

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.1      lattice_0.20-35 digest_0.6.15   later_0.7.3     mime_0.5       
 [6] grid_3.5.0      R6_2.2.2        xtable_1.8-3    jsonlite_1.6    magrittr_1.5   
[11] promises_1.0.1  tools_3.5.0     htmlwidgets_1.3 crosstalk_1.0.0 shiny_1.2.0    
[16] httpuv_1.4.4.1  yaml_2.1.19     compiler_3.5.0  htmltools_0.3.6

0 个答案:

没有答案