ShurupuS ShurupuS - 1 year ago 200
iOS Question

How to limit map bounds in mapbox MGLMapView?

I'm using

mapbox-iOS-SDK 3.2.3
and can't find any properties or smth like this to control the map bounds. I need to limit the visible area for the user. Is it possible in current SDK version?


There's nothing built in to the current version of Mapbox that looks like it would do what you want. You might be able to get something like it by

  1. Implementing mapViewRegionIsChanging: or mapView:regionDidChangeAnimated: in the map view delegate
  2. In those methods, check the current region. If it's outside the desired area, reset the map view to something inside the desired region. That is, as soon as the map view starts to move outside the region, make it go back.

This would probably work but it might make the view "stutter" if the user tries to scroll outside the target region. I don't know what your app does, but it might be worth considering (a) whether this is actually necessary and (b) whether there might be a better way to avoid whatever problem you expect than restricting map view scrolling.