How to get the zoom level from the leaflet map in R/shiny?

前端 未结 1 717
误落风尘
误落风尘 2020-12-15 08:24

I create a map using leaflet package in Shiny which have a selectInput to allow user to select from a site list. The site list also adds into leaflet as markers

相关标签:
1条回答
  • 2020-12-15 08:36

    You can access the zoom level using input$mapid_zoom (see here).

    In your observe, you could do:

     observe({
                    sel_site <- df[df$site == input$site,]
                    isolate({
                            new_zoom <- 4
                            if(!is.null(input$map_zoom)) new_zoom <- input$map_zoom
                            leafletProxy('map') %>%
                                    setView(lng = sel_site$lng, lat = sel_site$lat, zoom = new_zoom)
                    })
            })
    
    0 讨论(0)
提交回复
热议问题