dispose method

Future<void> dispose()

Fully dipose of all the the resouces managed by the annotation manager. The manager cannot be used after this has been called

Implementation

Future<void> dispose() async {
  if (controller.isDisposed) return;

  // De-register the callbacks registered in the constructor first, before
  // anything below can throw. Otherwise a manager recreated after a style
  // reload would leave the disposed manager's callbacks attached to the
  // controller, which then resolve ids against an already cleared
  // `_idToAnnotation` (jumpy drags, missing-key errors).
  if (onTap != null) {
    controller.onFeatureTapped.remove(_onFeatureTapped);
  }
  controller.onFeatureDrag.remove(_onDrag);

  _idToAnnotation.clear();
  // No _setAll() here: the sources are removed right below anyway, and when
  // this runs because the style was replaced they are already gone - the
  // setGeoJsonSource call would then hit a missing source on the native side.
  for (var i = 0; i < allLayerProperties.length; i++) {
    await controller.removeLayer(_makeLayerId(i));
    await controller.removeSource(_makeLayerId(i));
  }
}