diff --git a/lib/src/layer/tile_layer.dart b/lib/src/layer/tile_layer.dart index fbbb3c0e4..7b52f289a 100644 --- a/lib/src/layer/tile_layer.dart +++ b/lib/src/layer/tile_layer.dart @@ -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, @@ -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 @@ -1086,6 +1100,18 @@ class _TileLayerState extends State 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;