getImageWithCancelLoadingSupport method
- TileCoordinates coordinates,
- TileLayer options,
- Future<
void> cancelLoading
Retrieve a tile as an image, based on its coordinates and the TileLayer
For this method to be called instead of getImage
, supportsCancelLoading
must be overriden to true
.
Usually redirects to a custom ImageProvider, with one parameter using
getTileUrl
, and one using cancelLoading
.
For many implementations, this is the only method that will need implementing.
Supports cancelling loading tiles, which is designed to allow for implementations that can cancel HTTP requests or other processing in-flight, when the underlying tile is disposed before it is loaded. This may increase performance, and may decrease unnecessary tile requests. Note that this only applies to the web platform.
The cancelLoading
future will complete when the underlying tile is
disposed/pruned. The implementation should therefore listen for its
completion, then cancel the loading. If an image Codec is required,
decode transparentImage
- it will never be visible anyway. Note that
cancelLoading
will always be completed on disposal, even if the tile has
been fully loaded, but this side effect is not usually an issue.
See this example with 'package:dio's CancelToken
:
final cancelToken = CancelToken();
cancelLoading.then((_) => cancelToken.cancel());
Implementation
ImageProvider getImageWithCancelLoadingSupport(
TileCoordinates coordinates,
TileLayer options,
Future<void> cancelLoading,
) {
throw UnimplementedError(
'A `TileProvider` that overrides `supportsCancelLoading` to `true` must '
'override `getImageWithCancelLoadingSupport`',
);
}