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

How can I manually tell the TileLayerOptions to load and paint a tile? #966

Closed
JaffaKetchup opened this issue Jul 9, 2021 Discussed in #963 · 21 comments
Closed

How can I manually tell the TileLayerOptions to load and paint a tile? #966

JaffaKetchup opened this issue Jul 9, 2021 Discussed in #963 · 21 comments

Comments

@JaffaKetchup
Copy link
Member

Discussed in #963

Originally posted by JaffaKetchup July 5, 2021
I need to do this as I'm implementing a way to remove grey tiles, but I can't change the base code in flutter_map. See JaffaKetchup/flutter_map_tile_caching#12.

My existing code:

@override
ImageProvider getImage(Coords<num> coords, TileLayerOptions options) {
    // `preloadSurroundings` is a boolean dictating whether the grey tiles should be attempted to be removed
    if (preloadSurroundings) {
      for (double x = coords.x - 6; x < coords.x + 6; x++) {
        for (double y = coords.y - 6; y < coords.y + 6; y++) {
          /*_CachedTileImageProvider(
            getTileUrl(Coords<num>(x, y)..z = coords.z, options),
            Coords<num>(coords.x, coords.y)..z = coords.z,
            cacheName: cacheName,
          );*/
         // How can I manually load AND PAINT the image above
        }
      }
    }
    return _CachedTileImageProvider(
      getTileUrl(coords, options),
      Coords<num>(coords.x, coords.y)..z = coords.z,
      cacheName: cacheName,
    );
  }
@ibrierley
Copy link
Collaborator

Isn't this just the same issue as 963?

@JaffaKetchup
Copy link
Member Author

Yeah, I can close it if you want (as duplicate), but it was to attract attention because no-one had answered, so I wasn't sure if anybody had actually seen it, or no-body knew. That's why it has a 'Discussed in' header.

@JaffaKetchup JaffaKetchup changed the title How can I manually tell the TileLayerOptions to load and paint a tile? How can I manually tell the TileLayerOptions to load and paint a tile? [DISCUSSION] Jul 9, 2021
@ibrierley
Copy link
Collaborator

The issue also confuses me, as typically grey tiles are just transparent tiles that aren't available yet aren't they...so what's actually trying to be achieved ?

@JaffaKetchup
Copy link
Member Author

Yeah, sorry, should've clarified. This is for my plugin that handles caching.

A user wanted to preload a whole area after it had been downloaded (JaffaKetchup/flutter_map_tile_caching#12) to totally avoid the grey tiles (which still appeared even if the tile was cached/downloaded already because of the time to lookup, fetch from the caching database and paint).

I suggested that preloading a whole area would be unnecessary and could cause extreme performance issues (if 20000 tiles (currently max number of cached tiles allowed) were shown, the map would be incredibly laggy), so the idea is to automatically get the nearest tiles in each direction before the user scrolls there.

Therefore I need to paint a tile before it actually becomes visible, the topic of this issue/discussion.

@ibrierley
Copy link
Collaborator

I've certainly played with preloading tiles (iirc I preloaded an extra tile the user was panning to). But I had to edit the tile layer code myself around the tileRange.min.y for loop (which looks partially what you are trying already)...Only thing I can think of is to have your own tile_layer code (or have it as part of the plugin), but maybe that's an issue.

Just thinking though (taking a quick scan of the plugin), do you need to use a database, why not just use a file cache ? (just wondering if that's faster to get around the problem another way).

@JaffaKetchup
Copy link
Member Author

JaffaKetchup commented Jul 9, 2021

Yeah, I hoped I wouldn't have to edit the code in this package.
The main reason I can't use files is that the plugin was originally created by someone else using sqflite, so instead of changing it completely, I've just stuck with it. It also allows better queries etc.. Rewriting for that now would be a huge refactoring and at the moment, I just don't particularly want to do that.

@JaffaKetchup
Copy link
Member Author

Actually, I've reconsidered. Perhaps using a file method would be better. I can still find some code from one of my previous attempts at #798, so @ibrierley, do you think using a file method would be quicker?

@ibrierley
Copy link
Collaborator

ibrierley commented Jul 10, 2021 via email

@JaffaKetchup
Copy link
Member Author

That package looks good at first glimpse, but this worries me:

By default the cached files are stored in the temporary directory of the app. This means the OS can delete the files any time.

Information about the files is stored in a database using sqflite on Android, iOS and macOs, or in a plain JSON file on other platforms. The file name of the database is the key of the cacheManager, that's why that has to be unique.

I need to not store in app cache, because the OS deleting map tiles could have bad consequences (extreme example: hiker downloads an area, without the hiker knowing, the OS deletes it, the hiker gets stuck on a mountain with no signal). I also need to have multiple caching spaces to keep a functionality I recently added. This may be solvable if I specify where else to put it?

And surely by using a database, it won't make a difference to the time again.

Although this package has nice features built-in like having an expiry, I may have to use network_to_file_image, and make that expiry functionality another way using metadata of some sorts?

But yeah, I probably will have a go with this, to see if it is indeed faster. Hopefully, it'll cut down on my library's size as well (less code). I'll try the package you mentioned first, but I feel I may need to use that other library instead. Thanks for the suggestion!

However, in the event that neither of these two options is faster, I'll still need to do the original purpose of this issue, so I'm leaving this issue open for that.

@JaffaKetchup
Copy link
Member Author

I've done the basics required, and unfortunately, I can't see that much of a difference. I'll still have to do this, but a way might be to make the map bigger than normal, so it overflows the visible area?

@JaffaKetchup
Copy link
Member Author

Ok, so that doesn't work very well either.

So the question still stands, 'How can I manually tell the TileLayerOptions to load and paint a tile?'

@JaffaKetchup
Copy link
Member Author

Hi there,
Does anyone else have any ideas, or I'll close this for now?
Thanks.

@ibrierley
Copy link
Collaborator

Tbh, given the sluggish turnaround of changes here anyway, I'd probably go with a custom plugin alternate tile provider.

@JaffaKetchup
Copy link
Member Author

given the sluggish turnaround of changes here

😂

Probably misunderstanding here, but does that ('custom plugin alternate tile provider') mean it can be done without submitting a PR for this library?

@ibrierley
Copy link
Collaborator

ibrierley commented Aug 3, 2021 via email

@ibrierley
Copy link
Collaborator

ibrierley commented Aug 3, 2021 via email

@ibrierley
Copy link
Collaborator

ibrierley commented Aug 3, 2021 via email

@JaffaKetchup
Copy link
Member Author

JaffaKetchup commented Aug 3, 2021

Don't worry about the spam, I'm just as bad with editing my comments all the time :)

I see. So I'm assuming thats using the Plugin API (plugins: [])?

Thanks for the examples and suggestions!

@JaffaKetchup
Copy link
Member Author

JaffaKetchup commented Aug 3, 2021

 (I find that too hard to follow these days anyway).

Yeah same, that naming is so confusing 😅

Don't worry, I just answered my own question looking at line 84 of your vector plugin.

Thanks again, and I'll see what I can reasonably do with a tile layer (ie. As long as it doesn't triple the size of my library)!

@JaffaKetchup JaffaKetchup changed the title How can I manually tell the TileLayerOptions to load and paint a tile? [DISCUSSION] How can I manually tell the TileLayerOptions to load and paint a tile? Aug 4, 2021
@github-actions
Copy link

github-actions bot commented Sep 4, 2021

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Sep 4, 2021
@JaffaKetchup
Copy link
Member Author

For now I'm going to close this, even though I haven't yet done what @ibrierley suggested - I found it quite complicated. Thanks for the help!

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

2 participants