Open shafayatb opened 1 year ago
Use clustering
How will clustering help in this situation?
I have this exact same issue.
Did you end up finding any solutions?
No. Enabled disk caching so next time it won't take much time. Also i am not using large images in the markers.
This issue has been automatically marked as stale because it has not had recent activity. Please comment here if it is still valid so that we can reprioritize. Thank you!
rendering async images is still a problem i think. also see recent discussion in https://github.com/googlemaps/android-maps-compose/issues/385
using a key to trigger re-composition of the marker when the image is loaded does not work for me. (using coil)
var showImage by remember {
mutableStateOf(false)
}
val painter = rememberAsyncImagePainter(
model = ImageRequest.Builder(LocalContext.current)
.data("https://www.aquasafemine.com/wp-content/uploads/2018/06/dummy-man-570x570.png")
.size(Size.ORIGINAL) // Set the target size to load the image at.
.build()
)
if (painter.state is AsyncImagePainter.State.Success) {
showImage = true
}
MarkerComposable(
keys = arrayOf(showImage),
state = singapore4State,
) {
Image(
painter = painter,
contentDescription = "asdf"
)
}
I've found out that using clustering plus the NonHierarchicalViewBasedAlgorithm
as algorithm for the ClusterManager
helps since it will render the images only for unclustered items that are visible on the screen.
var mapSize by remember { mutableStateOf(IntSize.Zero) }
GoogleMap(
modifier = Modifier
.fillMaxSize()
.onGloballyPositioned { mapSize = it.size },
cameraPositionState = cameraPositionState,
) {
val coroutineScope = rememberCoroutineScope()
if (!state.mapItems.isNullOrEmpty()) {
val clusterManager = rememberClusterManager<CollaboratorsMapItem>()
val renderer = rememberClusterRenderer(
clusterContent = null,
clusterItemContent = { item ->
AndroidView(
factory = { context ->
ImageView(context).apply {
scaleType = ImageView.ScaleType.CENTER_CROP
layoutParams = ViewGroup.LayoutParams(56.toPxSize, 56.toPxSize)
load(item.collaborator.imageUrl) {
allowHardware(false)
crossfade(false)
error(com.veeva.link.library.ui.R.drawable.ui_img_default_profile)
fallback(com.veeva.link.library.ui.R.drawable.ui_img_default_profile)
placeholder(com.veeva.link.library.ui.R.drawable.ui_img_default_profile)
}
}
},
modifier = Modifier
.size(56.dp)
.border(3.dp, MaterialTheme.colorScheme.surface.copy(alpha = ContentAlpha.medium), CircleShape)
.padding(3.dp)
.clip(CircleShape),
)
},
clusterManager = clusterManager,
)
SideEffect {
clusterManager ?: return@SideEffect
clusterManager.algorithm = NonHierarchicalViewBasedAlgorithm(mapSize.width.toDp.roundToInt(), mapSize.height.toDp.roundToInt())
}
SideEffect {
if (clusterManager?.renderer != renderer && renderer != null) {
(renderer as DefaultClusterRenderer).minClusterSize = 2
clusterManager?.renderer = renderer
}
}
if (clusterManager != null) {
Clustering(
items = state.mapItems,
clusterManager = clusterManager,
)
}
}
}
Basically what I am doing is downloading the images from server and making an icon with the icon generator. After all the icons has been fully generated then I am putting the markers in the map. But from large list of markers it will take too much time to draw the markers. So how to do this in an optimized way?
I tried to recompose the markers each time the image is downloaded but it got stuck in infinite recompose.