请参阅以下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函数不提供此类功能。有人知道解决方法吗?
答案 0 :(得分:0)
我不知道R但是在JS中你需要在你的collapsed
上添加选项L.control.layers
现在,如果你想打开控件,你必须调用它:
$(".leaflet-control-layers").addClass("leaflet-control-layers-expanded");
如果你想关闭它:
$(".leaflet-control-layers").removeClass("leaflet-control-layers-expanded");