diff --git a/maps-compose-utils/src/main/java/com/google/maps/android/compose/clustering/Clustering.kt b/maps-compose-utils/src/main/java/com/google/maps/android/compose/clustering/Clustering.kt index cf61e87ec..47169aef7 100644 --- a/maps-compose-utils/src/main/java/com/google/maps/android/compose/clustering/Clustering.kt +++ b/maps-compose-utils/src/main/java/com/google/maps/android/compose/clustering/Clustering.kt @@ -3,6 +3,7 @@ package com.google.maps.android.compose.clustering import android.os.Handler import android.os.Looper import androidx.compose.runtime.Composable +import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.MutableState import androidx.compose.runtime.SideEffect @@ -92,6 +93,14 @@ public fun Clustering( clusterManager.cluster() } } + + // Disposes the clustering items if re-composed and removed. + DisposableEffect(itemsState) { + onDispose { + clusterManager.clearItems() + clusterManager.cluster() + } + } } @OptIn(MapsComposeExperimentalApi::class)