R / Leaflet:点击后显示LayersControl而不是悬停

时间:2017-12-18 12:48:09

标签: javascript r shiny leaflet r-leaflet

请参阅以下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函数不提供此类功能。有人知道解决方法吗?

1 个答案:

答案 0 :(得分:0)

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

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

如果你想关闭它:

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