Skip to content

[BUG] Tiles not updated when urlTemplate changes if tile provider not reconstructed #183

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

Open
codeOfJannik opened this issue Mar 4, 2025 · 4 comments · May be fixed by #182
Open

[BUG] Tiles not updated when urlTemplate changes if tile provider not reconstructed #183

codeOfJannik opened this issue Mar 4, 2025 · 4 comments · May be fixed by #182
Labels
bug This issue reports broken functionality or another error

Comments

@codeOfJannik
Copy link

What is the bug?

When a FMTCTileProvider is used and the urlTemplate is switched during runtime, the rendered map tiles on the currently visible map area are not updated to the style of the new url template. Also emitting an event to the reset stream of the TileLayer does not force the layer to show the new style. But if you move around the map, new map tiles are rendered in the new style. So switching the url template in general works.

How can we reproduce it?

  • Take the flutter_map 8.1.0 example app
  • add flutter_map_tile_caching as a dependency
  • add FMTC init and setup to main.dart:
WidgetsFlutterBinding.ensureInitialized();
await FMTCObjectBoxBackend().initialise();
await const FMTCStore('mapStore').manage.create();
  • to lib/pages/reset_tile_layer.dart add the FMTCTileProvider logic:
final _fmtcTileProvider = FMTCTileProvider(stores: {'mapStore': BrowseStoreStrategy.readUpdateCreate}, httpClient: httpClient);

final httpClient = IOClient(HttpClient()..userAgent = null);

class ResetTileLayerPage extends StatefulWidget {
TileLayer(
    reset: resetController.stream,
    urlTemplate: layerToggle ? layer1 : layer2,
    subdomains: layerToggle ? const [] : const ['a', 'b', 'c'],
    userAgentPackageName: 'dev.fleaflet.flutter_map.example',
    tileProvider: _fmtcTileProvider,
),

Do you have a potential solution?

No response

Platforms

tested on iOS device and Android emulator

Severity

Obtrusive: Prevents normal functioning but causes no errors in the console

@codeOfJannik codeOfJannik added bug This issue reports broken functionality or another error needs verification This needs to be verified/tested before fixes (or not) can be made labels Mar 4, 2025
@JaffaKetchup
Copy link
Owner

JaffaKetchup commented Mar 5, 2025

Hi @codeOfJannik,
Thanks for reporting, I can reproduce this, and I've found why/where the issue occurs. I'll look into fixing it.

@JaffaKetchup JaffaKetchup removed the needs verification This needs to be verified/tested before fixes (or not) can be made label Mar 5, 2025
@JaffaKetchup
Copy link
Owner

#182 has been updated to include the best solution to this problem, following the pattern of the FM tile providers. However, it relies upon a breaking change. I do not intend to release a breaking change yet, as the purpose/aim of the PR may be changed by an upcoming change to FM.

The issue occurs because the Flutter image cache key assigned to the tile does not consider the URL template - this was missed during testing, since in the example app, it does not occur because the provider is reconstructed every time the URL is changed, and is not easy to fix without a breaking change because the internal image provider takes the entire TileLayer as a parameter (from which it then generates the tile's URL), which does not have an equality, so it is not tested. Therefore, the image cache does not realise it needs a new image, so just displays the one cached in memory.

There's a few workaround options:

  • When you change the URL, reconstruct a new FMTCTileProvider - you may also need to change a property (a dummy header field or a new HTTP client might work well) - to break the equality chain
  • Override your FMTC dependency to the 'support-vector' branch from Git (you shouldn't be affected by any changes, but since it does technically change the external API, it is considered breaking even if no-one is likely to be using that API)
  • In the coming day(s) I'll try to release a v11 prerelease containing those changes, which you can then depend on (but will be more stable than depending from Git as you won't receive any further commits which change things unexpectedly)

@JaffaKetchup JaffaKetchup changed the title [BUG] v10 - Current rendered tiles not updated when urlTemplate changes [BUG] Tiles not updated when urlTemplate changes if tile provider not reconstructed Mar 5, 2025
@codeOfJannik
Copy link
Author

@JaffaKetchup Thanks for investigating and providing the workaround options!

@JaffaKetchup
Copy link
Owner

I've released v11.0.0-dev.2, so you can depend on that instead of Git (if you were using that option). It is unlikely to progress to a full release soon, see the description on the #182 PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue reports broken functionality or another error
Projects
None yet
2 participants