0

我有一个闪亮的应用程序,线条很大

我只想在缩放 15 时查看它并仅加载可见部分

library(leaflet)
library(shiny)
library(dplyr)
library(sf)

#random multilinestring
polyline_test <-st_multilinestring()


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

 server <- function(input, output, session){

 output$map <- renderLeaflet({
   leaflet() %>% 
     addTiles() 
})

 ##Only select data visible on the map

new_zoom <- reactive({
    if(!is.null(input$map_zoom)){
     new_zoom <- input$map_zoom
   }
     else {new_zoom <- 2}
 })

polyline_visible <- reactive({
   validate(
      need(new_zoom()>15,"t")
 )
#bbox_zone <- input$map_bounds
#st_polygon()
#polyline_test 
#What is the best way to extract the lines within the bounds ?

})

 #Show layer only at zoom 15

  observe({
      if (new_zoom() > 15) {
         leafletProxy("map") %>%
         addPolylines(data = polyline_visible())
      }else{
         leafletProxy("map") %>% clearShapes()
      }
})
}

shinyApp(ui = ui, server = server)

我想知道在可见地图范围内提取线条的最佳方法?

4

0 回答 0