1

有没有办法完全禁用 gvisMap 中的拖动和/或缩放,并删除缩放控件?我查看了帮助中引用的google.com 开发人员文档gvisMap(options)下的选项,但看不到此控件。

扩大问题的范围以包括替代包,我注意到plotGoogleMaps()在 R 包plotGoogleMaps中有一个选项draggable=FALSE,但没有相应的参数来禁用缩放,并且将其渲染为闪亮并不像renderGvis(). 我也快速浏览了一下RgoogleMaps包裹。

背景:我特别想要一个谷歌卫星地图来过渡到街景,我从启用缩放/拖动的传单地图设置地图边界,因此在谷歌卫星视图上启用缩放/拖动是多余的/令人困惑的。禁用这些功能是一个可以改善用户体验的细节。

[编辑] 这个修改后的例子有点长,但完整地展示了我所指的功能。除了一些琐事之外,它工作正常,例如我不知道为什么需要软糖因素,我不知道如何关闭谷歌地图中的标记 - 但这些超出了我的问题范围。然而,我的问题的具体主题是:我可以像在谷歌地图上一样禁用拖动和缩放leafletOptions(zoomControl = FALSE, dragging = F)吗?如果我有一个补充问题,可能是“如何减少谷歌地图包的泛滥?” - 但这不是这个论坛的有效问题。也就是说,我欢迎就如何简化这一点进行任何更广泛的指导。

library(shiny)
library(leaflet)
library(googleVis)
library(RgoogleMaps)

ui <- fluidPage(fluidPage(fluidRow(
  h5('control map - use only this one to drag and zoom'),
  column(6, leafletOutput('controlmap'), offset = 0)
  ,
  h5("google map - drop 'peg man' to get street view"),
  column(6, htmlOutput('gmap'), offset = 0)
)
,
fluidRow(
  h5('choropleth - where the colour-coded data is displayed'),
  column(6, leafletOutput('fitmap'), offset = 0)
)))

server <- function(input, output) {
  latlongR <- reactive({
    if (is.null(input$controlmap_bounds)) {
      data.frame(
        Lat = c(51.52, 51.51),
        Long = c(-.106, -.096),
        Tip = as.character(1:2)
      )
    } else {
      data.frame(
        Lat = c(
          input$controlmap_bounds$north,
          input$controlmap_bounds$south
        ),
        Long = c(
          input$controlmap_bounds$east,
          input$controlmap_bounds$west
        ),
        Tip = as.character(1:2)
      )
    }
  })

  boundR <- reactive({
    fudgezoom <- .7 #fudge - unsure why neeed
    x0 <- latlongR()
    d1 <- abs(diff(x0[, 1]))
    d2 <- abs(diff(x0[, 2]))
    m1 <- mean(x0[, 1])
    m2 <- mean(x0[, 2])
    x1 <- c(m1 + fudgezoom * d1 / 2, m1 - fudgezoom * d1 / 2)
    x2 <- c(m2 + fudgezoom * d2 / 2, m2 - fudgezoom * d2 / 2)
    x3 <- cbind(x0, LatLong = paste0(x1, ':', x2))
    x3
  })

  output$controlmap <- renderLeaflet({
    leaflet(width = 500, height = 400) %>%
      addProviderTiles('OpenStreetMap') %>%
      setView(lng = -0.106831,
              lat = 51.515328,
              zoom = 15)
  })

  output$fitmap <- renderLeaflet({
    x1 <- latlongR()
    fudgefit <- .5 #this fudge depends on layout and maybe other variables
    x2 <-
      RgoogleMaps::MaxZoom(
        latrange = fudgefit * x1$Lat,
        lonrange = fudgefit * x1$Long,
        size = c(500, 400)
      )
    leaflet(
      width = 500,
      height = 400,
      options = leafletOptions(zoomControl = FALSE, dragging = F)
    ) %>%
      addProviderTiles('CartoDB.Positron') %>%
      fitBounds(
        lng1 = x1$Long[1],
        lat1 = x1$Lat[1],
        lng2 = x1$Long[2],
        lat2 = x1$Lat[2]
      ) %>%
      setView(zoom = x2,
              lat = mean(x1$Lat),
              lng = mean(x1$Long))
  })

  output$gmap <- renderGvis({
    x3 <- boundR()
    gvisMap(
      x3,
      "LatLong" ,
      tipvar = "Tip",
      options = list(
        showTip = F,
        icons = NULL,
        useZoomControl = F,
        useMapTypeControl = F
      )
    )

  })

}

shinyApp(ui = ui, server = server)
4

0 回答 0