Unable to load pmtiles #51
-
So, here is my steps,
Requirement:
Very basic example of how I access pmtiles. I believe pmtiles are both raster and vector ? So unsure If i really need to use vector tile layer to access pmtiles with different values as shown in the screenshot above. class MainScreen extends StatefulWidget {
static const String idScreen = 'mainScreen';
const MainScreen({Key? key}) : super(key: key);
@override
_MainScreenState createState() => _MainScreenState();
}
class _MainScreenState extends State<MainScreen> {
PmTilesTileProvider? _pmTilesTileProvider;
MapController flutterMapController = MapController();
@override
void didChangeDependencies() {
super.didChangeDependencies();
}
@override
void initState() {
super.initState();
_loadPmTiles();
}
Future<void> _loadPmTiles() async {
// Copy the PMTiles file from assets to a temporary directory
final ByteData data = await rootBundle.load("assets/terrain.pmtiles");
final Uint8List bytes = data.buffer.asUint8List();
final tempDir = await getTemporaryDirectory();
final tempFile = File('${tempDir.path}/terrain.pmtiles');
await tempFile.writeAsBytes(bytes);
// Use the PmTilesTileProvider.fromSource method to load the PMTiles archive
final provider = await PmTilesTileProvider.fromSource(tempFile.path);
setState(() {
_pmTilesTileProvider = provider;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Expanded(
child: Stack(
children: [
Positioned(
top: 0,
left: 0,
child: SizedBox(
child: FlutterMap(
mapController: flutterMapController,
options: const MapOptions(
maxZoom: 11,
initialZoom: 10,
minZoom: 2,
),
children: [
TileLayer(
tileProvider: _pmTilesTileProvider,
urlTemplate: '',
),
],
),
),
),
],
),
),
],
),
);
}
} This is the metadalayer I get from https://pmtiles.io/
and this is what is shows me there I know its there but i can't find a way to access it ? Any help will do. Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Depends on your pmtiles file. Your current pmtiles format is |
Beta Was this translation helpful? Give feedback.
-
So I used your plugin to load geojson data and it works really well. There is a lag when the map is loading another set of geojson data but when fully loaded without any simplification it is really smooth. I will try to optimize the loading when ios side is stable and working. Great plugin. Screen_Recording_20241028_120010.mp4 |
Beta Was this translation helpful? Give feedback.
So I used your plugin to load geojson data and it works really well. There is a lag when the map is loading another set of geojson data but when fully loaded without any simplification it is really smooth. I will try to optimize the loading when ios side is stable and working. Great plugin.
Screen_Recording_20241028_120010.mp4