From 7fb7fdd6210837921dd7a4ca4aad9a7e436415ea Mon Sep 17 00:00:00 2001 From: maRci002 Date: Tue, 4 Aug 2020 14:43:39 +0200 Subject: [PATCH 1/3] Make sure tile loads asynchronously --- lib/src/layer/tile_layer.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/layer/tile_layer.dart b/lib/src/layer/tile_layer.dart index 3315c4cc5..e6f9c1577 100644 --- a/lib/src/layer/tile_layer.dart +++ b/lib/src/layer/tile_layer.dart @@ -1079,7 +1079,7 @@ class Tile implements Comparable { this.retain = false, this.loadError = false, }) { - loadTileImage(); + Timer.run(loadTileImage); } void loadTileImage() { From e56f3d2b89ab312b8a2ece1dbf247169388b96dd Mon Sep 17 00:00:00 2001 From: maRci002 Date: Tue, 4 Aug 2020 15:22:38 +0200 Subject: [PATCH 2/3] Run asynchronously only when necessary --- lib/src/layer/tile_layer.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/src/layer/tile_layer.dart b/lib/src/layer/tile_layer.dart index e6f9c1577..15073a3bd 100644 --- a/lib/src/layer/tile_layer.dart +++ b/lib/src/layer/tile_layer.dart @@ -1079,7 +1079,7 @@ class Tile implements Comparable { this.retain = false, this.loadError = false, }) { - Timer.run(loadTileImage); + loadTileImage(); } void loadTileImage() { @@ -1132,14 +1132,14 @@ class Tile implements Comparable { void _tileOnLoad(ImageInfo imageInfo, bool synchronousCall) { if (null != tileReady) { this.imageInfo = imageInfo; - tileReady(coords, null, this); + Timer.run(() => tileReady(coords, null, this)); } } void _tileOnError(dynamic exception, StackTrace stackTrace) { if (null != tileReady) { - tileReady( - coords, exception ?? 'Unknown exception during loadTileImage', this); + Timer.run(() => tileReady( + coords, exception ?? 'Unknown exception during loadTileImage', this)); } } From 7413bba7b91f6697f7912aa2660465a940d7c9e4 Mon Sep 17 00:00:00 2001 From: maRci002 Date: Tue, 4 Aug 2020 16:17:51 +0200 Subject: [PATCH 3/3] Remove async callbacks and call `loadTileImage` when tile is in `_tiles` --- lib/src/layer/tile_layer.dart | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/src/layer/tile_layer.dart b/lib/src/layer/tile_layer.dart index 15073a3bd..8a28ddac8 100644 --- a/lib/src/layer/tile_layer.dart +++ b/lib/src/layer/tile_layer.dart @@ -936,7 +936,7 @@ class _TileLayerState extends State with TickerProviderStateMixin { void _addTile(Coords coords) { var tileCoordsToKey = _tileCoordsToKey(coords); - _tiles[tileCoordsToKey] = Tile( + var tile = _tiles[tileCoordsToKey] = Tile( coords: coords, coordsKey: tileCoordsToKey, tilePos: _getTilePos(coords), @@ -946,6 +946,8 @@ class _TileLayerState extends State with TickerProviderStateMixin { options.tileProvider.getImage(_wrapCoords(coords), options), tileReady: _tileReady, ); + + tile.loadTileImage(); } void _tileReady(Coords coords, dynamic error, Tile tile) { @@ -1078,9 +1080,7 @@ class Tile implements Comparable { this.active = false, this.retain = false, this.loadError = false, - }) { - loadTileImage(); - } + }); void loadTileImage() { try { @@ -1132,14 +1132,14 @@ class Tile implements Comparable { void _tileOnLoad(ImageInfo imageInfo, bool synchronousCall) { if (null != tileReady) { this.imageInfo = imageInfo; - Timer.run(() => tileReady(coords, null, this)); + tileReady(coords, null, this); } } void _tileOnError(dynamic exception, StackTrace stackTrace) { if (null != tileReady) { - Timer.run(() => tileReady( - coords, exception ?? 'Unknown exception during loadTileImage', this)); + tileReady( + coords, exception ?? 'Unknown exception during loadTileImage', this); } }