Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

leaflet setView zoom level to non integer (decimal) value in R?

Tags:

r

leaflet

Using the leaflet R package, is there a way to set zoom to a non-integer (i.e. decimal) value?

That is, something inbetween these two zoom levels:

enter image description here

Example

As zoom moves from level 3 through to 4, it appears as though it's being rounded to the nearest integer

The only thing changing below is the zoom parameter

library(leaflet)
library(dplyr)

leaflet() %>%
  addTiles() %>% 
  setView(lng=174.768, lat=-36.852, zoom = 3) %>% 
  addMarkers(lng=174.768, lat=-36.852, popup="The birthplace of R") 


leaflet() %>%
  addTiles() %>% 
  setView(lng=174.768, lat=-36.852, zoom = 3.2) %>% 
  addMarkers(lng=174.768, lat=-36.852, popup="The birthplace of R") 

leaflet() %>%
  addTiles() %>% 
  setView(lng=174.768, lat=-36.852, zoom = 3.4) %>% 
  addMarkers(lng=174.768, lat=-36.852, popup="The birthplace of R") 

leaflet() %>%
  addTiles() %>% 
  setView(lng=174.768, lat=-36.852, zoom = 3.6) %>% 
  addMarkers(lng=174.768, lat=-36.852, popup="The birthplace of R") 


leaflet() %>%
  addTiles() %>% 
  setView(lng=174.768, lat=-36.852, zoom = 3.8) %>% 
  addMarkers(lng=174.768, lat=-36.852, popup="The birthplace of R") 


leaflet() %>%
  addTiles() %>% 
  setView(lng=174.768, lat=-36.852, zoom = 4) %>% 
  addMarkers(lng=174.768, lat=-36.852, popup="The birthplace of R") 

Question

Is there a way to set a non-integer (decimal) zoom?

Note ?setView leads to zoom pan options, which returns a 404

like image 851
stevec Avatar asked Sep 01 '25 04:09

stevec


1 Answers

You need Fractional Zoom:

var map = L.map('map', {zoomSnap: 0.25});

There is more about it here: https://leafletjs.com/examples/zoom-levels/

I use it on one of my maps like this:

var map = L.map('map', {attributionControl: false, crs: L.CRS.Simple, zoomSnap: 0.25, minZoom: -3});

...

map.setView(xy(<%= @image.width.to_i/2 %>, <%= @image.height.to_i/2 %>), -1.5);
like image 155
Jeremy Gradisher Avatar answered Sep 02 '25 19:09

Jeremy Gradisher