mapbox / mapbox/mapbox-maps-android

[Compose] - AnnotatedLayerFeature not working in ViewAnnotation

Open
#2,344 4 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auto-triaged bug :beetle: compose
Dominant language
Kotlin
Stars
578
Forks
161
PR merge metrics
No merged PRs in 30d

Description

Environment

  • Android OS version: 14
  • Devices affected: All devices
  • Maps SDK Version: 11.3.0

Observed behavior and steps to reproduce

I'm currently displaying a ViewAnnotation for a PointAnnotation. In order to hide the ViewAnnotation when that PointAnnotation is clustered, I'm using the annotatedLayerFeature to set the layer and feature id.

As seen from sample apps and other documentations, setting annotatedLayerFeature should ideally result in a behaviour where ViewAnnotation will be displayed only when that marker is visible. This is working as expected in iOS, but in Android it's not working properly. ViewAnnotation is not at all displayed when using annotatedLayerFeature.

MapboxMap {
    // Rendering markers (Point Annotations)
    PointAnnotationGroup(
        annotations = markers.invoke().map { marker ->
            (PointAnnotationOptions.fromFeature(
                Feature.fromGeometry(
                    marker.point,
                    null,
                    marker.id
                )
            ) ?: PointAnnotationOptions().withPoint(marker.point.toPoint()))
                .withIconImage(marker.icon)
        },
        annotationConfig = AnnotationConfig(
            layerId = "PointAnnotationLayer",
            annotationSourceOptions = AnnotationSourceOptions(
                clusterOptions = ClusterOptions(
                    textColor = Color.WHITE,
                    textSize = 16.0,
                    colorLevels = listOf(
                        Pair(0, Color.BLACK)
                    )
                )
            )
        )
    )

    // Rendering tool windows (View Annotations)
    markers.invoke().forEach { marker ->
        ViewAnnotation(
            options = viewAnnotationOptions {
                geometry(marker.point.toPoint())
                // This has no effect
                annotatedLayerFeature(
                    layerId = "PointAnnotationLayer"
                ) {
                    featureId(marker.id)
                }
                annotationAnchor {
                    anchor(ViewAnnotationAnchor.TOP)
                    offsetY(160.0)
                }
                allowOverlap(false)
            },
            content = marker.toolWindow
        )
    }
}

Expected behavior

When using annotatedLayerFeature option in ViewAnnotation, that ViewAnnotation should be displayed when that marker is visible and it should be hidden when the marker is clustered. This is working properly in iOS.

Notes / preliminary analysis

This feature is working properly in iOS. Also noticed that there is an option to send id for PointAnnotation in iOS. There is no such option in Android to set the id in composable side as well as in PointerAnnotationOption. I tried creating PointAnnotationOption using the fromFeature method, while checking this method I noticed that we are not at all using the id value from the feature.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Compose ViewAnnotation and PointAnnotationGroup entry points, then trace annotatedLayerFeature and PointAnnotationOptions.fromFeature, especially how the feature id is handled. Reproduce the Android 14 behavior with the issue's sample and verify that the ViewAnnotation appears for a visible marker and hides when that marker is clustered, matching iOS.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.