4

I need to define the maximum zoom level of a tiled map in R leaflet. The problem is that I have points that are placed very close to each other and I would like to be able to distinguish each of them on a map by further zooming in. My problem is that I cannot define the zoom level accurately as it is greyed out. How can I define the zoom level, so that it is possible to zoom in further?

I tried adding a providerTileOptions() using the maxZoom setting but this just gives me an empty map.

enter image description here

library(leaflet)
names = c("point1", "point2", "point3")
lat = c(46.67933, 46.67940, 46.67941) 
long <- c(7.310553, 7.310570, 7.310565)

data <- as.data.frame(cbind(names, as.numeric(lat), as.numeric(long)))

m <- leaflet() %>%
  addProviderTiles('Esri.WorldImagery', options = providerTileOptions()) %>% 
  addMarkers(data = data, lat = ~lat, ~long, popup = data$names, label = data$names)

m

1 Answer 1

9

If you set maxZoom and maxNativeZoom you can get past this - for example:

addProviderTiles('Esri.WorldImagery',
 options = providerTileOptions(maxNativeZoom=19,maxZoom=100)) %>% 

then from zoom level 19 to 100 it will show zoom level 19 tiles. I'm not sure what the largest zoom level for those tiles is, but if you can find it then use that instead of 19. I think its 19 because at 20 if I zoom out I can see "Not Yet Available" tiles...

You can see the current zoom level by creating an HTML element and updating it via some javascript events:

m <- leaflet() %>%
    addProviderTiles('Esri.WorldImagery' ) %>%
    addControl(html="<h1 id='zoom'>Zoom</h1>") %>%
    onRender("function(el,x,data){
       var map=this;
       var evt = function(e){
         $('#zoom').html(map.getZoom())
       };
       map.on('zoom', evt);
       }
")
3
  • Thank you for your answer @Spacedman. Just out of curiosity, is there a way to know at which zoom level you are, e.g. to print that out of a variable?
    – redshoe
    Commented Nov 7, 2018 at 18:03
  • 1
    That's probably worth another question, but I've answered it here anyway.
    – Spacedman
    Commented Nov 7, 2018 at 18:57
  • Awesome, simple solution to a problem I see on many forums!
    – Aegis
    Commented Oct 2 at 20:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.