-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add mbtiles tile provider for flutter_map (#21)
* add flutter_map_mbtiles package * add files * fix errors * update example page * add doc strings * mbtiles example: support for non desktop plattforms * update readme files * disabled banner for example app * add tests * don't expose the mbtiles package * add `silenceTileNotFound` parameter * bump dependencies - mbtiles - codecov workflow * add examples, sort example cards alphabetically * add `silenceTileNotFound` param, only dispose if created internally * fix example * disable vector_map_tiles_pmtiles on web vector_map_tiles is not compatible with web * small fixes in docs, examples and tests * more fixes in docs * update vector_map_tiles_mbtiles * add flutter_map_mbtiles * remove vector_map_tiles_mbtiles * Update main.dart * Update pubspec.yaml * score packages one by one * fix git url * mbtiles ^0.3.1
- Loading branch information
Showing
26 changed files
with
665 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:flutter/services.dart'; | ||
import 'package:path_provider/path_provider.dart'; | ||
|
||
/// This function copies an asset file from the asset bundle to the temporary | ||
/// app directory. | ||
/// | ||
/// **It is not recommended to use this in production and for larger files.** | ||
/// Instead download your files from a web server or s3 storage. | ||
Future<File> copyAssetToFile(String assetFile) async { | ||
final tempDir = await getTemporaryDirectory(); | ||
final filename = assetFile.split('/').last; | ||
final file = File('${tempDir.path}/$filename'); | ||
|
||
final data = await rootBundle.load(assetFile); | ||
await file.writeAsBytes( | ||
data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes), | ||
flush: true, | ||
); | ||
return file; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_map/flutter_map.dart'; | ||
import 'package:flutter_map_mbtiles/flutter_map_mbtiles.dart'; | ||
import 'package:flutter_map_plugins_example/common/utils.dart'; | ||
import 'package:latlong2/latlong.dart'; | ||
import 'package:mbtiles/mbtiles.dart'; | ||
|
||
class FlutterMapMbTilesPage extends StatefulWidget { | ||
const FlutterMapMbTilesPage({super.key}); | ||
|
||
@override | ||
State<FlutterMapMbTilesPage> createState() => _FlutterMapMbTilesPageState(); | ||
} | ||
|
||
class _FlutterMapMbTilesPageState extends State<FlutterMapMbTilesPage> { | ||
final Future<MbTiles> _futureMbtiles = _initMbtiles(); | ||
MbTiles? _mbtiles; | ||
|
||
static Future<MbTiles> _initMbtiles() async { | ||
// This function copies an asset file from the asset bundle to the temporary | ||
// app directory. | ||
// It is not recommended to use this in production. Instead download your | ||
// mbtiles file from a web server or object storage. | ||
final file = await copyAssetToFile( | ||
'assets/mbtiles/countries-raster.mbtiles', | ||
); | ||
return MbTiles(mbtilesPath: file.path); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
backgroundColor: Colors.white, | ||
title: const Text('flutter_map_mbtiles'), | ||
), | ||
body: FutureBuilder<MbTiles>( | ||
future: _futureMbtiles, | ||
builder: (context, snapshot) { | ||
if (snapshot.hasData) { | ||
_mbtiles = snapshot.data; | ||
final metadata = _mbtiles!.getMetadata(); | ||
return Column( | ||
children: <Widget>[ | ||
Padding( | ||
padding: const EdgeInsets.all(12), | ||
child: Text( | ||
'MBTiles Name: ${metadata.name}, ' | ||
'Format: ${metadata.format}', | ||
), | ||
), | ||
Expanded( | ||
child: FlutterMap( | ||
options: const MapOptions( | ||
minZoom: 0, | ||
maxZoom: 6, | ||
initialZoom: 2, | ||
initialCenter: LatLng(49, 9), | ||
), | ||
children: [ | ||
TileLayer( | ||
tileProvider: MbTilesTileProvider( | ||
mbtiles: _mbtiles!, | ||
silenceTileNotFound: true, | ||
), | ||
), | ||
], | ||
), | ||
), | ||
], | ||
); | ||
} | ||
if (snapshot.hasError) { | ||
return Center(child: Text(snapshot.error.toString())); | ||
} | ||
return const Center(child: CircularProgressIndicator()); | ||
}, | ||
), | ||
); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
// close the open database connection | ||
_mbtiles?.dispose(); | ||
super.dispose(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## [1.0.0] 2024-mm-dd | ||
|
||
- Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Joscha Eckert (josxha) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
Oops, something went wrong.