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))
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.
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.
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 .
A couple of points:
minZoom
and maxZoom
(notice the capital Z)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))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With