From 7d34846b4a2867ba0902c41ac96346802c60c842 Mon Sep 17 00:00:00 2001 From: Gary Date: Sun, 29 Nov 2020 17:52:54 +1100 Subject: [PATCH 1/2] Add the fastReplace option to TileLayerOptions. --- lib/src/layer/tile_layer.dart | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/src/layer/tile_layer.dart b/lib/src/layer/tile_layer.dart index fbbb3c0e4..82f412e2f 100644 --- a/lib/src/layer/tile_layer.dart +++ b/lib/src/layer/tile_layer.dart @@ -227,6 +227,14 @@ 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`). + /// + /// When set to `true`, the `tileFadeIn*` options will be ignored. + final bool fastReplace; + TileLayerOptions({ Key key, this.urlTemplate, @@ -269,6 +277,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 +1095,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; From f7b064ca00d8b4763bffb200f3aeeab75df1b4e2 Mon Sep 17 00:00:00 2001 From: Gary Date: Mon, 30 Nov 2020 09:21:25 +1100 Subject: [PATCH 2/2] Document the pinch-to-zoom flickering. --- lib/src/layer/tile_layer.dart | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/src/layer/tile_layer.dart b/lib/src/layer/tile_layer.dart index 82f412e2f..7b52f289a 100644 --- a/lib/src/layer/tile_layer.dart +++ b/lib/src/layer/tile_layer.dart @@ -232,6 +232,11 @@ class TileLayerOptions extends LayerOptions { /// 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;