The basis of any map is a TileLayer
, which displays square raster images in a continuous grid, sourced from the Internet or a local file system.
flutter_map supports WMS Usage, but most map tiles are accessed through the CARTO/XYZ/Slippy Map standard, where the mapping library (flutter_map) fills in XYZ placeholders in a URL.
You must comply to your tile server's ToS. Failure to do so may result in you being banned from their services.
The OpenStreetMap Tile Server (as used above) can be found here. Other servers may have different terms.
This package is not responsible for your misuse of any tile server.
It is possible to use more than one tile layer, and can be used with transparency/opacity.
The children
list works like the children of a Stack
: last is on top.
Need more control over the source of tiles, or how tiles are fetched? You'll need to change the TileProvider
.
userAgentPackageName
Always specify the userAgentPackageName
argument to avoid being blocked by your tile server.
It should be passed the application's package name, such as 'com.example.app'. This is important to avoid blocking by tile servers due to high-levels of unidentified traffic. If no value is passed, it defaults to 'unknown'.
This is passed through to the NetworkTileProvider
(if in use) in a suitably formatted string, where it forms the 'User-Agent' header, overriding any custom user agent specified in the HTTP client.
To override this behaviour, specify a 'User-Agent' key in the NetworkTileProvider
.headers
property.
This is all ignored on the web, where the 'User-Agent' header cannot be changed due to a limitation of Dart/browsers.
The tileProvider
parameter in TileLayer
takes a TileProvider
object specifying a tile provider to use for that layer.
This has a default of NetworkTileProvider
which gets tiles from the internet through a dedicated image provider.
There's two situations in which you'll need to change the tile provider:
Sourcing tiles from the filesystem or asset store: #local-tile-providers
Using a plugin that instructs you to do so (Creating New Tile Providers)
NetworkTileProvider
takes two arguments, but you'll usually never need to specify them:
httpClient
: custom BaseClient
By default, a RetryClient
backed by a standard Client
is used
headers
: custom Map<String, String>
By default, only the default headers, plus a custom 'User-Agent' header based on the #useragentpackagename property, are included with each request
These tile providers use the templateUrl
to get the appropriate tile from the asset store of the application, or from a file on the users device, respectively.
Specifying any fallbackUrl
(even if it is not used) in the TileLayer
will reduce the performance of these providers.
It will cause 23% slower asset tile requests with AssetTileProvider
, and will cause main thread blocking when requesting tiles from FileTileProvider
.
AssetTileProvider
This tile providers uses the templateUrl
to get the appropriate tile from the asset store of the application.
FileTileProvider
This tile providers uses the templateUrl
to get the appropriate tile from the a path/directory/file on the user's device - either internal application storage or external storage.
On the web, FileTileProvider()
will throw an UnsupportedError
when a tile request is attempted, due to the lack of the web platform's access to the local filesystem.
If you know you are running on the web platform, use a NetworkTileProvider
or a custom tile provider.