getAvailableOverlays static method

(OverlayCollection, bool) getAvailableOverlays({
  1. void onCompleteDownload(
    1. GemError error
    )?,
})

Retrieve overlays available for the current map style.

The method returns a tuple containing an OverlayCollection and a boolean that indicates whether all overlay information was immediately available. If the boolean is false some overlay metadata will be downloaded later and the optional onCompleteDownload callback will be invoked when the download completes.

Parameters

  • onCompleteDownload: Optional callback invoked with a GemError when asynchronous overlay metadata download finishes.

Returns

  • A OverlayCollection containing the available overlays.
  • A bool which is true when all overlay information was immediately available. If false, some overlay metadata will be downloaded later and the optional onCompleteDownload callback will be invoked when the download completes.

Example

final Completer<GemError> completer = Completer<GemError>();
final (OverlayCollection, bool) availableOverlays = OverlayService.getAvailableOverlays(onCompleteDownload: (error) {
    completer.complete(error);
});
await completer.future;
OverlayCollection collection = availableOverlays.$1;

Implementation

static (OverlayCollection, bool) getAvailableOverlays({
  final void Function(GemError error)? onCompleteDownload,
}) {
  EventDrivenProgressListener? listener;
  if (onCompleteDownload != null) {
    listener = EventDrivenProgressListener();

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

    GemKitPlatform.instance.registerEventHandler(listener.id, listener);
  }

  final OperationResult resultString = staticMethod(
    'OverlayService',
    'getAvailableOverlays',
    args: (listener != null) ? listener.id : 0,
  );

  final (OverlayCollection, bool) result = (
    OverlayCollection.init(resultString['result']['first']),
    resultString['result']['second'],
  );

  if (onCompleteDownload != null && result.$2) {
    onCompleteDownload(GemError.success);
  }

  return result;
}