mapbox / mapbox/mapbox-maps-android
how create custom cluster in mapbox android(Jetpack compose )
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 578
- Forks
- 161
- PR merge metrics
- No merged PRs in 30d
Description
Hello I want to create custom cluster with my compose component
```kotlin
@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
```kotlin
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by comparing the Compose ViewAnnotation entry point with PointAnnotationGroup and the mentioned ViewAnnotationNode and MapApplier internals. Done means a custom Compose cluster appearance is rendered instead of the default circular cluster while preserving the event annotations and interactions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin
- Domain
- mobile
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100