mapbox-maps-flutter
mapbox-maps-flutter copied to clipboard
[Android] AnnotationManager seem to create duplicate annotation's ids
My code belike
Future<void> example() async {
//create point annotation-managers
final pointAnnotationOne =
await mapboxMap.annotations.createPointAnnotationManager();
final pointAnnotationTwo =
await mapboxMap.annotations.createPointAnnotationManager();
// add points
final myPointOne =
await pointAnnotationOne.create(mapbox.PointAnnotationOptions());
print(myPointOne.id); //print "0"
final myPointTwo =
await pointAnnotationTwo.create(mapbox.PointAnnotationOptions());
print(myPointTwo.id); //print "0"
// remove point
pointAnnotationOne.delete(myPointOne); // OK
pointAnnotationTwo.delete(myPointTwo); //! throw Annotation has not been added on the map
}
when I navigate to PointAnnotationController.kt, I see that different annotation managers are using the same annotationMap instance 🤔
class PointAnnotationController(private val delegate: ControllerDelegate) :
FLTPointAnnotationMessager._PointAnnotationMessager {
private val annotationMap = mutableMapOf<String, PointAnnotation>()
private val managerCreateAnnotationMap = mutableMapOf<String, MutableList<String>>()
override fun create(
managerId: String,
annotationOption: FLTPointAnnotationMessager.PointAnnotationOptions,
result: FLTPointAnnotationMessager.Result<FLTPointAnnotationMessager.PointAnnotation>
) {
try {
val manager = delegate.getManager(managerId) as PointAnnotationManager
val annotation = manager.create(annotationOption.toPointAnnotationOptions())
annotationMap[annotation.id.toString()] = annotation // **<- is something wrong here?**
if (managerCreateAnnotationMap[managerId].isNullOrEmpty()) {
managerCreateAnnotationMap[managerId] = mutableListOf(annotation.id.toString())
} else {
managerCreateAnnotationMap[managerId]!!.add(annotation.id.toString())
}
result.success(annotation.toFLTPointAnnotation())
} catch (e: Exception) {
result.error(e)
}
}
override fun delete(
managerId: String,
annotation: FLTPointAnnotationMessager.PointAnnotation,
result: FLTPointAnnotationMessager.Result<Void>
) {
try {
val manager = delegate.getManager(managerId) as PointAnnotationManager
if (!annotationMap.containsKey(annotation.id)) { // **<- is something wrong here?**
result.error(Throwable("Annotation has not been added on the map: $annotation."))
return
}
manager.delete(
annotationMap[annotation.id]!!
)
annotationMap.remove(annotation.id)
managerCreateAnnotationMap[managerId]?.remove(annotation.id)
result.success(null)
} catch (e: Exception) {
result.error(e)
}
}
Hi @ankiimation, we have addressed the issue with duplicating annotation manager id in this pr https://github.com/mapbox/mapbox-maps-flutter/pull/366, this has been included in our v1.0.0-beta.2 release, could you please try and let us know if this issue has been fixed?