From 42691b7986d2bae47dba5179037479150a2168a0 Mon Sep 17 00:00:00 2001 From: ank27 Date: Thu, 1 Dec 2022 14:08:30 +0200 Subject: [PATCH] limit bounds calculation loop --- .../main/java/com/mapbox/maps/ViewAnnotationManagerImpl.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sdk/src/main/java/com/mapbox/maps/ViewAnnotationManagerImpl.kt b/sdk/src/main/java/com/mapbox/maps/ViewAnnotationManagerImpl.kt index 688242093f..8160b91f86 100644 --- a/sdk/src/main/java/com/mapbox/maps/ViewAnnotationManagerImpl.kt +++ b/sdk/src/main/java/com/mapbox/maps/ViewAnnotationManagerImpl.kt @@ -209,8 +209,11 @@ internal class ViewAnnotationManagerImpl( var west: Pair? = null var south: Pair? = null - while (!isCorrectBound) { + // we run the loop twice to adjust bounds correctly to fit all the annotations. + var boundsCounter = 1 + while (!isCorrectBound && boundsCounter <= MAX_ADJUST_BOUNDS_COUNTER) { val zoom = cameraOptionForCoordinates.zoom + boundsCounter++ isCorrectBound = true viewAnnotationOptions.forEach { options -> val frame = getViewAnnotationOptionsFrame(options) ?: Rect(0, 0, 0, 0) @@ -662,6 +665,7 @@ internal class ViewAnnotationManagerImpl( internal const val EXCEPTION_TEXT_ASSOCIATED_FEATURE_ID_ALREADY_EXISTS = "View annotation with associatedFeatureId=%s already exists!" private const val TAG = "ViewAnnotationImpl" + private const val MAX_ADJUST_BOUNDS_COUNTER = 2 @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) internal fun needToReorderZ(