dragEvents method

Cancelable dragEvents({
  1. dynamic onBegin(
    1. PolygonAnnotation
    )?,
  2. dynamic onChanged(
    1. PolygonAnnotation
    )?,
  3. dynamic onEnd(
    1. PolygonAnnotation
    )?,
})

Registers drag event callbacks for the annotations managed by this manager.

  • onBegin: Triggered when a drag gesture begins on an annotation.
  • onChanged: Triggered continuously as the annotation is being dragged.
  • onEnd: Triggered when the drag gesture ends.

This method returns a Cancelable object that can be used to cancel the drag event listener when it's no longer needed. Example usage:

manager.dragEvents(
  onBegin: (annotation) {
    print("Drag started for: ${annotation.id}");
  },
  onChanged: (annotation) {
    print("Dragging at: ${annotation.geometry}");
  },
  onEnd: (annotation) {
    print("Drag ended at: ${annotation.geometry}");
  },
);

Implementation

Cancelable dragEvents({
  Function(PolygonAnnotation)? onBegin,
  Function(PolygonAnnotation)? onChanged,
  Function(PolygonAnnotation)? onEnd,
}) {
  return _annotationInteractionEvents(
          instanceName: "$_channelSuffix/$id/drag")
      .cast<PolygonAnnotationInteractionContext>()
      .listen((data) {
    switch (data.gestureState) {
      case GestureState.started when onBegin != null:
        onBegin(data.annotation);
      case GestureState.changed when onChanged != null:
        onChanged(data.annotation);
      case GestureState.ended when onEnd != null:
        onEnd(data.annotation);
      default:
        break;
    }
  }).asCancelable();
}