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

Issues when change map tiles URL dynamically #583

Closed
jesusrp98 opened this issue Apr 11, 2020 · 14 comments · Fixed by #584
Closed

Issues when change map tiles URL dynamically #583

jesusrp98 opened this issue Apr 11, 2020 · 14 comments · Fixed by #584

Comments

@jesusrp98
Copy link
Contributor

First thing, congratulation! The v0.9.0 release include really nice features!

Since this new update, when I try to change the map tiles URL while running the app, it takes a couple seconds, after to start navigating the mapo with the finger, until all tiles are updated. Before, this change was instantly performed.

Here's how I change the URL dynamically:

FlutterMap(
  mapController: _mapController,
  options: MapOptions(
    ...
  ),
  layers: <LayerOptions>[
    TileLayerOptions(
      urlTemplate: context.watch<MapProvider>().mapUrl,
      backgroundColor: Theme.of(context).canvasColor,
    ),
    MarkerLayerOptions(
      ...
    ),
  ],
),

Is this a bug, or is there a better method to update the map URL, for example using the MapController class? Thank!

@maRci002
Copy link
Contributor

Hello, in #572 PR I implemented Leaflet's tile fetching / retaining strategy. Basicly if a Tile was loaded there is currently no way to force it to change Image based on new url while it is retained.

Give me some time I'll make some changes to watch url changes.

@jesusrp98
Copy link
Contributor Author

Great. This could be implemented as an option inside the MapController itself.

For example:
mapControler.setUrl(newMapUrl);

Great job, and thanks a lot!

@maRci002
Copy link
Contributor

You can test it, just change your dependency and run flutter pub upgrade

  flutter_map:
    git:
      url: git://github.com/johnpryan/flutter_map.git
      ref: 646912e30075032473b3fce6aea5ab6f2d8b1359

You will see the fade in animation (except if you provided tileFadeInDuration = 0), if you really need I can provide some flag like skipTileFadeInWhileReload, however I think it is unnecessary because even in Leaflet this would be two steps remove old layer and attach new layer which would cause the fade in effect.

@jesusrp98
Copy link
Contributor Author

Works perfectly!
Thank you very much for this fix :)

@mootw
Copy link
Collaborator

mootw commented May 3, 2020

Using this fix causes flashing (A brief delay where the old image disappears completely, and the new one is not active). if the URL is changed frequently and tileFadeInDuration = 0. I would expect there to be no delay if the fade in is set to zero. The old tile should wait for a new tile to load and swap between them with zero blank time.

@jesusrp98
Copy link
Contributor Author

I have the same problem as @moonag and I agree that this is an issue @johnpryan

@maRci002
Copy link
Contributor

maRci002 commented May 4, 2020

I'll take a look later today.

@moonag @jesusrp98 I'm a bit confused what should happen if forinstace there are 9x tiles loaded on screen and if you change the URL then old tiles should be visible until new ones aren't downloaded (for simplicity user isn't panning / zooming while Tiles are downloading), assume 6x tiles download very fast so they will be shown asap but 3x is still in downloading phase, SO you will see old and new tiles as mixed.

@jesusrp98
Copy link
Contributor Author

I get what you're saying @maRci002. The thing is that in earlier versions of this plugin, when you change the tile URL, the screen wouldn't flash the background color. It will simply apply all the updated tiles.

So the right behaviour should be just to wait untill all visible tiles are downloaded, and then display the new ones.

You could check this behaviour in < v0.9.0 version of this package.
Hope I explained it correctly :)

@mootw
Copy link
Collaborator

mootw commented May 4, 2020

Just to clarify, each tile is loaded individually and replaced individually. @maRci002 @jesusrp98 . The issue is that the tile flashes the background color (transparent) for a brief time when the new one is switched out with this fix. Pre 0.9.0 behavior would be to switch out the tiles instantly without the tile briefly disappearing before the new one appears. This is true even if the fade in delay is set to zero. You can create this by having 2 url layers switch quickly between each other and see the blank frames. It does apply to the whole screen, but individual tiles blank before the new one is shown. When you change the URL, the tile should wait for the new one to load in and then show the new one; but still keep the old tile visible.

@maRci002
Copy link
Contributor

maRci002 commented May 4, 2020

I'm pretty sure in < v0.9.0 version the tiles were independent of each other so it could happen if geoserver delays some tiles download speed because of high triffic then old and new tiles will be shown mixed.

@moonag When you change the URL, the tile should wait for the new one to load in and then show the new one; but still keep the old tile visible.

I'll implement this behavior.

@jesusrp98
Copy link
Contributor Author

Nice! Looking forward to test it!

@maRci002
Copy link
Contributor

maRci002 commented May 4, 2020

I made some changes to support this kind of behaviour check out:

  flutter_map:
    git:
      url: git://github.com/johnpryan/flutter_map.git
      ref: c590ab12edbf5b6fce30b13a42e974c0abadd506

First of all set overrideTilesWhenUrlChanges to true secondly you do not have play with tileFadeInDuration = 0 anymore (feel free to use it) because you can set tileFadeInStartWhenOverride to 1.0 to avoid fade in animations when old tile is being override.

I still think overrideTilesWhenUrlChanges is an unsafe operation so it is false by default, see little demo:
url change without drop old tiles

Please do some tests forinstace what happens if a tile is in loading phase and url changes then new one loads fine and if old finished loading then it should never be on screen (I tested it only in my mind 😄).

@mootw
Copy link
Collaborator

mootw commented May 5, 2020

@maRci002 I tested it out. Behaves exactly as intended. There does not seem to be an issue if a tile url is swapped before it is fully loaded It always shows the old one which is preferred. It is exactly as intended! You are insane! This should be a PR as it adds improvements tile fetching behavior.

@maRci002
Copy link
Contributor

maRci002 commented May 5, 2020

It is actually a PR see #584 .

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

Successfully merging a pull request may close this issue.

3 participants