getTileImage method
Future<Uint8List?>
getTileImage(
- TileCoordinates coords,
- TileLayer options
)
Implementation
Future<Uint8List?> getTileImage(
TileCoordinates coords, TileLayer options) async {
final int zoom = coords.z.toInt();
final int x = coords.x.toInt();
final int y = coords.y.toInt();
final String tileKey = "$zoom/$x/$y.png";
final String cachePath = await _getCachePath(tileKey);
final File cacheFile = File(cachePath);
if (await cacheFile.exists()) {
return await cacheFile.readAsBytes();
} else {
final Uint8List? bytes = await _fetchTileImage(coords, options);
if (bytes != null) {
await cacheFile.create(recursive: true);
await cacheFile.writeAsBytes(bytes);
return bytes;
} else {
return null;
}
}
}