vector_map_tiles_mbtiles
A TileProvider for flutter_map that adds support for MBTiles.
- Supported vector tile format:
pbf
(sometimes known asmvt
) - If you have raster tiles you can use flutter_map_mbtiles.
- Web is not supported because of it's lacking SQLite support.
Getting started
Add the following packages to your pubspec.yaml
file:
dependencies:
flutter_map: ^6.0.0 # in case you don't have it yet
vector_map_tiles_mbtiles: ^1.0.0 # this package
mbtiles: ^0.4.0 # MBTiles package
Usage
- Open the MBTiles file
The MBTiles file must be stored on the file system and read permission must be granted to the app.
You can use the path_provider package to get the path of the app document directory.
// initiate your tile provider
final mbtiles = MbTiles(mbtilesPath: mbTilesPath, gzip: false);
// OR: in case your protobuf data is not gzip encoded use:
final mbtiles = MbTiles(mbtilesPath: mbTilesPath, gzip: false);
- Provide mbtiles to the
MbTilesVectorTileProvider
:
@override
Widget build(BuildContext context) {
return FlutterMap(
options: MapOptions(
minZoom: 8,
maxZoom: 18,
initialZoom: 11,
initialCenter:
metadata.defaultCenter ?? const LatLng(0, 0),
),
children: [
VectorTileLayer(
theme: _theme,
tileProviders: TileProviders({
'openmaptiles': MbTilesVectorTileProvider(
mbtiles: mbtiles,
silenceTileNotFound: true,
),
}),
// do not set maximumZoom here to the metadata.maxZoom
// or tiles won't get over-zoomed.
maximumZoom: 18,
),
],
);
}
Additional information
If you need help you
can open an issue
or join
the flutter_map
discord server.