Skip to content

Commit

Permalink
Review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
ignatz committed Nov 8, 2023
1 parent f32f36b commit 68d838e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
4 changes: 0 additions & 4 deletions lib/src/layer/tile_layer/tile_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ class TileImage extends ChangeNotifier {
/// tile display is used with a maximum opacity less than 1.
bool get readyToDisplay => _readyToDisplay;

// Used to sort TileImages by their distance from the current zoom.
double zIndex(double maxZoom, int currentZoom) =>
maxZoom - (currentZoom - coordinates.z).abs();

/// Change the tile display options.
set tileDisplay(TileDisplay newTileDisplay) {
final oldTileDisplay = _tileDisplay;
Expand Down
34 changes: 17 additions & 17 deletions lib/src/layer/tile_layer/tile_image_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,14 @@ class TileImageView {

for (final tile in _tileImages.values) {
final c = tile.coordinates;
if (_keepRange.contains(c)) {
if (!tile.readyToDisplay) {
final retainedAncestor =
_retainAncestor(retain, c.x, c.y, c.z, c.z - 5);
if (!retainedAncestor) {
_retainChildren(retain, c.x, c.y, c.z, c.z + 2);
}
}
} else {
if (!_keepRange.contains(c)) {
stale.add(tile);
continue;
}

final retainedAncestor = _retainAncestor(retain, c.x, c.y, c.z, c.z - 5);
if (!retainedAncestor) {
_retainChildren(retain, c.x, c.y, c.z, c.z + 2);
}
}

Expand All @@ -54,15 +52,17 @@ class TileImageView {

for (final tile in _tileImages.values) {
final c = tile.coordinates;
if (_visibleRange.contains(c)) {
retain.add(tile);
if (!_visibleRange.contains(c)) {
continue;
}

retain.add(tile);

if (!tile.readyToDisplay) {
final retainedAncestor =
_retainAncestor(retain, c.x, c.y, c.z, c.z - 5);
if (!retainedAncestor) {
_retainChildren(retain, c.x, c.y, c.z, c.z + 2);
}
if (!tile.readyToDisplay) {
final retainedAncestor =
_retainAncestor(retain, c.x, c.y, c.z, c.z - 5);
if (!retainedAncestor) {
_retainChildren(retain, c.x, c.y, c.z, c.z + 2);
}
}
}
Expand Down
15 changes: 10 additions & 5 deletions lib/src/layer/tile_layer/tile_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -554,15 +554,20 @@ class _TileLayerState extends State<TileLayer> with TickerProviderStateMixin {
))
.toList();

// Sort in render order;
// Sort in render order. In reverse:
// 1. Tiles at the current zoom.
// 2. Tiles at the current zoom +/- 1.
// 3. Tiles at the current zoom +/- 2.
// 4. ...etc
final maxZoom = widget.maxZoom;
int renderOrder(Tile a, Tile b) => a.tileImage
.zIndex(maxZoom, tileZoom)
.compareTo(b.tileImage.zIndex(maxZoom, tileZoom));
int renderOrder(Tile a, Tile b) {
final (za, zb) = (a.tileImage.coordinates.z, b.tileImage.coordinates.z);
final cmp = (zb - tileZoom).abs().compareTo((za - tileZoom).abs());
if (cmp == 0) {
// When compare parent/child tiles of equal distance, prefer higher res images.
return zb.compareTo(za);
}
return cmp;
}

return MobileLayerTransformer(
// ignore: deprecated_member_use_from_same_package
Expand Down

0 comments on commit 68d838e

Please sign in to comment.