Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
As briefly described in #map-widget, the children
property takes a list of Widget
s, which will be stacked on top of each other (last on top). These can be any Widget
, such as a FutureBuilder
or StreamBuilder
, but are usually Layer
s which are provided by this library or plugins.
There is also the nonRotatedChildren
property, which work similarly as their 'rotatable' counterpart, but - as the name suggests - do not get rotated as the map gets rotated. For example, the AttributionWidget
should be used inside nonRotatedChildren
instead of children
, as it needs to remain vertical and therefore readable.
As a minimum, all maps should have a Tile Layer, as this is what actually displays any map. Other layers are available, such as markers/waypoints and lines.
You can add polygons to maps to display shapes made out of points to users using PolygonLayer()
.
Due to the nature of the Earth being a sphere, drawing lines perfectly requires large amounts of difficult maths that may not behave correctly when given certain edge-cases.
Avoid creating large polygons, or polygons that cross the edges of the map, as this may create undesired results.
Excessive use of polygons or use of complex polygons will create performance issues and lag/'jank' as the user interacts with the map. See for more information.
To improve performance, try enabling polygonCulling
. This will prevent the calculation and rendering of polygons outside of the current viewport, however this may not work as expected in all situations.
polygons
)As you can see PolygonLayerOptions()
accepts list of Polygon
s. Each determines the shape of a polygon by defining the LatLng
of each corner. 'flutter_map' will then draw a line between each coordinate, and fill it.
'flutter_map' doesn't provide any public methods to manipulate polygons, as these would be deemed out of scope.
However, some useful methods can be found in libraries such as 'latlong2' and 'poly_bool_dart'. These can be applied to the input of Polygon
's points
argument, and the map will do it's best to try to render them. However, more complex polygons - such as those with holes - may be painted inaccurately, and may therefore require manual adjustment (of holePointsList
, for example).
You can add markers to maps to display specific points to users using MarkerLayer()
.
Excessive use of markers or use of complex markers will create performance issues and lag/'jank' as the user interacts with the map. See for more information.
If you need to use a large number of markers, an existing might help.
markers
)As you can see MarkerLayerOptions()
accepts list of Markers which determines render widget, position and transformation details like size and rotation.
This page (and subpages) only talks about WMTS-supporting raster layers, which is the most common and default type of mapping.
For information about WMS-supporting layers or vector tiles, visit the page.
A tile layer displays raster map tiles in a grid pattern, from a tile source such as a remote server or file system. This might look something like this:
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 . Other servers may have different terms.
This package is not responsible for your misuse of another tile server.
Visit the Full API Reference for the full list of available options
subdomains
)Takes a list of strings specifying the available subdomains. For example:
One will be chosen differently every request by the tile provider to replace the '{s}' part of the urlTemplate
.
If you are not sure of the correct values for your server, don't specify anything. For example, the urlTemplate
used in the example above will work without the '{s}' part and any subdomains specified.
This option is no longer recommended in many cases, and it can be detrimental to performance in some cases.
Major servers - such as OpenStreetMap's - support HTTP/2 & HTTP/3, which don't require subdomain aliases to increase browser connection concurrency. Using a single URL improves performance and ability to cache. For more information, see .
Other servers may still use these subdomains to bypass browser connection concurrency and perform load balancing, in which case, this property is recommended.
tileBounds
)Takes a LatLngBounds
to restrict the layer to only loading tiles within that area. For example:
will restrict the tiles to only loading Egypt (a square-ish country). Note that the map can still be moved freely outside of this range.
An example use-case might therefore be loading a specialised map for a region and just a basic map style elsewhere (different urlTemplate
s). In this case, the bounded layer should go beneath the unbounded layer. Setting backgroundColor: Colors.transparent
is also necessary on the bounded layer to ensure the other layer is visible elsewhere.
errorImage
)will use a sea tile on every tile that cannot be fetched.
This is an optional parameter that has no default. If this is not specified, and tiles are unable to be fetched, then the background color.
tileSize
)Takes a double
number specifying the width and height (in pixels) of each tile. As tiles are always square, only one number is needed.
This defaults to 256, as most tile servers serve 256x256px tiles.
tileBuilder
)Takes a callback function, in the format Widget Function(BuildContext context, Widget tileWidget, Tile tile)
. For example:
will show the tile's coordinate on the tile.
There is also tilesContainerBuilder
available, which works slightly differently, but is recommended when the same builder can be used on every tile, for performance reasons.
There are predefined tile builders available, such as a dark mode emulator and a loading time debugger.
reset
)This option is significantly less important and useful after v3.0.0. Please consider updating to that version or later.
Takes a Stream<void>?
, that causes the layer to 'reset' when an event is received. This might be necessary after updating the templateUrl
. For example:
urlTemplate
)This parameter is not strictly required, but the map is essentially useless without it specified with a valid URL.
Takes a string that is a valid URL, which is the template to use when the tile provider constructs the URL to request a tile from a tile server. For example:
will use the OpenStreetMap Tile Server.
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 . Other servers may have different terms.
This package is not responsible for your misuse of another tile server.
The '{s}', '{z}', '{x}' & '{y}' parts indicate where to place the subdomain, zoom level, x coordinate, and y coordinate respectively. Not providing at least the latter 3 parts won't necessarily throw an error, but the map won't show anything.
userAgentPackageName
)Takes a String
, which should be the unique package name (eg. com.example.app). For example:
This string is used to construct a 'User-Agent' header, sent with all tile requests (on platforms other than the web, due to Dart limitations), necessary to prevent blocking by tile servers.
Constructed agents are in the format: 'flutter_map (packageName)'. If the package name is not specified, 'unknown' is used in place.
Although it is not required, not specifying the correct package name will/may group your applications traffic with other application's traffic. If the total traffic exceeds the server's limits, they may choose to block all traffic with that agent, leading to a 403 HTTP error.
tileProvider
)For more information, see:
retinaMode
)If true
, the providers should request four tiles of half the specified size and a bigger zoom level in place of one to utilize the high resolution. In this case, you should set MapOptions
's maxZoom
should be maxZoom - 1
instead.
For example, this is the recommended setup:
You can add lines to maps to display paths/ways made out of points to users using PolylineLayer()
.
Due to the nature of the Earth being a sphere, drawing lines perfectly requires large amounts of difficult maths that may not behave correctly when given certain edge-cases.
Avoid creating large polylines, or polylines that cross the edges of the map, as this may create undesired results.
Excessive use of polylines or use of complex polylines will create performance issues and lag/'jank' as the user interacts with the map. See for more information.
You can try the below methods to try to reduce the lag:
Keep saveLayers
set to false
(which is default). This will reduce rendering times, however it will also reduce the visual quality of the line at intersections.
Enable polylineCulling
. This will prevent the calculation and rendering of lines outside of the current viewport, however this may not work as expected in all situations.
Simplify the polyline by reducing the number of points within it. This will reduce calculation times, however it will make the line less precise. This is recommended, for example, when zoomed further out. You may be able to use an external Flutter library for this, called .
polylines
)As you can see PolylineLayerOptions()
accepts list of Polyline
s. Each determines the shape of a polyline by defining the LatLng
of each point. 'flutter_map' will then draw a line between each coordinate.
You may have a polyline with 'Google Polyline Encoding' (which is a lossy compression algorithm to convert coordinates into a string and back). These are often returned from routing engines, for example. In this case, you'll need to decode the polyline to the correct format first, before you can use it in a Polyline
's points
argument.
You can then use the package and the above snippet by doing:
... and Offline Mapping
The tileProvider
parameter in TileLayer
takes a TileProvider
object specifying a to use for that layer.
This has a default of NetworkNoRetryTileProvider
, which is recommended for most setups for better performance, unless your tile server is especially unreliable, or you need a local tile provider.
Custom TileProvider
s can be implemented by your application or other libraries. These may not conform to the usual rules above, and may additionally have their own parameters.
Network tile providers can take a Map<String, String>
of custom headers. Note that the that is automatically generated will not override any 'User-Agent' header if specified here. On the web, the 'User-Agent' header is not sent, as the browser controls the user agent.
Whilst not on the web, network tile providers can take a custom HttpClient
/RetryClient
, if you need to use it for whatever reason.
NetworkNoRetryTileProvider()
This is the default tile provider.
This tile provider uses the templateUrl
to get the appropriate tile from the Internet, and it won't retry the request if it fails.
There is no guarantee about the default caching behaviour, but tiles should be cached until an application restart.
NetworkTileProvider()
This tile provider uses the templateUrl
to get the appropriate tile from the Internet, but it will retry the request as specified in the RetryClient
(which can be customised as needed when not on the web).
There is no guarantee about the default caching behaviour, but tiles should be cached until an application restart.
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
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 automatically use NetworkImage()
behind the scenes. This is not recommended. If you know you are running on the web platform, avoid using this tile provider.
There is essentially two options for doing this:
Using AssetTileProvider
, you can bundle a set of map tiles and register them as an asset within your app's pubspec.yaml. This means that they will be downloaded together with your application, keeping setup simple, but at the expense of a larger application bundle size.
Using FileTileProvider
, you can bundle a set of map tiles and store them on a remote web server, that can be downloaded from later. This means that the setup may be more complicated for users, but the application's bundle size will be much smaller.
Either way, the filesystem should be structured like this: 'offlineMap/{z}/{x}/{y}.png', where every .png image is a tile.
To help choose whether FMTC or DIY is more appropriate for your usecase, please see:
We're writing this documentation page now! Please hold tight for now, and refer to older documentation or look in the API Reference.
You can add circle polygons to maps to users using CircleLayer()
.
Due to the nature of the Earth being a sphere, drawing lines perfectly requires large amounts of difficult maths that may not behave correctly when given certain edge-cases.
Avoid creating large polygons, or polygons that cross the edges of the map, as this may create undesired results.
Excessive use of circles will create performance issues and lag/'jank' as the user interacts with the map. See for more information.
Property | Type | Defaults | Description |
---|---|---|---|
Property | Type | Defaults | Description |
---|
Takes an ImageProvider
, such as a NetworkImage
, to use if the tile cannot be fetched using the templateUrl
. The size of the returned image should be the same as the . For example:
A bool
flag to enable or disable (default) makeshift retina mode, recommended on supporting devices. If the tile server supports retina mode natively ('@2' tiles), you should use them instead, by including the '{r}' placeholder in the .
Property | Type | Defaults | Description |
---|
One way to accomplish this is to use another Flutter library called , together with a custom method. You can use the code snippet below, which can just be pasted into a file and imported whenever needed:
If you have a set of custom raster tiles that you need to provide to all your users, you may want to consider bundling them together, to make a them easier to deploy to your users. Note that this is different to the section below.
If you have a raster-format .mbtiles file, for example from TileMill, you should use to convert it to the correct structure first. Alternatively, you can use an external package such as '' to extract during runtime.
The provides advanced caching and bulk downloading capability, which handles many surrounding and supporting features for you and your app, with minimal implementation effort.
However, using simpler packages in a DIY solution can be a better option in some cases. You'll need to implement a custom TileProvider
backed by an alternative image provider or cache lookup system: see .
If you prefer to offer a set of map tiles to all your users before runtime, consider using the solution instead.
points
List<LatLng>
required
The coordinates of each vertex
holePointsList
List<List<LatLng>>?
The coordinates of each vertex to 'cut-out' from the shape
color
Color
Color(0xFF00FF00)
Fill color
borderStrokeWidth
double
0.0
Width of the border
borderColor
Color
Color(0xFFFFFF00)
Color of the border
disableHolesBorder
bool
false
Whether to apply the border at the edge of 'cut-outs'
isDotted
bool
false
Whether to make the border dotted/dashed instead of solid
label
String?
Text to display as label in center of polygon
labelStyle
TextStyle
TextStyle()
Custom styling to apply to the label
labelPlacement
PolygonLabelPlacement
PolygonLabelPlacement.polylabel
Where to place the label in the polygon
|
| required | Marker position on map |
|
| required | Builder used to render marker |
|
|
| Marker width |
|
|
| Marker height |
|
|
| If true, marker will be counter rotated to the map rotation |
|
| The origin of the marker in which to apply the matrix |
|
| The alignment of the origin, relative to the size of the box |
|
| Point of the marker which will correspond to marker's location |
|
| required | The coordinates of each point |
|
|
| Width of the line |
|
|
| Fill color |
|
|
| Width of the border of the line |
|
|
| Color of the border of the line |
|
| List of colors to make gradient fill instead of a solid fill |
|
| List doubles representing the percentage of where to START each gradient color along the line |
|
|
| Whether to make the line dotted/dashed instead of solid |
We're writing this documentation page now! Please hold tight for now, and refer to older documentation or look in the API Reference.
Before publishing your app to users, you should credit the tile server you use, this library, and potentially and plugins you use.
Please credit flutter_map, it helps us to gain more developers that we can help!
You should also credit your tile server if it says to in the server's terms of service. You must credit OpenStreetMap if using its tile server or another tile server that relies on its data.
The default builder, as shown above, can be used to get a classic attribution box appearance quickly without much setup. Just add a source and a function (if you want a clickable link to appear), and 'flutter_map' automatically gets credited.
Alternatively, create your own box from scratch by omitting the defaultWidget
constructor from the widget. Then you can build a custom widget as you would normally.