0

I have been trying to update PolylineAnnotation with a new color but keep getting the below error.

[maps-android\AnnotationManagerImpl]: Can't update annotation: com.mapbox.maps.plugin.annotation.generated.PolylineAnnotation@774cedb, the annotation isn't an active annotation.

Is there a way to check if the PolylineAnnotation is active?

I am using Mapbox Offical Package (mapbox_maps_flutter)

Here is how I have tried updating the PolylineAnnotation. I have tried using the update method on PolylineAnnotationManager

final nearestLineAnnotation = PolylineAnnotation( 
    id: nearestLine.id, 
    lineColor: selectedRadioColor, 
    lineWidth: nearestLine.lineWidth,
    geometry: nearestLine.geometry, 
);    

await _mapboxMapController.annotations
        .createPolylineAnnotationManager()
        .then(
      (polylineAnnotationManager) {
        polylineAnnotationManager.update(nearestLineAnnotation);
     },
);

Please guide me if I am doing something wrong. Thank you :-)

Indrajeet Singh
  • 62
  • 2
  • 10

1 Answers1

0

I made a mistake by initializing PolylineAnnotationManager multiple times, through which AnnotationManager could not find active PolylineAnnotations.

Note: Initialize PolylineAnnotationManager only once the map is loaded on the onMapLoadedListener event.

late PolylineAnnotationManager _polylineAnnotationManager;

_onMapLoadedListener(MapLoadedEventData event) async {
  final jsonString = await rootBundle.loadString('assets/example.json');
  _polylineAnnotationManager = await _mapboxMapController!.annotations
     .createPolylineAnnotationManager();
  drawInitailLines();
}

Now we can use _polylineAnnotationManager anywhere in the file to add, remove or modify PolylineAnnotation using Polyline ID on any event.

Indrajeet Singh
  • 62
  • 2
  • 10