startDownload method
- List<
RectangleGeographicArea> areas, - void onComplete(
- GemError err
Downloads map tiles for the given area(s).
Parameters
- IN areas The areas to download.
- IN onComplete Callback to be called when the download is complete.
- Will be called with GemError.success error and non-null result upon success.
- Will be called with GemError.outOfRange error if the area is too large for the specified maxSquareKm.
- Will be called with GemError.cancel error if the download was cancelled.
- Will be called with GemError.upToDate error if the area is cached.
Returns
- ProgressListener for the operation progress if the operation could be started, null otherwise.
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.registerOnCompleteWithDataCallback((
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;
}