Can't use Marker as a default clusterItemContent
I wanted to use default markers and change the color of the selected ones. But I can't use even a default Marker as a clusterItemContent because of the error:
java.lang.IllegalArgumentException: width and height must be > 0
I can't change the size of the Marker because it doesn't have a Modifier parameter. So, how can I change the color of the selected marker as before (or in more optimal way), disable titles, snippets etc.?
clusterItemContent = {
Marker(
//icon = it.getMarkerDescriptor(selectedEvent == it)
)
}
fun getMarkerDescriptor(isSelected: Boolean = false): BitmapDescriptor? =
if (isSelected) BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE) else null
P.S. If I use a custom icon, it drastically decrease performance (especially in debug mode). Is there a way to optimize it?
P.P.S. With a custom icon, I also can't disable snippets and title - only sending null in the data. (The way it doesn't show is to send true in onClusterItemClick)
clusterItemContent = {
Icon(imageVector = Icons.Filled.Abc, it.name)
}
If you would like to upvote the priority of this issue, please comment below or react with :+1: so we can see what is popular when we triage.
@Psijic Thank you for opening this issue. 🙏 Please check out these other resources that might help you get to a resolution in the meantime:
- Check the issue tracker - bugs and feature requests for Google Maps Platform APIs and SDKs
- Open a support case - Get 1:1 support in Cloud Console.
- Discord - chat with other developers
- StackOverflow - use the
google-mapstag
This is an automated message, feel free to ignore.
Similar issue on my end - using Marker as clusterItemContent results in java.lang.IllegalStateException: Invalid applier. This is very simple to reproduce in the sample. Just add this code to MapClusteringActivity:
// Optional: Custom rendering for non-clustered items
clusterItemContent = {
Marker(
state = MarkerState(position = it.itemPosition),
title = "Title",
snippet = "Snippet"
)
}
Hm, I see a huge performance difference in clustering about 1k of items. Even if I use a 990 bytes .webp Image as an item, it has about 3x time against default markers to re-cluster. And that time the UI is frozen even if I use Clustering in LaunchedEffect.
How can I make the selected marker different (change size and/or color) to not to decrease performance?
As for now the simplest way is to add a new marker with same position to the content:
val content: (@Composable () -> Unit) = {
Clustering(
items = currentItems,
onClusterItemClick = {
Timber.v("Marker clicked: ${it.name}")
viewModel.selectItem(it)
true
}
)
selectedItem?.let {
Marker(state = MarkerState(it.position), zIndex = 1f, icon = BitmapDescriptorFactory.defaultMarker(
BitmapDescriptorFactory.HUE_AZURE))
}
}