Skip to content

Commit eb92ff2

Browse files
fix: consider zoomOffset & emulated retina mode when generating tile coordinates (#2060)
1 parent a4d849e commit eb92ff2

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

lib/src/layer/tile_layer/tile_coordinates.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,17 @@ class TileCoordinates extends Point<int> {
6161
/// simplify the tile coordinates: we just return the same value.
6262
class TileCoordinatesResolver {
6363
/// Resolves coordinates in the context of world replications.
64-
const TileCoordinatesResolver(this.replicatesWorldLongitude);
64+
const TileCoordinatesResolver(
65+
this.replicatesWorldLongitude, {
66+
this.zoomOffset = 0,
67+
});
6568

6669
/// True if we simplify the coordinates according to the world replications.
6770
final bool replicatesWorldLongitude;
6871

72+
/// The zoom number used for modulus will be offset with this value.
73+
final int zoomOffset;
74+
6975
/// Returns the simplification of the coordinates.
7076
TileCoordinates get(TileCoordinates positionCoordinates) {
7177
if (!replicatesWorldLongitude) {
@@ -74,7 +80,7 @@ class TileCoordinatesResolver {
7480
if (positionCoordinates.z < 0) {
7581
return positionCoordinates;
7682
}
77-
final modulo = 1 << positionCoordinates.z;
83+
final modulo = 1 << (positionCoordinates.z + zoomOffset);
7884
int x = positionCoordinates.x;
7985
while (x < 0) {
8086
x += modulo;

lib/src/layer/tile_layer/tile_image_manager.dart

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,17 @@ class TileImageManager {
3030
TileCoordinatesResolver _resolver = const TileCoordinatesResolver(false);
3131

3232
/// Sets if we replicate the world longitude in several worlds.
33-
void setReplicatesWorldLongitude(bool replicatesWorldLongitude) {
34-
if (_resolver.replicatesWorldLongitude == replicatesWorldLongitude) {
35-
return;
33+
void setReplicatesWorldLongitude(
34+
bool replicatesWorldLongitude,
35+
int zoomOffset,
36+
) {
37+
if (_resolver.replicatesWorldLongitude != replicatesWorldLongitude ||
38+
_resolver.zoomOffset != zoomOffset) {
39+
_resolver = TileCoordinatesResolver(
40+
replicatesWorldLongitude,
41+
zoomOffset: zoomOffset,
42+
);
3643
}
37-
_resolver = TileCoordinatesResolver(replicatesWorldLongitude);
3844
}
3945

4046
/// Filter tiles to only tiles that would be visible on screen. Specifically:

lib/src/layer/tile_layer/tile_layer.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ class _TileLayerState extends State<TileLayer> with TickerProviderStateMixin {
384384

385385
_tileImageManager.setReplicatesWorldLongitude(
386386
camera.crs.replicatesWorldLongitude,
387+
widget.zoomOffset.round(),
387388
);
388389

389390
if (_mapControllerHashCode != mapController.hashCode) {

0 commit comments

Comments
 (0)