From 3b26ba4e86f897507117152dd7cb0d5bc9e8d840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrique=20Lo=CC=81pez=20Man=CC=83as?= Date: Mon, 27 Nov 2023 08:57:49 +0100 Subject: [PATCH] docs: showcase usage of custom algorithm --- .../android/compose/MarkerClusteringActivity.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/src/main/java/com/google/maps/android/compose/MarkerClusteringActivity.kt b/app/src/main/java/com/google/maps/android/compose/MarkerClusteringActivity.kt index 28068b79a..d7bfe60a2 100644 --- a/app/src/main/java/com/google/maps/android/compose/MarkerClusteringActivity.kt +++ b/app/src/main/java/com/google/maps/android/compose/MarkerClusteringActivity.kt @@ -31,6 +31,7 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color +import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp @@ -38,6 +39,7 @@ import androidx.compose.ui.unit.sp import com.google.android.gms.maps.model.CameraPosition import com.google.android.gms.maps.model.LatLng import com.google.maps.android.clustering.ClusterItem +import com.google.maps.android.clustering.algo.NonHierarchicalViewBasedAlgorithm import com.google.maps.android.compose.clustering.Clustering import com.google.maps.android.compose.clustering.rememberClusterManager import com.google.maps.android.compose.clustering.rememberClusterRenderer @@ -171,7 +173,19 @@ private fun CustomUiClustering(items: List) { @OptIn(MapsComposeExperimentalApi::class) @Composable fun CustomRendererClustering(items: List) { + val configuration = LocalConfiguration.current + val screenHeight = configuration.screenHeightDp.dp + val screenWidth = configuration.screenWidthDp.dp val clusterManager = rememberClusterManager() + + // Here the clusterManager is being customized with a NonHierarchicalViewBasedAlgorithm. + // This speeds up by a factor the rendering of items on the screen. + clusterManager?.setAlgorithm( + NonHierarchicalViewBasedAlgorithm( + screenHeight.value.toInt(), + screenWidth.value.toInt() + ) + ) val renderer = rememberClusterRenderer( clusterContent = { cluster -> CircleContent(