flutter_map_tile_caching
flutter_map_tile_caching copied to clipboard
[BUG] `checkTileCached` method appears broken
What do you want implemented?
Download cached map tiles as image file permanently, so that i can use map when offline.
What other alternatives are available?
No response
Can you provide any other information?
No response
Platforms Affected
Android
Severity
Annoying: Currently have to use workarounds
Requirements
- [X] I agree to follow this project's Code of Conduct
- [X] I am using the latest stable version of this package
- [X] I have checked for similar feature requests which may be duplicates
Hi there @caini1213,
You've exactly described the whole purpose of this library. Can you be more specific about what you need implementing, or what you need help with?
Hi, there
I would like to store the tiles permanently as image file instead of caching it in url, and I saw u had raised some issues about this features at "https://github.com/fleaflet/flutter_map/issues/795", by using network_to_file_image library. So would like to ask that had u solves or implemented this features in ur library? Would u mind to share it? Tq
@caini1213 This library does exactly that. It stores each tile as an image on the user's device. It is both more reliable and safer than traditional caching, for reasons I won't go into now, but this library still maintains the name caching, because it technically is.
Note that a completely custom implementation is used here: it does not use the library mentioned in that thread.
How to get the image file (png / jpg) of the cached tile?
Can I ask why you need to do that?
As I noticed, there is a limited cached duration but store the tile permanently would be better.
If you read the documentation on that property, you can find how to turn it off. For example, IntelliSense in VSCode.
I can't remember myself right now, but I know there's a way of doing it, so ^
@caini1213 Just found it. Try setting it to Duration.zero. This should disable it.
https://user-images.githubusercontent.com/58871500/197142598-886f77ff-d9dc-4716-9271-3e29855656ed.mp4
@caini1213 That video seems to be showing correct functioning? Is something still not working for you?
Alright, but the problem is when I zoom the map, the red color downloaded region will cover the region that I didnt choose to download.
Ok, it might look wrong, but this is actually correct.
As you zoom out, tiles cover a larger area. For example, a tile at zoom level 18 might only cover one residential street, whereas a tile at zoom level 11 might show a whole city.
Therefore, the further you zoom out, the more of the map will be downloaded - but only at that zoom level. As you can see when you zoom back in, ~half the area becomes non-red again. You can try increasing the minimum zoom level if you don't want the whole world downloaded at zoom level 1.
It is impossible to download any fraction of a tile except one whole, so you'll notice that all bulk downloaders have this behaviour.

Currently I'm using ^5.1.0 version, from the image above, the .checkTileAsync() function is to check whether the tile is cached from the store selected right? Can u help me to see if there is any mistake here? Because whenever I load the cached tiles, the red color region will cover over my map (no matter zoom in or out) instead of covering only the downloaded region.
Can you post a video of this behaviour, or is it the same as the one above?
https://user-images.githubusercontent.com/58871500/197148703-db3f404b-2f60-43e2-8f59-b92cf5b94e5c.mp4
petal_20221021_162100.mp4
the region is downloaded with zoom level 16 - 20
Yes this is unusual. Can you post some more of your surrounding code than the screenshot above?
I know that the checkTileCachedAsync function should be working correctly - because it does in the example - so it must be something a bit off in your implementation.

yes, is unusual... pls let me know if there is any mistake :)
FYI, I pass TileLayerOptions( maxZoom: 20, urlTemplate: 'http://www.google.cn/maps/vt?lyrs=s@189&gl=cn&x={x}&y={y}&z={z}')
when download the region.
Unfortunately, I can't see any mistakes. It does appear that the function is returning true for all tiles. Can you assure us that those tiles actually aren't downloaded? I cannot see why that function would be broken when working in the example app.
Can you try painting that polygon for the area you think you downloaded?
As example, i choose to download the region around these 5 blocks and so, the color region should show around them only.
https://user-images.githubusercontent.com/58871500/197153865-123a6de7-9bcd-45d0-982a-cf10990d02b8.mp4
But it cover all over the map as shown in the video, hmm it's weird
Ok, another debugging method. Can you try zooming out significantly for me, then zooming in significantly for me - outside the intended downloading area. Can you do a screen recording of that?
https://user-images.githubusercontent.com/58871500/197155248-69320c15-6a5d-43a4-b290-e7524fcb0940.mp4
Like this?
Ok, that doesn't seem right either. I'll have to investigate, but I'm not sure I'll find anything. I'll be in contact soon. Thanks for your help.
Alright, thank you very much!
Hi there, any updates? :)