TileLayer
Displays square raster images in a continuous grid,
sourced from the provided url_template and fallback_url.
Typically, the first layer to be added to a Map,
as it provides the tiles on which other layers are displayed.
This control supports basic map tile caching (for compatible tile providers). On non-web platforms, built-in caching is automatically enabled with a default soft limit of 1 GB. On web platforms, caching is typically handled by the browser.
No guarantees are provided regarding the persistence or reliability of cached tiles. Cached data may become unavailable or be cleared at any time. For example, do not rely on this caching mechanism in scenarios where missing tiles could create risk or unsafe conditions (for example, offline or safety-critical mapping applications).
It aims to:
Improve developer experience by:
- Reducing the costs of using tile servers by reducing duplicate tile requests
- Keep your app lightweight - the built-in cache doesn't ship any binaries or databases, just a couple extra libraries you probably already use
Improve user experience by:
- Reducing tile loading durations, as fetching from the cache is very quick
- Reducing network/Internet usage, which may be limited or metered/expensive (eg. mobile broadband)
- Improve compliance with tile server requirements, by reducing the strain on them
- Be extensible, customizable, and integrate with multiple tile providers
But it comes at the expense of usage of on-device storage capacity.
flet-map doesn't provide tiles, so you'll need to bring your own raster tiles. There are multiple different supported sources.
- Slippy Map/CARTO (XYZ): This is the most common format for raster tiles,
although many satellite tiles will instead use WMS.
Typically, a URL with placeholders for X, Y, and Z values. Set the
url_templateto the template provided by the tile server - usually it can be copied directly from an account portal or documentation. Additional information, like API/access keys, can be passed in using theadditional_optionsproperty. It's also possible to specify afallback_urltemplate, used if fetching a tile from the primaryurl_templatefails. - Tile Map Service (TMS): This is also supported. Follow the instructions for
the XYZ source above, then set the
enable_tmsproperty toTrue. Read more on WMS here. - Web Map Services (WMS): This is also supported. Use
wms_configurationto specify the necessary configuration for WMS tile servers. Read more on WMS here.
Example:
ftm.TileLayer(
url_template="https://tile.openstreetmap.org/{z}/{x}/{y}.png",
user_agent_package_name="MyTownMaps/1.4 (+https://example.org; contact: maps@example.org)",
)
Inherits: MapLayer
Properties
additional_options- Static information that should replace placeholders in theurl_template.display_mode- Defines how tiles are displayed on the map.enable_retina_mode- Whether to enable retina mode.enable_tms- Whether to inverse Y-axis numbering for tiles.error_image_src- The source of the tile image to show in place of the tile that failed to load.evict_error_tile_strategy- If a tile was loaded with error, the tile provider will be asked to evict the image based on this strategy.fallback_url- Fallback URL template used if fetching tiles fromurl_templatefails.keep_buffer- When panning the map, keep this many rows and columns of tiles before unloading them.max_native_zoom- Maximum zoom number supported by the tile source has available.max_zoom- The maximum zoom level up to which this layer will be displayed (inclusive).min_native_zoom- Minimum zoom level supported by the tile source.min_zoom- The minimum zoom level at which this layer is displayed (inclusive).pan_buffer- When loading tiles only visible tiles are loaded by default.subdomains- List of subdomains used in the URL template.tile_bounds- Defines the bounds of the map.tile_size- The size in pixels of each tile image.url_template- The URL template is a string that contains placeholders, which, when filled in, create a URL/URI to a specific tile.user_agent_package_name- The package name of the user agent to use when fetching tiles from the tile server.wms_configuration- The configuration for WMS tile servers.zoom_offset- The zoom number used in tile URLs will be offset with this value.zoom_reverse- Whether the zoom number used in tile URLs will be reversed (max_zoom - zoominstead ofzoom).
Events
on_image_error- Fires if an error occurs when fetching the tiles.