1

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
3

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);
       }
")
  • 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 Nov 7 '18 at 18:03
  • 1
    That's probably worth another question, but I've answered it here anyway. – Spacedman Nov 7 '18 at 18:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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