R Leaflet: Zoom Control Level
13,176
A couple of points:
- It's
minZoom
andmaxZoom
(notice the capital Z) - 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))
Author by
Alex Soto
Updated on June 14, 2022Comments
-
Alex Soto almost 2 years
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))