-
Notifications
You must be signed in to change notification settings - Fork 126
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
[Compose] - AnnotatedLayerFeature not working in ViewAnnotation #2344
Comments
I have same probrem. Feature.fromGeometry(
marker.point,
null,
marker.id
) We can't specify annotation id when create annotation. I think Annotation Id is created randomly. |
Thanks for the report, I've created an internal ticket to expose feature id when creating annotation, so to align with iOS implementation. |
@shrikanth-zuper Regarding this specific question, I don't think using I'd suggest to use query rendered features and show
|
Hey @pengdev, Thank you so much for this RenderedQuery solution. Now I'm able to hide the ViewAnnotations when PointAnnotations are clustered. Although there is one issue. I tried this solution and found out that mapIdleEvents is emitted every few 100 ms. Due to this mapView.queueEvent is getting called every few 100 ms when the map is idle unless the user moves the camera. Also visibleAnnotations are getting cleared and updated constantly during this process. I have tried an alternate solution where I used the MapEvents -> onMapIdle and onCameraChanged callbacks to identify when the map is idle and query the visible features only once and update the list. Is this solution efficient? val visibleAnnotations = remember {
mutableStateListOf<Feature>()
}
var isMapIdle by remember {
mutableStateOf(false)
}
MapboxMap(
modifier = Modifier.fillMaxSize(),
mapViewportState = mapboxViewPortState,
mapEvents = MapEvents(
onMapIdle = {
Timber.d("MAPBOX: MAP IDLE")
isMapIdle = true
},
onCameraChanged = {
Timber.d("MAPBOX: CAMERA CHANGED")
isMapIdle = false
}
),
) {
MapEffect(isMapIdle, size) { mapView ->
val mapboxMap = mapView.mapboxMap
if(isMapIdle) {
// schedule the query rendered features on render thread to avoid blocking main thread.
mapView.queueEvent(
event = {
mapboxMap.queryRenderedFeatures(
RenderedQueryGeometry(
ScreenBox(
ScreenCoordinate(
0.0,
0.0
),
ScreenCoordinate(size.width.toDouble(), size.height.toDouble())
)
),
options = RenderedQueryOptions(listOf(ANNOTATION_GROUP_LAYER_ID), null)
) { expected ->
expected.value?.let { queriedRenderedFeatures ->
val features = queriedRenderedFeatures.map { it.queriedFeature.feature }
// Update only the diff of the features to avoid unnecessary removing/adding of view annotations.
visibleAnnotations.removeAll { !features.contains(it) }
visibleAnnotations.addAll(features.filter { !visibleAnnotations.contains(it) })
}
}
},
needRender = false
)
}
}
} |
Environment
Observed behavior and steps to reproduce
I'm currently displaying a
ViewAnnotation
for aPointAnnotation.
In order to hide theViewAnnotation
when thatPointAnnotation
is clustered, I'm using theannotatedLayerFeature
to set the layer and feature id.As seen from sample apps and other documentations, setting
annotatedLayerFeature
should ideally result in a behaviour whereViewAnnotation
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.Expected behavior
When using
annotatedLayerFeature
option inViewAnnotation
, 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 creatingPointAnnotationOption
using the fromFeature method, while checking this method I noticed that we are not at all using the id value from the feature.The text was updated successfully, but these errors were encountered: