0

For one of the map use case , need to provide maximum zoom in option for the user in shiny app. Have tried to explore some of the options as per below code. Wanted to understand if this is the maximum limit we can have in shiny app using leaflet or I am missing something , really appreciate some guidance here. One of the reactjs web application , Zoom In is possible even further - Here we are using bing / google map license though.

field <- raster::shapefile("sampleShapleFile.shp") # shapefile (field) imported

library(leaflet)
library(leaflet.extras)

leaflet(data = field ,
        options = leafletOptions(zoomSnap = 0.25, zoomDelta = 0.25)) %>%
  addFullscreenControl(position = "topleft", pseudoFullscreen = FALSE) %>%
  addBingTiles(
    "Aq4GyoG8kzfeKO7Nsav5_BcjVVA_d1ULSTeXeW2zM0aPuANIqhvV5IrFtMjOGX3s",
    imagerySet = c("AerialWithLabels"),
    group = "AerialWithLabels",
    options = tileOptions(minZoom = 0, maxZoom = 18)
  ) %>%
  addPolygons(
    fill = FALSE,
    stroke = TRUE,
    weight = 5,
    opacity = 1,
    color = "#FFFFFF"
  ) %>%
  addLegend("bottomright", color = "#FFFFFF", labels = "Test") %>%
  addMeasure(
    position = "bottomleft",
    primaryLengthUnit = "meters",
    primaryAreaUnit = "sqmeters",
    activeColor = "#10bae0",
    completedColor = "#241ad9"
  ) %>%
  addDrawToolbar(
    targetGroup = 'draw',
    polygonOptions = FALSE,
    circleOptions = FALSE,
    rectangleOptions = FALSE,
    markerOptions = FALSE,
    circleMarkerOptions = FALSE,
    editOptions = editToolbarOptions(selectedPathOptions = selectedPathOptions())
  ) %>%
  addScaleBar(position = "topright",
              options = scaleBarOptions(
                maxWidth = 1,
                metric = TRUE,
                imperial = FALSE
              ))

string
  • 787
  • 10
  • 39
  • I am not sure I fully understand your question, but have you explore setView {leaflet}? I find that using the zoom parameter in setView allows me to control zoom well. – Susan Switzer Nov 16 '21 at 15:28
  • @SusanSwitzer thanks for response .... with setView I can provide a particular zoom level ..... In this case using scaleBar ( + , - ) user controls the zoom level ( Zoom In / Out) ,Is there a way we can zoom In even further – string Nov 17 '21 at 07:01

1 Answers1

0

"maxNativeZoom" with "maxZoom" Option in "addTiles" can be utilized to enhance zoom in level for Google / Bing Map

Useful Reference Links : https://gis.stackexchange.com/questions/78843/zoom-further-in-than-level-19-with-leaflet-javascript-api

https://github.com/digidem/leaflet-bing-layer/issues/8

## app.R ##
library(shiny)
library(shinydashboard)
library(leaflet)
library(leaflet.extras)

ui <- dashboardPage(dashboardHeader(),
                    dashboardSidebar(),
                    dashboardBody(leafletOutput("map")))

server <- function(input, output) {
  field <-
    raster::shapefile("sample.shp") # shapefile (field) imported
  
  
  
  output$map <- renderLeaflet({
    leaflet(data = field) %>%
      addFullscreenControl(position = "topleft", pseudoFullscreen = FALSE) %>%
      # addTiles(
      #   group = "Satellite",
      #   urlTemplate = "http://mt0.google.com/vt/lyrs=s&hl=en&x={x}&y={y}&z={z}&s=Ga",
      #   options = tileOptions(maxZoom = 21 , maxNativeZoom = 18)
      # ) %>%
      addBingTiles("Aq4GyoG8kzfeKO7Nsav5_BcjVVA_d1ULSTeXeW2zM0aPuANIqhvV5IrFtMjOGX3s",
                   imagerySet = c("AerialWithLabels"),group = "AerialWithLabels",
                   maxNativeZoom = 18,maxZoom = 21
                   ) %>%
      addPolygons(
        fill = FALSE,
        stroke = TRUE,
        weight = 5,
        opacity = 1,
        color = "#FFFFFF"
      ) %>%
      addLegend("bottomright", color = "#FFFFFF", labels = "Test") %>%
      addMeasure(
        position = "bottomleft",
        primaryLengthUnit = "meters",
        primaryAreaUnit = "sqmeters",
        activeColor = "#10bae0",
        completedColor = "#241ad9"
      ) %>%
      addDrawToolbar(
        targetGroup = 'draw',
        polygonOptions = FALSE,
        circleOptions = FALSE,
        rectangleOptions = FALSE,
        markerOptions = FALSE,
        circleMarkerOptions = FALSE,
        editOptions = editToolbarOptions(selectedPathOptions = selectedPathOptions())
      ) %>%
      addScaleBar(
        position = "topright",
        options = scaleBarOptions(
          maxWidth = 10,
          metric = TRUE,
          imperial = FALSE
        )
      )
    
  })
  
  
}

shinyApp(ui, server)

string
  • 787
  • 10
  • 39