grabOverlayOfflineData static method

TaskHandler? grabOverlayOfflineData({
  1. required int uid,
  2. required void onComplete(
    1. GemError error
    ),
})

Start grabbing (downloading) the latest offline overlay data for all existing offline map areas.

The operation is asynchronous; the provided onComplete callback is invoked with a GemError indicating completion status. If the grabber is not enabled for the overlay the callback receives GemError.activation.

Parameters

  • uid: Overlay UID to download data for.
  • onComplete: Callback invoked when the operation finishes.

Returns

  • A TaskHandler if the operation started successfully, otherwise null.

Example

final overlayUid = CommonOverlayId.safety.id; // Example overlay UID (e.g., speed cameras)
if (!OverlayService.isOverlayOfflineDataGrabberSupported(overlayUid)) {
  print('Overlay offline data grabber not supported for this overlay');
  return;
}

OverlayService.enableOverlayOfflineDataGrabber(overlayUid);

See also:

Implementation

// final taskHandler = OverlayService.grabOverlayOfflineData(
//     uid: overlayUid,
//     onComplete: (error) {
//     // Handle the completion of the offline data grabber (check GemError)
//   }
// );
/// ```
///
/// ## See also:
///
/// - [OverlayInfo.uid] - Retrieve the unique identifier of an overlay.
/// - [enableOverlayOfflineDataGrabber] - Enable the offline data grabber for an overlay.
/// - [disableOverlayOfflineDataGrabber] - Disable the offline data grabber for an overlay.
/// - [isOverlayOfflineDataGrabberEnabled] - Check whether the offline data grabber is enabled for an overlay.
/// - [isOverlayOfflineDataGrabberSupported] - Check whether an overlay supports the offline data grabber feature.
/// - [cancelGrabOverlayOfflineData] - Cancel a running offline data grab operation.
static TaskHandler? grabOverlayOfflineData({
  required final int uid,
  required final void Function(GemError error) onComplete,
}) {
  final EventDrivenProgressListener progListener =
      EventDrivenProgressListener();

  progListener.registerOnCompleteWithData((
    final int err,
    final String hint,
    final Map<dynamic, dynamic> json,
  ) {
    GemKitPlatform.instance.unregisterEventHandler(progListener.id);
    onComplete(GemErrorExtension.fromCode(err));
  });

  GemKitPlatform.instance.registerEventHandler(progListener.id, progListener);

  final OperationResult resultString = staticMethod(
    'OverlayService',
    'grabOverlayOfflineData',
    args: <String, dynamic>{'uid': uid, 'listener': progListener.id},
  );

  final GemError errorCode = GemErrorExtension.fromCode(
    resultString['result'],
  );

  if (errorCode != GemError.success) {
    GemKitPlatform.instance.unregisterEventHandler(progListener.id);
    onComplete(errorCode);
    return null;
  }

  return TaskHandlerImpl(progListener.id);
}