Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/src/layer/tile_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ class _TileLayerState extends State<TileLayer> with TickerProviderStateMixin {

void _addTile(Coords<double> coords) {
var tileCoordsToKey = _tileCoordsToKey(coords);
_tiles[tileCoordsToKey] = Tile(
var tile = _tiles[tileCoordsToKey] = Tile(
coords: coords,
coordsKey: tileCoordsToKey,
tilePos: _getTilePos(coords),
Expand All @@ -946,6 +946,8 @@ class _TileLayerState extends State<TileLayer> with TickerProviderStateMixin {
options.tileProvider.getImage(_wrapCoords(coords), options),
tileReady: _tileReady,
);

tile.loadTileImage();
Copy link
Copy Markdown
Collaborator

@johnpryan johnpryan Aug 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nitpick) This code could use the cascade operator to simplify:

_tiles[tileCoordsToKey] = Tile(
  // ...
)..loadTileImage();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it but didn't work. I'll give it another try maybe hotreload bugged.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I retried it didn't work. I think this happens under hood when cascade operator is used.

  1. Tile object created
  2. loadTileImage method called on Tile
  3. Tile added to _tiles[tileCoordsToKey]

With temp variable this happens:

  1. Tile object created
  2. Tile added to _tiles[tileCoordsToKey]
  3. loadTileImage method called on Tile

So even if loadTileImage's callback is synchronous we are sure it is already in _tiles map.

}

void _tileReady(Coords<double> coords, dynamic error, Tile tile) {
Expand Down Expand Up @@ -1078,9 +1080,7 @@ class Tile implements Comparable<Tile> {
this.active = false,
this.retain = false,
this.loadError = false,
}) {
loadTileImage();
}
});

void loadTileImage() {
try {
Expand Down