Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use Marker as a default clusterItemContent #310

Open
Psijic opened this issue Apr 19, 2023 · 4 comments
Open

Can't use Marker as a default clusterItemContent #310

Psijic opened this issue Apr 19, 2023 · 4 comments
Assignees
Labels
priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@Psijic
Copy link

Psijic commented Apr 19, 2023

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 Psijic added triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Apr 19, 2023
@wangela
Copy link
Member

wangela commented Apr 19, 2023

If you would like to upvote the priority of this issue, please comment below or react with 👍 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.

@ghost
Copy link

ghost commented Apr 25, 2023

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

@Psijic
Copy link
Author

Psijic commented May 5, 2023

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
Copy link
Author

Psijic commented May 5, 2023

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

@kikoso kikoso added priority: p3 Desirable enhancement or fix. May not be included in next release. and removed triage me I really want to be triaged. labels Jul 10, 2023
@kikoso kikoso self-assigned this Sep 29, 2023
@wangela wangela added priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. and removed priority: p3 Desirable enhancement or fix. May not be included in next release. labels Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

4 participants