Skip to content

Instantly share code, notes, and snippets.

@kuwapa
Created October 16, 2021 20:29
Show Gist options
  • Save kuwapa/6724d2352beee142d469b51e111f05fb to your computer and use it in GitHub Desktop.
Save kuwapa/6724d2352beee142d469b51e111f05fb to your computer and use it in GitHub Desktop.
restricting map to bounds. Gist #2
map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0),
object : MapboxMap.CancelableCallback {
override fun onCancel() {}
override fun onFinish() {
map.setMinZoomPreference(map.cameraPosition.zoom)
map.limitViewToBounds(bounds)
map.addOnScaleListener(object : MapboxMap.OnScaleListener {
override fun onScaleBegin(detector: StandardScaleGestureDetector) {}
override fun onScale(detector: StandardScaleGestureDetector) {
map.limitViewToBounds(bounds)
}
override fun onScaleEnd(detector: StandardScaleGestureDetector) {}
})
map.addOnCameraIdleListener { map.limitViewToBounds(bounds) }
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment