Skip to content

Commit

Permalink
make flyTo check if it can fly to worldCopies (#4459)
Browse files Browse the repository at this point in the history
  • Loading branch information
CrokinoleMaster authored and jfirebaugh committed Mar 22, 2017
1 parent 50439e0 commit 9941dde
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/geo/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ class Transform {
this.zoom = Math.min(this.zoom, zoom);
}

get renderWorldCopies() {
return this._renderWorldCopies;
}

get worldSize() {
return this.tileSize * this.scale;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ui/camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ class Camera extends Evented {

// If a path crossing the antimeridian would be shorter, extend the final coordinate so that
// interpolating between the two endpoints will cross it.
if (Math.abs(tr.center.lng) + Math.abs(center.lng) > 180) {
if (tr.renderWorldCopies && Math.abs(tr.center.lng) + Math.abs(center.lng) > 180) {
if (tr.center.lng > 0 && center.lng < 0) {
center.lng += 360;
} else if (tr.center.lng < 0 && center.lng > 0) {
Expand Down
51 changes: 43 additions & 8 deletions test/unit/ui/camera.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@ const fixedNum = fixed.Num;

test('camera', (t) => {
function createCamera(options) {
const transform = new Transform(0, 20);
transform.resize(512, 512);

const camera = new Camera(transform, {});
options = options || {};

if (options) {
camera.jumpTo(options);
}
const transform = new Transform(0, 20, options.renderWorldCopies);
transform.resize(512, 512);

return camera;
return new Camera(transform, {})
.jumpTo(options);
}

t.test('#jumpTo', (t) => {
Expand Down Expand Up @@ -1011,6 +1008,44 @@ test('camera', (t) => {
camera.flyTo({ center: [170, 0], duration: 10 });
});

t.test('does not pan eastward across the antimeridian if no world copies', (t) => {
const camera = createCamera({renderWorldCopies: false});
camera.setCenter([170, 0]);
let crossedAntimeridian;

camera.on('move', () => {
if (camera.getCenter().lng > 170) {
crossedAntimeridian = true;
}
});

camera.on('moveend', () => {
t.notOk(crossedAntimeridian);
t.end();
});

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

t.test('does not pan westward across the antimeridian if no world copies', (t) => {
const camera = createCamera({renderWorldCopies: false});
camera.setCenter([-170, 0]);
let crossedAntimeridian;

camera.on('move', () => {
if (camera.getCenter().lng < -170) {
crossedAntimeridian = true;
}
});

camera.on('moveend', () => {
t.notOk(crossedAntimeridian);
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 9941dde

Please sign in to comment.