Skip to content

Commit

Permalink
jump back to world zero when crossing the antimeridian in flyTo or other
Browse files Browse the repository at this point in the history
camera operations mapbox#2071
  • Loading branch information
andrewharvey committed Mar 22, 2017
1 parent 9941dde commit fc24c44
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/geo/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ class Transform {

setLocationAtPoint(lnglat, point) {
const translate = this.pointCoordinate(point)._sub(this.pointCoordinate(this.centerPoint));
this.center = this.coordinateLocation(this.locationCoordinate(lnglat)._sub(translate));
this.center = this.coordinateLocation(this.locationCoordinate(lnglat)._sub(translate)).wrap();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/ui/camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ 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));
tr.center = tr.unproject(from.add(to.sub(from).mult(us)).mult(scale)).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 fc24c44

Please sign in to comment.