Skip to content

Commit 3454b23

Browse files
WudgeJalkclaude
andcommitted
fix: DiscreteTileRange.contains rejects TileCoordinates of another zoom level
`contains` compared x/y only. `TileImageView` checks the coordinates of every loaded level against ranges of the target level, so a tile of another level whose x/y fell in the range was rendered and kept as if it were visible, even with every target tile ready. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 34457c1 commit 3454b23

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

‎lib/src/layer/tile_layer/tile_range.dart‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,12 @@ class DiscreteTileRange extends TileRange {
121121
/// Check if a [Point] is inside of the bounds of the [DiscreteTileRange].
122122
///
123123
/// We use a modulo in order to prevent side-effects at the end of the world.
124+
/// [TileCoordinates] at another zoom level are never contained.
124125
bool contains(
125126
Point<int> point, {
126127
bool replicatesWorldLongitude = false,
127128
}) {
129+
if (point is TileCoordinates && point.z != zoom) return false;
128130
if (!replicatesWorldLongitude) {
129131
return _bounds.contains(point);
130132
}

‎test/layer/tile_layer/tile_image_view_test.dart‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,28 @@ void main() {
139139
});
140140

141141
group('renderTiles', () {
142+
test('a tile of another zoom level is not rendered as visible', () {
143+
// Every visible z10 tile is ready: no fallback is needed. The z9 tile
144+
// has x/y inside the z10 visible range but belongs to another level.
145+
final tileImages = tileImagesMappingFrom([
146+
MockTileImage(2, 2, 10),
147+
MockTileImage(3, 2, 10),
148+
MockTileImage(2, 3, 10),
149+
MockTileImage(3, 3, 10),
150+
MockTileImage(2, 2, 9),
151+
]);
152+
final tileImageView = TileImageView(
153+
tileImages: tileImages,
154+
positionCoordinates: Set<TileCoordinates>.from(tileImages.keys),
155+
visibleRange: discreteTileRange(2, 2, 3, 3, zoom: 10),
156+
keepRange: discreteTileRange(2, 2, 3, 3, zoom: 10),
157+
);
158+
expect(
159+
tileImageView.renderTiles,
160+
isNot(contains(const TileCoordinates(2, 2, 9))),
161+
);
162+
});
163+
142164
test('%.retainChildren uses correct coordinates for z+2 fallback', () {
143165
// This test verifies that _retainChildren correctly calculates
144166
// descendant coordinates when recursing to z+2 level.

‎test/layer/tile_layer/tile_range_test.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ void main() {
281281
expect(tileRange.contains(const Point(2, 4)), isFalse);
282282
expect(tileRange.contains(const Point(3, 4)), isFalse);
283283
expect(tileRange.contains(const Point(4, 4)), isFalse);
284+
expect(tileRange.contains(const TileCoordinates(3, 3, 0)), isFalse);
284285
});
285286
});
286287
}

0 commit comments

Comments
 (0)