1

请参阅以下 MWE:

library(shiny)
library(leaflet)


ui <- fluidPage(leafletOutput("mymap"))

server <- function(input, output, session) {
  output$mymap <- renderLeaflet({
    leaflet() %>%
      addProviderTiles(
        providers$Stamen.TonerLite,
        group = 'stamen',
        options = providerTileOptions(noWrap = TRUE)
      ) %>%
      addProviderTiles(providers$CartoDB.Positron, group = 'cartodb') %>%
      addLayersControl(baseGroups = c('stamen', 'cartodb'),
                       position = 'bottomleft')

  })
}

shinyApp(ui, server)

LayerControl (addLayersControl) 的标准行为是在用户悬停图标后出现。相反,我想在单击后查看图层选项。标准 addLayersControl 函数不提供此类功能。有人知道解决方法吗?

4

1 回答 1

0

我不知道 R 但在 JS 中你需要将选项添加collapsed到你的L.control.layers 现在,如果你想打开控件,你必须调用这个:

$(".leaflet-control-layers").addClass("leaflet-control-layers-expanded");

如果你想关闭它:

$(".leaflet-control-layers").removeClass("leaflet-control-layers-expanded");
于 2017-12-20T08:54:04.083 回答