android-maps-compose icon indicating copy to clipboard operation
android-maps-compose copied to clipboard

Can't use Marker as a default clusterItemContent

Open Psijic opened this issue 2 years ago • 5 comments

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)
            }

Psijic avatar Apr 19 '23 18:04 Psijic

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:

This is an automated message, feel free to ignore.

wangela avatar Apr 19 '23 18:04 wangela

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"
                )
            }

ghost avatar Apr 25 '23 10:04 ghost

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?

Psijic avatar May 05 '23 11:05 Psijic

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))
    }
}

Psijic avatar May 05 '23 17:05 Psijic