startDownload method

ProgressListener? startDownload(
  1. List<RectangleGeographicArea> areas,
  2. void onComplete(
    1. GemError err
    )
)

Starts downloading map tiles for the specified geographic area(s).

Completion is reported through the onComplete callback with a GemError indicating the final status. If the operation cannot be started an error will be delivered to onComplete and the method returns null.

Parameters

  • areas: (List<RectangleGeographicArea>) A list of one or more geographic rectangles to download tiles for.
  • onComplete: (void Function(GemError err)) Callback invoked when the operation finishes. The callback receives a GemError with one of the following meaningful values:

Returns

  • (ProgressListener?) A ProgressListener instance that can be used to monitor progress and register additional callbacks, or null if the operation could not be started.

Example

final service = MapDownloaderService();
service.setMaxSquareKm = 300;

service.startDownload([area], (err) {
  if (err == GemError.success) {
    print('Download started successfully.');
  } else {
    print('Failed to start download: $err');
  }
});

See also:

Implementation

ProgressListener? startDownload(
  List<RectangleGeographicArea> areas,
  final void Function(GemError err) onComplete,
) {
  final EventDrivenProgressListener progListener =
      EventDrivenProgressListener();

  final OperationResult resultString = objectMethod(
    pointerId,
    'MapDownloaderService',
    'startDownload',
    args: <String, Object>{
      'areasCoordinates': areas,
      'progressListener': progListener.id,
    },
  );

  // ignore: unnecessary_type_check
  if (resultString.data is Map && resultString.containsKey('gemApiError')) {
    final int errorCode = resultString['gemApiError'] as int;
    final GemError error = GemErrorExtension.fromCode(errorCode);
    if (error != GemError.success) {
      onComplete(error);
      return null;
    }
  }

  progListener.registerOnCompleteWithData((
    final int err,
    final String hint,
    final Map<dynamic, dynamic> json,
  ) {
    if (err == 0) {
      onComplete(GemErrorExtension.fromCode(0));
    } else {
      onComplete(GemErrorExtension.fromCode(err));
    }
  });

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