flutter_map_mbtiles 1.0.0 flutter_map_mbtiles: ^1.0.0 copied to clipboard
Mapbox MBTiles tile provider for flutter_map that can be used for a map that is 100% offline.
flutter_map_mbtiles #
Raster and Vector MBTiles TileProvider
for flutter_map.
- Supported raster tiles:
jpg
,png
,webp
- If you want to use
pbf
vector tiles you can use vector_map_tiles_mbtiles. - Web is not supported because of it's lacking SQLite support.
Getting started #
pubspec.yaml
dependencies:
flutter_map: ^6.0.0 # in case you don't have it yet
flutter_map_mbtiles: ^1.0.0 # this package
Usage #
late final MBTiles mbtiles;
@override
void initState() {
// open mbtiles
mbtiles = MBTiles(
mbtilesPath: 'assets/mbtiles/countries-raster.mbtiles',
);
super.initState();
}
@override
Widget build(BuildContext context) {
return FlutterMap(
options: MapOptions(
initialZoom: zoom,
initialCenter: center,
onPositionChanged: (position, hasGesture) {
if (position.center == null || position.zoom == null) return;
setState(() {
center = position.center!;
zoom = position.zoom!;
});
},
minZoom: 0,
maxZoom: 6,
),
children: [
TileLayer(
tileProvider: MBTilesTileProvider(
mbtiles: mbtiles,
),
),
],
);
}
@override
void dispose() {
// close mbtiles
mbtiles.dispose();
super.dispose();
}