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

[FEATURE] Improve the handling of retina tiles #1670

Closed
bramp opened this issue Sep 27, 2023 · 1 comment · Fixed by #1673
Closed

[FEATURE] Improve the handling of retina tiles #1670

bramp opened this issue Sep 27, 2023 · 1 comment · Fixed by #1673
Labels
feature This issue requests a new feature P: 2 (soon™?)

Comments

@bramp
Copy link
Contributor

bramp commented Sep 27, 2023

What is the bug?

The TileLayer class has a retinaMode boolean, which when set triggers flutter_maps to request 4 tiles for every 1 and display them at half size, effectively doubling the resolution.

The urlTemplate supports a {r} placeholder, that is always replaced with a '@2x' asking the tile provider to return a tile at double the standard resolution (for example, requesting a 256x256 image, will have a 512x512 returned).

However, these things don't play well together. For example, if flutter_maps needs to fill a 256x256 square on the screen, one of the following three things will happen:

  1. If {r} is in the urlTemplate, the @2x will always be added, regardless of the devices dpi (e.g even if the device only supports 1x, thus details from the image will be lost when displayed).

  2. If retinaMode is set to true, then flutter_maps will fetch 4 squares (at one zoom lower) to make a 512x512 image for this space, and fill that in on the screen, thus simulating it. This only makes sense to do if the device supports dpi > 1x.

  3. If the url contains {r} and retinaMode is set to true, we end up fetching 4 squares at 512x512 each (so total of 1024x1024), and jamming that into the 256x256 space.

So # 3 seems wasteful.

How can we reproduce it?

TileLayer(
   retinaMode: true,
   urlTemplate: 'https://..../{z}/{x}/{y}{r}',
)

Will attempt to both fetch 2x quality images, as well as make four requests for every 1 tile.

Do you have a potential solution?

After discussion on #1666, we think the correct behaviour should be:

TileLayer.retinaMode becomes a enum:

  • off: don't do anything about retina mode
  • on: if '{r}' is provided, fill it with '@2x', else simulate it
  • auto (default): if the device's dpi > 1x then 'on', otherwise use 'off'

and for private testing

  • simulate: simulate retina mode

Platforms

All

Severity

Minimum: Allows normal functioning

@bramp bramp added bug This issue reports broken functionality or another error needs triage This new bug report needs reproducing and prioritizing labels Sep 27, 2023
@JaffaKetchup JaffaKetchup added feature This issue requests a new feature P: 2 (soon™?) and removed bug This issue reports broken functionality or another error needs triage This new bug report needs reproducing and prioritizing labels Sep 28, 2023
@JaffaKetchup JaffaKetchup changed the title [BUG] Improve the handling of retina tiles [FEATURE] Improve the handling of retina tiles Sep 28, 2023
@JaffaKetchup
Copy link
Member

One thing we haven't considered, which is I guess why this wasn't done before, is that we need the BuildContext to whether the device is high DPI. This has huge knock on effects, as the retina mode (simulation now) is used to change some other properties.

@JaffaKetchup JaffaKetchup linked a pull request Sep 29, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This issue requests a new feature P: 2 (soon™?)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants