Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility of tiles caching #276

Closed
MichalMisiaszek opened this issue May 11, 2019 · 10 comments
Closed

Possibility of tiles caching #276

MichalMisiaszek opened this issue May 11, 2019 · 10 comments

Comments

@MichalMisiaszek
Copy link

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 !

@johnpryan
Copy link
Collaborator

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 #279 to track.

Thanks for the feedback! Let me know if I'm misunderstanding

@MichalMisiaszek
Copy link
Author

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 ?

@johnpryan
Copy link
Collaborator

johnpryan commented May 17, 2019

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

@MichalMisiaszek
Copy link
Author

Understood. I guess I would need to dig into it.

@MichalMisiaszek
Copy link
Author

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.

@aytunch
Copy link
Contributor

aytunch commented May 17, 2019

@MichalMisiaszek What is the default expiration for tile images in the current implementation with cached network image?

@MichalMisiaszek
Copy link
Author

MichalMisiaszek commented May 17, 2019

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.

@aytunch
Copy link
Contributor

aytunch commented May 17, 2019

@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.

@MichalMisiaszek
Copy link
Author

Yes, I plan to make it work and then will share here.

@JaffaKetchup
Copy link
Member

Hello,
I wanted to add to this issue and the last comment with this pull request and fork that I made: #798

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants