loadTileRegion method

Future<TileRegion> loadTileRegion(
  1. String id,
  2. TileRegionLoadOptions loadOptions,
  3. OnTileRegionLoadProgressListener? progressListener
)

Loads a new tile region or updates the existing one.

@param id: The tile region identifier. @param loadOptions: The tile region load options. @param progressListener: Invokes when loading progress is updated.

Creating of a new region requires providing both geometry and tileset descriptors to the given load options, otherwise the load request fails with RegionNotFound error.

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

If there are no values provided to the given load options, the existing tile region gets refreshed: the missing resources get loaded and the expired resources get updated.

A failed load request can be re-attempted with another TileStore.loadTileRegion call.

If there is already a pending loading operation for the tile region with the given id, the pending loading operation will fail with an error of Canceled type.

  • Note: The user-provided callbacks will be executed on a TileStore-controlled worker thread; it is the responsibility of the user to dispatch to a user-controlled thread.

  • Important: 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<TileRegion> loadTileRegion(
    String id,
    TileRegionLoadOptions loadOptions,
    OnTileRegionLoadProgressListener? progressListener) async {
  if (progressListener != null) {
    await _api.addTileRegionLoadProgressListener(id);
    final eventChannel = EventChannel(
        "com.mapbox.maps.flutter/${_messageChannel}/tile-region-${id}");
    eventChannel.receiveBroadcastStream().listen((event) {
      progressListener(TileRegionLoadProgress.decode(event));
    });
  }
  return _api.loadTileRegion(id, loadOptions);
}