Skip to content

Commit

Permalink
Wrap to world zero when crossing the antimeridian (#4451)
Browse files Browse the repository at this point in the history
Fixes #2071
  • Loading branch information
andrewharvey authored and jfirebaugh committed Mar 22, 2017
1 parent c248672 commit d99dce8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/geo/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ class Transform {
setLocationAtPoint(lnglat, point) {
const translate = this.pointCoordinate(point)._sub(this.pointCoordinate(this.centerPoint));
this.center = this.coordinateLocation(this.locationCoordinate(lnglat)._sub(translate));
if (this._renderWorldCopies) {
this.center = this.center.wrap();
}
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/ui/camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,9 @@ class Camera extends Evented {
const scale = 1 / w(s);
tr.zoom = startZoom + tr.scaleZoom(scale);
tr.center = tr.unproject(from.add(to.sub(from).mult(us)).mult(scale));
if (tr.renderWorldCopies) {
tr.center = tr.center.wrap();
}

if (this.rotating) {
tr.bearing = interpolate(startBearing, bearing, k);
Expand Down
18 changes: 18 additions & 0 deletions test/unit/ui/camera.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,24 @@ test('camera', (t) => {
camera.flyTo({ center: [170, 0], duration: 10 });
});

t.test('jumps back to world 0 when crossing the antimeridian', (t) => {
const camera = createCamera();
camera.setCenter([-170, 0]);

let leftWorld0 = false;

camera.on('move', () => {
leftWorld0 = leftWorld0 || (camera.getCenter().lng < -180);
});

camera.on('moveend', () => {
t.false(leftWorld0);
t.end();
});

camera.flyTo({ center: [170, 0], duration: 10 });
});

t.test('peaks at the specified zoom level', (t) => {
const camera = createCamera({zoom: 20});
const minZoom = 1;
Expand Down

0 comments on commit d99dce8

Please sign in to comment.