Skip to content

Commit

Permalink
Merge pull request #781 from pento/try/fast-tile-replace
Browse files Browse the repository at this point in the history
Add a fastReplace option to TileLayerOptions.
  • Loading branch information
kengu authored Apr 30, 2021
2 parents 1cb0e6f + f7b064c commit 38d9047
Showing 1 changed file with 26 additions and 0 deletions.
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

0 comments on commit 38d9047

Please sign in to comment.