有没有办法完全禁用gvisMap中的拖动和/或缩放,还可以删除缩放控件?我查看了gvisMap(options)
帮助中引用的google.com developers docs下的选项,但无法看到此控件。
扩大问题的范围以包含替代软件包,我注意到R软件包plotGoogleMaps()
中的plotGoogleMaps
有一个选项draggable=FALSE
,但是没有相应的参数来禁用缩放,并且将它渲染成闪亮并不像renderGvis()
那么简单。我也快速查看了RgoogleMaps
包。
背景:我特别想要一个谷歌卫星地图过渡到街景,我从启用缩放/拖动的传单地图设置地图边界,因此在谷歌卫星视图上启用缩放/拖动是多余/混乱的。禁用这些功能是一个可以改善用户体验的细节。
[edit]这个修改过的例子有点长,但完整地显示了我所指的功能。它除了一些小问题之外还可以正常工作,例如我不知道为什么需要软糖因素,而且我不知道如何关闭谷歌地图中的标记 - 但这些不在我的范围内题。我的问题的具体主题是:我可以在谷歌地图上禁用拖放和缩放,就像我在leafletOptions(zoomControl = FALSE, dragging = F)
中一样吗?如果我有一个补充问题,那就是“如何减少谷歌地图套餐的扩散?”#39; - 但这不是本论坛的有效问题。也就是说,我欢迎任何更广泛的指导如何简化这一点。
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)