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

how create custom cluster in mapbox android(Jetpack compose ) #2572

Open
yet300 opened this issue Feb 11, 2025 · 3 comments
Open

how create custom cluster in mapbox android(Jetpack compose ) #2572

yet300 opened this issue Feb 11, 2025 · 3 comments
Labels

Comments

@yet300
Copy link

yet300 commented Feb 11, 2025

Hello I want to create custom cluster with my compose component

@Composable
private fun EventPinContent(event: Event) {
    Box(
        modifier = Modifier
            .size(width = 155.dp, height = 55.dp)
            .clip(PinMapShape())
            .background(MaterialTheme.colorScheme.background)
    ) {
        Row(
            modifier = Modifier
                .fillMaxWidth()
                .offset(x = 10.dp, y = 6.dp),
            verticalAlignment = Alignment.CenterVertically,
            horizontalArrangement = Arrangement.spacedBy(7.dp)
        ) {
            Icon(
                painter = painterResource(EventCategoryPaint(event.category)),
                contentDescription = null,
                tint = MaterialTheme.colorScheme.primary,
                modifier = Modifier.size(24.dp)
            )

            Text(
                text = event.title,
                color = MaterialTheme.colorScheme.primary,
                style = interBold13to19(),
                maxLines = 1,
                overflow = TextOverflow.Ellipsis,
            )
        }
    }
}

@Composable
private fun ClusterPinContent(count: Int) {
    Box(
        modifier = Modifier
            .wrapContentSize()
            .defaultMinSize(minWidth = 100.dp)
            .height(55.dp)
            .clip(PinMapShape())
            .background(MaterialTheme.colorScheme.background)
            .padding(horizontal = 10.dp)
    ) {
        Row(
            modifier = Modifier
                .fillMaxWidth()
                .padding(vertical = 6.dp),
            verticalAlignment = Alignment.CenterVertically,
            horizontalArrangement = Arrangement.spacedBy(7.dp)
        ) {
            NumberBox(
                number = count,
                modifier = Modifier.size(width = 39.dp, height = 28.dp)
            )
            Text(
                text = stringResource(Res.strings.events),
                color = MaterialTheme.colorScheme.primary,
                style = interBold13to19(),
                maxLines = 1,
                overflow = TextOverflow.Ellipsis,
            )
        }
    }
}

now I use ViewAnnotation

events.forEach { event ->
        val point = Point.fromLngLat(event.longitude, event.latitude)

        ViewAnnotation(
            options = viewAnnotationOptions {
                geometry(point)
                allowOverlap(true)
            },
            modifier = Modifier.clickable { component.onEventClick(event) }
        ) {
            EventPinContent(event)
        }
    }

I tried to use PointAnnotationGroup but it draws a circular cluster, I also tried to combine the two approaches, but because ViewAnnotationNode and MapApplier internal

in the second picture, it's working.
https://docs.mapbox.com/android/assets/ideal-img/maps-guides-standard-usecases.92d97f8.960.png

@yet300
Copy link
Author

yet300 commented Feb 12, 2025

@natiginfo
Copy link
Contributor

Hi! Currently, we don't support view annotation clustering.

@yet300
Copy link
Author

yet300 commented Feb 13, 2025

Hi again, how can i make a custom cluster design? I need to display on the map the events that people have created, on the pin will be displayed the icon of the event and its name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants