【问题标题】:R Shiny: googleway package - turn off auto zooming and panning during updateR Shiny:googleway 包 - 在更新期间关闭自动缩放和平移
【发布时间】:2018-07-31 12:36:40
【问题描述】:

使用googleway R package with Shiny 并使用 google_map_update 和 update_heatmap 更新地图。

在调用 google_map_update 期间是否可以保持相同的缩放级别和位置 - 它当前会在点更改坐标时自动缩小并平移,这很令人头疼 - 可以关闭吗?

下面的代码来自链接,为滑块打开了自动化。放大地图,然后制作动画,您会看到自动缩放和平移发生。

library(shiny)
library(googleway)

ui <- fluidPage(
  sliderInput(inputId = "sample", label = "sample", min = 1, max = 10,
              step = 1, value = 10, animate = TRUE),
  google_mapOutput(outputId = "map")
)

server <- function(input, output){

  map_key <- ''

  set.seed(20170417)
  df <- tram_route[sample(1:nrow(tram_route), size = 10 * 100, replace = T), ]

  output$map <- renderGoogle_map({
    google_map(key = map_key) %>%
      add_heatmap(data = df, lat = "shape_pt_lat", lon = "shape_pt_lon",
                  option_radius = 0.001)
  })

  observeEvent(input$sample,{

    df <- tram_route[sample(1:nrow(tram_route), size = input$sample * 100, replace = T), ]

    google_map_update(map_id = "map") %>%
      update_heatmap(data = df, lat = "shape_pt_lat", lon = "shape_pt_lon")
  })
}

shinyApp(ui, server)

【问题讨论】:

    标签: r shiny googleway


    【解决方案1】:

    当然!

    使用update_map_view = FALSE


    文档

    ?update_heatmap

    update_map_view - 逻辑指定地图是否应根据形状重新居中


    示例

    google_map_update(map_id = "map") %>%
      update_heatmap(
        data = df
        , lat = "shape_pt_lat"
        , lon = "shape_pt_lon"
        , update_map_view = F
      )
    

    事实上,我现在建议始终使用update_map_view = FALSE,因为它更节省内存(对于浏览器),因为您不会不断更新地图“边界”的数组。但我还没有在任何地方正式记录这一点。

    【讨论】:

      猜你喜欢
      • 2016-10-09
      • 2023-03-27
      • 1970-01-01
      • 2011-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-30
      • 1970-01-01
      相关资源
      最近更新 更多