Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R Leaflet: Zoom Control Level

Tags:

r

zooming

leaflet

I am trying to set zoom out maximum in my R Leaflet map. I follow an example of a previous question/answer in Prevent zooming out in leaflet R-Map? , but it doesn't work. The line that should be able to do this is:

options = providerTileOptions(minzoom = 1, maxzoom = 10))

Can you guys can help me to figure out why?

Here is code:

 deck_lf_par_map <- leaflet(lpoints) %>%
               addPolygons(data = dio, noClip=T,
                           weight = 4,
                           dashArray="5, 1",
                           color = "black",
                           fillOpacity = .01,
                           smoothFactor = 0) %>%
               setView(lng = mean(lpoints$long), lat = mean(lpoints$lat), zoom = 09) %>%
               addProviderTiles("Stamen.TonerLite",
                                group = "Toner", 
                                options = providerTileOptions(minzoom = 1, maxzoom = 10)) %>%
               addTiles(group = "OSM") %>%
               addProviderTiles("Esri.WorldTopoMap",    
                                group = "Topo") %>%
               addProviderTiles("OpenStreetMap.Mapnik", group = "Mapnik") %>%
               addProviderTiles("CartoDB.Positron",     group = "CartoDB") %>%
              setMaxBounds((dioc@bbox[1,1] - .3), 
                           (dioc@bbox[2,1] - .3), 
                           (dioc@bbox[1,2] + .3), 
                           (dioc@bbox[2,2] + .3)) %>%
              addMarkers(lpoints$long, 
                         lpoints$lat, 
                         popup=ppopup, 
                         icon = tec_icon, 
                         group="Parishes", 
                         clusterOptions = markerClusterOptions()) %>%
             addLayersControl(baseGroups = c("Toner", "OSM", "Topo", "Mapnik", "CartoDB"),
                       options = layersControlOptions(collapsed = TRUE))
like image 822
Alex Soto Avatar asked Jun 23 '16 15:06

Alex Soto


People also ask

What does leaflet do in R?

leaflet is an open-source JavaScript library that is used to create dynamic online maps. The identically named R package makes it possible to create these kinds of maps in R as well.

What is zoom level?

A zoom level or scale is a number that defines how large or small the contents of a map appear in a map view . Scale is a ratio between measurements on a map view and measurements in the real-world.

How to change zoom level in leaflet?

A leaflet map has several ways to control the zoom level shown, but the most obvious one is setZoom() . For example, map. setZoom(0); will set the zoom level of map to 0 .


1 Answers

A couple of points:

  1. It's minZoom and maxZoom (notice the capital Z)
  2. You need the options in each Tile function that you want to set the zoom levels for.

library(leaflet)

## the first two tiles have a zoom level control - the others don't
leaflet() %>%
    setView(lng = 144, lat = -37, zoom = 09) %>%
    addProviderTiles("Stamen.TonerLite",
                     group = "Toner", 
                     options = providerTileOptions(minZoom = 8, maxZoom = 10)) %>%
    addTiles(group = "OSM",
             options = providerTileOptions(minZoom = 8, maxZoom = 10)) %>%
    addProviderTiles("Esri.WorldTopoMap",    
                     group = "Topo") %>%
    addProviderTiles("OpenStreetMap.Mapnik", group = "Mapnik") %>%
    addProviderTiles("CartoDB.Positron",     group = "CartoDB") %>%
    addLayersControl(baseGroups = c("Toner", "OSM", "Topo", "Mapnik", "CartoDB"),
                     options = layersControlOptions(collapsed = TRUE))
like image 75
SymbolixAU Avatar answered Oct 21 '22 16:10

SymbolixAU