startDownload method
- List<
RectangleGeographicArea> areas, - void onComplete(
- 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:- GemError.success — Download completed successfully.
- GemError.outOfRange — One or more requested areas exceed the configured getMaxSquareKm.
- GemError.cancel — The download was cancelled by calling cancelDownload.
- GemError.upToDate — The requested area is already cached and no download was necessary.
Returns
- (
ProgressListener?) A ProgressListener instance that can be used to monitor progress and register additional callbacks, ornullif 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:
- cancelDownload — Cancel a running download.
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;
}