mbtiles
Mapbox MBTiles v1.3 files, support for vector and raster tiles.
- Supported raster tiles:
jpg
,png
,webp
- Supported vector tiles:
pbf
- Web is not supported because of its missing support for SQLite.
Getting started
pubspec.yaml
dependencies:
# this package:
mbtiles: ^0.4.0
# coordinates will be returned as `LatLng`, include the following package
# if you want to work with them.
latlong2: ^0.9.0
# sqlite libraries (in case not otherwise bundled)
sqlite3_flutter_libs: ^0.5.18
Usage
This package has by design no flutter dependency to be able to use it in dart programs. Please refer to the flutter instructions if you want to use it in a flutter app and dart-only instructions to use it in pure dart.
flutter
- Ensure that you have added the
sqlite3_flutter_libs
package as a dependency if you don't provide the sqlite3 libraries otherwise. - Open your .mbtiles file.
- It is recommended to store the mbtiles file in one of the directories provided by path_provider.
- The mbtiles file cannot be opened if it is inside your flutter assets! Copy it to your file system first.
- If you want to open the file from the internal device storage or SD card, you need to ask for permission first! You can use permission_handler to request the needed permission from the user.
// open as read-only
final mbtiles = MBTiles(
mbtilesPath: 'path/to/your/mbtiles-file.mbtiles',
);
// open as writeable database
final mbtiles = MBTiles(
mbtilesPath: 'path/to/your/file.mbtiles',
editable: true,
);
- Afterward you can request tiles, read the metadata, etc.
// get metadata
final metadata = mbtiles.getMetadata();
// get tile data
final tile = mbtiles.getTile(z: 0, x: 0, y: 0);
- After you don't need the mbtiles file anymore, close its sqlite database connection.
void closeMbTiles() {
mbtiles.dispose();
}
dart-only
- Open the mbtiles database. You need to provide the dart program with platform specific sqlite3 libraries. Builds are available on www.sqlite.org
final mbtiles = MBTiles(
mbtilesPath: 'path/to/your/mbtiles-file.mbtiles',
sqlitePath: 'path/to/sqlite3',
);
- Afterward you can request tiles, read the metadata, etc.
// get metadata
final metadata = mbtiles.getMetadata();
// get tile data
final tile = mbtiles.getTile(z: 0, x: 0, y: 0);
- After you don't need the mbtiles file anymore, close its sqlite database connection.
void closeMbTiles() {
mbtiles.dispose();
}
See the example program for more information.