mapbox-maps-android icon indicating copy to clipboard operation
mapbox-maps-android copied to clipboard

PointAnnotations disappear/reappear depending on zoom level

Open brendanw opened this issue 1 year ago • 1 comments

Environment

  • Android OS version: Android 34
  • Devices affected: Pixel 5
  • Maps SDK Version: 11.3.0-beta.1

Observed behavior and steps to reproduce

After applying a filter that impacts the data source for a PointAnnotationGroup, PointAnnotation visibility does not persist, individual PointAnnotations disappear and re-appear depending on zoom level.

See screen recording at https://brendanw.s3.us-west-2.amazonaws.com/pointAnnotationIssue.mov

I didn't have this issue before switching to using the compose extension.

Expected behavior

PointAnnotation visibility should not change based on zoom level

Notes / preliminary analysis

Here is my compose extension usage

         val shouldDisplayExits = AppDependencies.mapModel.shouldDisplayExits.collectAsState().value
         if (shouldDisplayExits) {
            val exits = AppDependencies.mapModel.exits.collectAsState()
            val points = remember(exits.value) {
               if (exits.value == null) {
                  return@remember emptyList()
               } else {
                  exits.value!!.map { exit -> createPointAnnotationOption(exit) }
               }
            }

            PointAnnotationGroup(
               annotations = points,
               onClick = { pointAnnotation ->
                  val data = pointAnnotation.getData()
                  if (data?.isJsonNull == true || data == null) {
                     return@PointAnnotationGroup false
                  }

                  val jsonObject = data.asJsonObject ?: return@PointAnnotationGroup false
                  val exitId = jsonObject.get("exitId").asString ?: return@PointAnnotationGroup false
                  val exitName = jsonObject.get("exitName").asString ?: return@PointAnnotationGroup false
                  val isExitVerified = jsonObject.get("isExitVerified").asBoolean
                  lastViewAnnnotationOpen.value = Clock.System.now().toEpochMilliseconds()
                  AppDependencies.mapModel.openViewAnnotation(
                     exitId = exitId,
                     text = exitName,
                     latitude = pointAnnotation.point.latitude(),
                     longitude = pointAnnotation.point.longitude(),
                     profileId = null,
                     isVerified = isExitVerified,
                     dropzoneId = null
                  )

                  true
               }
            )
         }
         
private fun createPointAnnotationOption(exit: MapExit): PointAnnotationOptions {
   val element = JsonObject()
   element.addProperty("exitId", exit._id)
   element.addProperty("exitName", exit.name)
   element.addProperty("isExitVerified", exit.isExitVerified)
   val option = PointAnnotationOptions()
      .withPoint(Point.fromLngLat(exit.longitude, exit.latitude))
      .withIconImage("blue-pin")
      .withData(element)
   return option
}

brendanw avatar Mar 18 '24 04:03 brendanw

@brendanw from the video, it looks like the somehow the iconAllowOverlap behaves like it was disabled, could you try to manually set it to true?

Please also note there's a known issue regarding applying AnnotationGroup properties, which is fixed in 11.3.0-rc.1 release, please update to the latest version and try again.

pengdev avatar Apr 02 '24 08:04 pengdev

I am still seeing the issue with setting iconAllowOverlap=true on the PointAnnotationGroup and using 11.3.0-rc.1

brendanw avatar Apr 02 '24 16:04 brendanw

@brendanw could you also try with setting iconIgnorePlacement = true?

pengdev avatar Apr 05 '24 13:04 pengdev

I am still seeing the issue with setting iconIgnorePlacement = true on the PointAnnotationGroup and using 11.3.0-rc.1

brendanw avatar Apr 06 '24 03:04 brendanw

@brendanw could you please provide a minimal project to reproduce the issue? maybe a patch to our existing compos-app example app would be really helpful.

pengdev avatar Apr 12 '24 10:04 pengdev

@pengdev

https://github.com/brendanw/MapboxMemLeak/tree/bw/pointAnnotationIssue

^^ Can reproduce the issue by running the code on the pointAnnotationIssue branch. Just need to populate MAPBOX_SECRET_TOKEN environment variable before running.

I am reusing an older reproducer project for this, but here's the minimal diff for reproducing the issue -> https://github.com/brendanw/MapboxMemLeak/pull/2

With regard to the compose example app, I tried to use the compose-app example app. I populated SDK_REGISTRY_TOKEN and could get the application running, but the map screens all rendered black.

brendanw avatar Apr 12 '24 12:04 brendanw

@pengdev I updated the reproduction code at https://github.com/brendanw/MapboxMemLeak/pull/2 to use 11.3.1 and the issue is still present. This is a pretty significant issue and there is another issue that is blocking us from moving away from the compose extension, will this issue be addressed in 11.3.2 ?

brendanw avatar Apr 29 '24 13:04 brendanw

@brendanw sorry didn't have time to try your branch earlier, I dropped a comment in your branch and with iconAllowOverlap=true set to the PointAnnotationGroup, I do see the issue being resolved, please let me know if you have other issues.

pengdev avatar Apr 30 '24 10:04 pengdev

@pengdev I am an idiot. I have multiple PointAnnotationGroup's for the screen this is on and I neglected to add this field to one of those groups. Thanks for bearing with me and apologies for the false report!

brendanw avatar Apr 30 '24 13:04 brendanw