CancellableNetworkTileProvider class

TileProvider that fetches tiles from the network, with the capability to cancel unnecessary HTTP tile requests

Tiles that are removed/pruned before they are fully loaded do not need to complete (down)loading, and therefore do not need to complete the HTTP interaction. Cancelling these unnecessary tile requests early could:

  • Reduce tile loading durations (particularly on the web)
  • Reduce users' (cellular) data and cache space consumption
  • Reduce costly tile requests to tile servers*
  • Improve performance by reducing CPU and IO work

This provider uses 'dio', which supports aborting unnecessary HTTP requests in-flight, after they have already been sent.

Although HTTP request abortion is supported on all platforms, it is especially useful on the web - and therefore recommended for web apps. This is because the web platform has a limited number of simulatous HTTP requests, and so closing the requests allows new requests to be made for new tiles. On other platforms, the other benefits may still occur, but may not be as visible as on the web.

Once HTTP request abortion is added to Dart's 'native' 'http' package (which already has a PR opened), NetworkTileProvider will be updated to take advantage of it, replacing and deprecating this provider. This tile provider is currently a seperate package and not the default due to the reliance on the additional Dio dependency.


On the web, the 'User-Agent' header cannot be changed as specified in TileLayer.tileProvider's documentation, due to a Dart/browser limitation.

Constructors

CancellableNetworkTileProvider({Map<String, String>? headers})
Create a CancellableNetworkTileProvider to fetch tiles from the network, with cancellation support

Properties

hashCode int
The hash code for this object.
no setterinherited
headers Map<String, String>
Custom HTTP headers that may be sent with each tile request
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
supportsCancelLoading bool
Indicates to flutter_map internals whether to call getImage (when false) or getImageWithCancelLoadingSupport
no setter

Methods

dispose() → void
Called when the TileLayer is disposed
generateReplacementMap(String urlTemplate, TileCoordinates coordinates, TileLayer options) Map<String, String>
Generate the Map of placeholders to replacements, to be used in populateTemplatePlaceholders
inherited
getImage(TileCoordinates coordinates, TileLayer options) ImageProvider<Object>
Retrieve a tile as an image, based on its coordinates and the TileLayer
inherited
getImageWithCancelLoadingSupport(TileCoordinates coordinates, TileLayer options, Future<void> cancelLoading) ImageProvider<Object>
Retrieve a tile as an image, based on its coordinates and the TileLayer
getTileFallbackUrl(TileCoordinates coordinates, TileLayer options) String?
Generate a fallback URL for a tile, based on its coordinates and the TileLayer
inherited
getTileUrl(TileCoordinates coordinates, TileLayer options) String
Generate a primary URL for a tile, based on its coordinates and the TileLayer
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
populateTemplatePlaceholders(String urlTemplate, TileCoordinates coordinates, TileLayer options) String
Replaces placeholders in the form templatePlaceholderElement with their corresponding values
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited