Skip to content

Commit

Permalink
fix: eagerly listen to TileLayer.reset stream to ensure handler is …
Browse files Browse the repository at this point in the history
…fired (#1943)
  • Loading branch information
JaffaKetchup authored Sep 28, 2024
1 parent 4c3e3e2 commit bf91ee0
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions lib/src/layer/tile_layer/tile_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,7 @@ class _TileLayerState extends State<TileLayer> with TickerProviderStateMixin {

final _tileImageManager = TileImageManager();
late TileBounds _tileBounds;
late var _tileRangeCalculator =
TileRangeCalculator(tileSize: widget.tileSize);
late TileRangeCalculator _tileRangeCalculator;
late TileScaleCalculator _tileScaleCalculator;

// We have to hold on to the mapController hashCode to determine whether we
Expand All @@ -345,10 +344,14 @@ class _TileLayerState extends State<TileLayer> with TickerProviderStateMixin {
StreamSubscription<TileUpdateEvent>? _tileUpdateSubscription;
Timer? _pruneLater;

late final _resetSub = widget.reset?.listen((_) {
_tileImageManager.removeAll(widget.evictErrorTileStrategy);
if (mounted) _loadAndPruneInVisibleBounds(MapCamera.of(context));
});
StreamSubscription<void>? _resetSub;

@override
void initState() {
super.initState();
_resetSub = widget.reset?.listen(_resetStreamHandler);
_tileRangeCalculator = TileRangeCalculator(tileSize: widget.tileSize);
}

// This is called on every map movement so we should avoid expensive logic
// where possible, or filter as necessary
Expand Down Expand Up @@ -452,6 +455,11 @@ class _TileLayerState extends State<TileLayer> with TickerProviderStateMixin {
} else if (oldWidget.tileDisplay != widget.tileDisplay) {
_tileImageManager.updateTileDisplay(widget.tileDisplay);
}

if (widget.reset != oldWidget.reset) {
_resetSub?.cancel();
_resetSub = widget.reset?.listen(_resetStreamHandler);
}
}

@override
Expand Down Expand Up @@ -707,6 +715,11 @@ class _TileLayerState extends State<TileLayer> with TickerProviderStateMixin {

bool _outsideZoomLimits(num zoom) =>
zoom < widget.minZoom || zoom > widget.maxZoom;

void _resetStreamHandler(void _) {
_tileImageManager.removeAll(widget.evictErrorTileStrategy);
if (mounted) _loadAndPruneInVisibleBounds(MapCamera.of(context));
}
}

double _distanceSq(TileCoordinates coord, Point<double> center) {
Expand Down

0 comments on commit bf91ee0

Please sign in to comment.