-
-
Notifications
You must be signed in to change notification settings - Fork 893
Closed as not planned
Labels
invalidThis bug isn't reproducible, or the feature already existsThis bug isn't reproducible, or the feature already exists
Description
Please I need someone to help me out. I have been trying to load mbtiles on the map but to no avail. I actually can't figure out my mistake. i diclared var mbtiles.
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
// import 'package:flutter_map_mbtiles/flutter_map_mbtiles.dart';
import 'package:latlong2/latlong.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:flutter_map_mbtiles/flutter_map_mbtiles.dart';
import 'package:file_picker/file_picker.dart';
import 'dart:async';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MapScreen(),
);
}
}
class MapScreen extends StatefulWidget {
@override
_MapScreenState createState() => _MapScreenState();
}
class _MapScreenState extends State<MapScreen> {
var mbtiles;
// var mbtiles;
Future<void> pickMBTiles() async {
FilePickerResult? result = await FilePicker.platform.pickFiles(type: FileType.any);
if (result != null && result.files.single.path != null) {
final path = result.files.single.path!;
final loadedMbTiles = await mbtiles.open(path);
setState(() {
mbtiles = loadedMbTiles;
});
}else{
print("Failed to load MBTiles.");
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Flutter Map with MBTiles'),
actions: [
IconButton(
icon: Icon(Icons.folder_open),
onPressed: pickMBTiles,
),
],
),
body: FlutterMap(
options: MapOptions(
initialCenter: LatLng(43.724049, -79.511818),
initialZoom: 14.2,
),
children: [
if (mbtiles != null)
TileLayer(
tileProvider: MbTilesTileProvider(
silenceTileNotFound: !kDebugMode,
mbtiles: mbtiles!,
),
)
else
TileLayer(
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
userAgentPackageName: 'com.example.app',
),
RichAttributionWidget(
attributions: [
TextSourceAttribution(
'OpenStreetMap contributors',
onTap: () => launchUrl(Uri.parse('https://openstreetmap.org/copyright')),
),
],
),
],
),
);
}
}
Metadata
Metadata
Assignees
Labels
invalidThis bug isn't reproducible, or the feature already existsThis bug isn't reproducible, or the feature already exists