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

Add a fastReplace option to TileLayerOptions. #781

Merged
merged 2 commits into from
Apr 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions lib/src/layer/tile_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,19 @@ class TileLayerOptions extends LayerOptions {
// (see #576 - even Error Images are cached in flutter)
final EvictErrorTileStrategy evictErrorTileStrategy;

/// This option is useful when you have a transparent layer: rather than
/// keeping the old layer visible when zooming (resulting in both layers
/// being temporarily visible), the old layer is removed as quickly as
/// possible when this is set to `true` (default `false`).
///
/// This option is likely to cause some flickering of the transparent layer,
/// most noticeable when using pinch-to-zoom. It's best used with maps that
/// have `interactive` set to `false`, and zoom using buttons that call
/// `MapController.move()`.
///
/// When set to `true`, the `tileFadeIn*` options will be ignored.
final bool fastReplace;

TileLayerOptions({
Key key,
this.urlTemplate,
Expand Down Expand Up @@ -269,6 +282,7 @@ class TileLayerOptions extends LayerOptions {
this.tileBuilder,
this.tilesContainerBuilder,
this.evictErrorTileStrategy = EvictErrorTileStrategy.none,
this.fastReplace = false,
}) : updateInterval =
updateInterval <= 0 ? null : Duration(milliseconds: updateInterval),
tileFadeInDuration = tileFadeInDuration <= 0
Expand Down Expand Up @@ -1086,6 +1100,18 @@ class _TileLayerState extends State<TileLayer> with TickerProviderStateMixin {
return;
}

if (options.fastReplace && mounted) {
setState(() {
tile.active = true;

if (_noTilesToLoad()) {
// We're not waiting for anything, prune the tiles immediately.
_pruneTiles();
}
});
return;
}

var fadeInStart = tile.loaded == null
? options.tileFadeInStart
: options.tileFadeInStartWhenOverride;
Expand Down