mapbox / mapbox/mapbox-maps-android
Clustering feature with custom view annotation
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 578
- Forks
- 161
- PR merge metrics
- No merged PRs in 30d
Description
## Environment
- Android OS version: 14
- Devices affected: All
- Maps SDK Version: 11.2.2 and 11.3.0-rc.1
## Observed behavior and steps to reproduce
I would like to use [this](https://docs.mapbox.com/android/maps/guides/annotations/view-annotations/) and clustering options
I create points using PointAnnotationOptions. Adds points to pointAnnotationManager. Then I want to add a custom view using addViewAnnotation. And now the points overlap the clusters instead of disappearing. There is also a problem that when a cluster is created, points further away are visible on the map instead of disappearing.
```
listPoint.map { mapPoint ->
val jsonString = gson.toJson(mapPoint)
val pointAnnotationOptions = PointAnnotationOptions().withPoint(mapPoint.point)
.withData(JsonParser.parseString(jsonString))
pointAnnotationOptionsList.add(pointAnnotationOptions)
}
```
```
val annotationConfig = AnnotationConfig(
annotationSourceOptions = AnnotationSourceOptions(
clusterOptions = ClusterOptions(
circleRadius = 24.0,
colorLevels = listOf(Pair(0, Blue500.toArgb())),
clusterMaxZoom = 15
)
)
)
```
```
AndroidView(
factory = {
MapView(it).also { mapView ->
mapView.mapboxMap.loadStyle(Style.STANDARD)
val annotationApi = mapView.annotations
pointAnnotationManager =
annotationApi.createPointAnnotationManager(annotationConfig)
mainMapboxMap = mapView.mapboxMap
setupCamera(mapView, startZoom, centerPoint)
setMaxZoom(mapView, maxZoom)
mapView.mapboxMap.subscribeCameraChanged(callback)
}
}, update = { mapView ->
mainMapboxMap = mapView.mapboxMap
pointAnnotationManager?.let { manager ->
manager.deleteAll()
mapView.viewAnnotationManager.removeAllViewAnnotations()
val listP = manager.create(pointAnnotationOptionsList)
listP.map { pointAnnotation ->
var viewAnnotation: View = mapView.viewAnnotationManager.addViewAnnotation(
resId = R.layout.annotation_view,
options = viewAnnotationOptions {
geometry(pointAnnotation.geometry)
allowOverlap(true)
}
)
viewAnnotation.setOnClickListener {
val data = pointAnnotation.getData()
val item = gson.fromJson(data, MapItemListLiteModel::class.java)
onClickPoint(item.itemId)
}
if (viewAnnotation.isVisible) {
val data = pointAnnotation.getData()
val item = gson.fromJson(data, MapItemListLiteModel::class.java)
AnnotationViewBinding.bind(viewAnnotation).apply {
icon.load(item.url) {
crossfade(true)
memoryCacheKey(MemoryCache.Key(item.itemId.toString()))
diskCacheKey(item.itemId.toString())
transformations(CircleCropTransformation())
}
}
}
}
}
}, modifier = modifier
)
```
## Expected behavior
The points should disappear and only clusters remain on the map.
## Additional links and references
https://github.com/mapbox/mapbox-maps-android/assets/26688267/18018f99-80cf-472b-a636-fa29f586f496
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
Reproduce the issue using PointAnnotationManager with AnnotationConfig and ClusterOptions, then add views through viewAnnotationManager.addViewAnnotation as shown. Compare clustering behavior with and without the custom view annotations on Android 14 using Maps SDK 11.2.2 or 11.3.0-rc.1. Done means clustered points disappear while only cluster annotations remain visible.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100