Is there a way to entirely disable dragging and/or zooming in gvisMap, and remove the zoom control also? I have looked at options under google.com developers docs referenced in the help for gvisMap(options)
but can't see this control.
Broadening the scope of the question to include alternative packages, I note that plotGoogleMaps()
in R package plotGoogleMaps
has an option draggable=FALSE
, but there is no corresponding parameter to disable zoom, and rendering it in shiny is not so simple as renderGvis()
. I had a quick look at RgoogleMaps
package also.
Background: I particularly want a google satellite map for the transition to street view, I set the map bounds from a zoom/drag enabled leaflet map, so enabling zoom/drag on the google satellite view is redundant/confusing. Disabling these capabilities is a detail that would improve the UX.
[edit] This revised example is a bit longer but shows in full the functionality I am referring to. It works fine apart from some niggles such as I don't know why the fudge factors are needed, and I don't know how to turn off the markers in the google map - but these are outside the scope of my question. The specific subject of my question however is: can I disable drag and zoom on the google map, just like I do in leafletOptions(zoomControl = FALSE, dragging = F)
? If I had a supplementary question, it would be something like 'how do I reduce the proliferation of google mapping packages?' - but that is not a valid question for this forum. That said, I'd welcome any broader steer on how to simplify this.
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)