I am using Openstreetmaps with R/Shiny. I am trying to restrict map display to a given range of coordinates, i.e.xmin, ymin, xmax, ymax so that the users of the map won't be able to look other parts of the world other than the ones that are within the range.

I've made some research about it, but it hasn't been possible to find an answer. How can I do that?


According to this github issue:


you should be able to specify max bounds and min/max zoom levels with code like this

myMap <- leaflet(options = leafletOptions(minZoom = 11)) %>%
  addProviderTiles("OpenStreetMap") %>%
  setView( lng = -87.567215
           , lat = 41.822582
           , zoom = 11 ) %>%
  setMaxBounds( lng1 = -87.94011
                , lat1 = 41.64454
                , lng2 = -87.52414
                , lat2 = 42.02304 )
| improve this answer | |

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.