Hello,
Thank you for great plugin, I am build app in Flutter with heavy use of map and choose flutter_map over official plugin for many reasons. My users will use map in the range of connection/wifi but then go out where connection is poor or at all.
Is it possible to cache tiles downloaded before ? Like user looked at map already and we keep this tile on device for some time (with expiry) or until next possibility to download ?
BTW. OpenMaps are very often failing to download before timeout rising exception.
Thanks again !
The API allows for custom implementations of TileProvider now. By default, it uses a CachedNetworkTileProvider that wraps a CachedNetworkImageProvider which will cache images in memory.
If you are looking to cache images on disk you could look at implementing your own but you run the risk of storing a lot of tiles on the device. I created https://github.com/johnpryan/flutter_map/issues/279 to track.
Thanks for the feedback! Let me know if I'm misunderstanding
Thanks, that's what I was looking for. My problem is that user might be in poor connection area.
If I have cache of tiles I could use them. Each user will be mostly interested in his area, and cache could be regularly swept for not user tiles ? I think CachedNetworkImageProvider do not work well when connection is slow or broken ?
Yes, this would probably require some design around how to best cache the tiles, so I'd rather leave it up to the user to implement as a custom TileProvider
Understood. I guess I would need to dig into it.
Seems like using https://github.com/renefloor/flutter_cached_network_image and then https://pub.dev/packages/flutter_cache_manager allows for customization of cache in terms of duration, size etc.
@MichalMisiaszek What is the default expiration for tile images in the current implementation with cached network image?
According to code 30 days ?
BaseCacheManager(this._cacheKey,
{maxAgeCacheObject = const Duration(days: 30),
maxNrOfCacheObjects = 200,
FileFetcher fileFetcher}) {
_fileBasePath = getFilePath();
_maxAgeCacheObject = maxAgeCacheObject;
_maxNrOfCacheObjects = maxNrOfCacheObjects;
store = new CacheStore(
_fileBasePath, _cacheKey, _maxNrOfCacheObjects, _maxAgeCacheObject);
webHelper = new WebHelper(store, fileFetcher);
}
But it is stored in temporary not app directory so OS might be removing faster. I will keep it app storage.
@MichalMisiaszek When you accomplish saving the tiles in app storage, can you please share it here? It would be a great enhancement for the end users data plans:) Also it would be perfect to have the ability to show tiles from app storage only if network is slow.
Yes, I plan to make it work and then will share here.
Most helpful comment
Yes, I plan to make it work and then will share here.