Skip to content

Commit decf89b

Browse files
authored
fix: correct coordinate calculation in _retainChildren recursion (#2174)
1 parent 6d25519 commit decf89b

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

lib/src/layer/tile_layer/tile_image_view.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ final class TileImageView {
183183
}
184184

185185
if (z + 1 < maxZoom) {
186-
_retainChildren(retain, i, j, z + 1, maxZoom);
186+
_retainChildren(retain, 2 * x + i, 2 * y + j, z + 1, maxZoom);
187187
}
188188
}
189189
}

test/layer/tile_layer/tile_image_view_test.dart

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,37 @@ void main() {
138138
}
139139
});
140140

141+
group('renderTiles', () {
142+
test('%.retainChildren uses correct coordinates for z+2 fallback', () {
143+
// This test verifies that _retainChildren correctly calculates
144+
// descendant coordinates when recursing to z+2 level.
145+
// Using large coordinates (100, 200) to catch the bug where
146+
// i,j (0-1) was passed instead of 2*x+i, 2*y+j.
147+
const baseZoom = 10;
148+
final tileImages = tileImagesMappingFrom([
149+
// z=10 tile not ready
150+
MockTileImage(100, 200, baseZoom,
151+
loadFinished: false, readyToDisplay: false),
152+
// z=11 tiles don't exist
153+
// z=12 tile exists and is ready (this is what we want to fall back to)
154+
MockTileImage(400, 800, baseZoom + 2),
155+
]);
156+
157+
final tileImageView = TileImageView(
158+
tileImages: tileImages,
159+
positionCoordinates: Set<TileCoordinates>.from(tileImages.keys),
160+
visibleRange: discreteTileRange(100, 200, 100, 200, zoom: baseZoom),
161+
keepRange: discreteTileRange(100, 200, 100, 200, zoom: baseZoom),
162+
);
163+
164+
final renderTiles = tileImageView.renderTiles.toList();
165+
expect(
166+
renderTiles,
167+
contains(const TileCoordinates(400, 800, baseZoom + 2)),
168+
);
169+
});
170+
});
171+
141172
test('errorTilesNotVisible', () {
142173
const zoom = 10;
143174
final tileImages = tileImagesMappingFrom([

0 commit comments

Comments
 (0)