From 3b7e2795c4b499afb00a3a3cd3d3ad3a312c3432 Mon Sep 17 00:00:00 2001 From: Alfanhui Date: Thu, 7 Jun 2018 17:41:09 +0100 Subject: [PATCH] Added OfflineMode bool variable to TileLayerOptions, if true, image uses AssetImage(), if false (default) image uses NetworkImage(). Note: Only the master build of flutter enables pubspec to look in asset directories, else pubspec will require direct paths to all map images. To get offline maps tiles, see here: https://github.com/alfanhui/mbtilesToPngs --- flutter_map/lib/src/layer/tile_layer.dart | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/flutter_map/lib/src/layer/tile_layer.dart b/flutter_map/lib/src/layer/tile_layer.dart index ed5487e9b..b7a6d542a 100644 --- a/flutter_map/lib/src/layer/tile_layer.dart +++ b/flutter_map/lib/src/layer/tile_layer.dart @@ -20,6 +20,7 @@ class TileLayerOptions extends LayerOptions { final double zoomOffset; final List subdomains; final Color backgroundColor; + final bool offlineMode; /// When panning the map, keep this many rows and columns of tiles before /// unloading them. @@ -38,6 +39,7 @@ class TileLayerOptions extends LayerOptions { this.keepBuffer = 2, this.backgroundColor = const Color(0xFFE0E0E0), // grey[300] this.placeholderImage, + this.offlineMode = false, }); } @@ -374,7 +376,9 @@ class _TileLayerState extends State { placeholder: options.placeholderImage != null ? options.placeholderImage : new MemoryImage(kTransparentImage), - image: new NetworkImage(getTileUrl(coords)), + image: options.offlineMode == true + ? new AssetImage(getTileUrl(coords)) + : new NetworkImage(getTileUrl(coords)), fit: BoxFit.fill, ), ),