loadStylePack method

Future<StylePack> loadStylePack(
  1. String styleURI,
  2. StylePackLoadOptions loadOptions,
  3. OnStylePackLoadProgressListener? progressListener
)

Loads a new style package or updates the existing one.

@param styleURI: The URI of the style package's associated style. @param loadOptions: The style package load options. @param progressListener: Invokes when loading progress is updated.

If a style package with the given id already exists, it is updated with the values provided to the given load options. The missing resources get loaded and the expired resources get updated.

If there no values provided to the given loadOptions, the existing style package gets refreshed: the missing resources get loaded and the expired resources get updated.

A failed load request can be reattempted with another loadStylePack call.

If the style cannot be fetched for any reason, the load request is terminated. If the style is fetched but loading some of the style package resources fails, the load request proceeds trying to load the remaining style package resources.

By default, users may download up to 750 tile packs for offline use across all regions. If the limit is hit, any loadRegion call will fail until excess regions are deleted. This limit is subject to change. Please contact Mapbox if you require a higher limit. Additional charges may apply.

Implementation

Future<StylePack> loadStylePack(
    String styleURI,
    StylePackLoadOptions loadOptions,
    OnStylePackLoadProgressListener? progressListener) async {
  if (progressListener != null) {
    await _api.addStylePackLoadProgressListener(styleURI);
    final eventChannel = EventChannel(
        "com.mapbox.maps.flutter/${_messageChannel}/${styleURI}");
    eventChannel.receiveBroadcastStream().listen((event) {
      progressListener(StylePackLoadProgress.decode(event));
    });
  }
  return _api.loadStylePack(styleURI, loadOptions);
}