Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanitize flyto's zoom parameter to clamp between map's minzoom and maxzoom #4726

Merged
merged 2 commits into from
May 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ui/camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ class Camera extends Evented {
startBearing = this.getBearing(),
startPitch = this.getPitch();

const zoom = 'zoom' in options ? +options.zoom : startZoom;
const zoom = 'zoom' in options ? util.clamp(+options.zoom, tr.minZoom, tr.maxZoom) : startZoom;
const bearing = 'bearing' in options ? this._normalizeBearing(options.bearing, startBearing) : startBearing;
const pitch = 'pitch' in options ? +options.pitch : startPitch;

Expand Down
40 changes: 40 additions & 0 deletions test/unit/ui/camera.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,46 @@ test('camera', (t) => {
camera.flyTo(options);
});

t.test('respects transform\'s maxZoom', (t) => {

const transform = new Transform(2, 10, false);
transform.resize(512, 512);

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

camera.on('moveend', () => {
t.equalWithPrecision(camera.getZoom(), 10, 1e-10);
const { lng, lat } = camera.getCenter();
t.equalWithPrecision(lng, 12, 1e-10);
t.equalWithPrecision(lat, 34, 1e-10);

t.end();
});

const flyOptions = { center: [12, 34], zoom: 30};
camera.flyTo(flyOptions);
});

t.test('respects transform\'s minZoom', (t) => {

const transform = new Transform(2, 10, false);
transform.resize(512, 512);

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

camera.on('moveend', () => {
t.equalWithPrecision(camera.getZoom(), 2, 1e-10);
const { lng, lat } = camera.getCenter();
t.equalWithPrecision(lng, 12, 1e-10);
t.equalWithPrecision(lat, 34, 1e-10);

t.end();
});

const flyOptions = { center: [12, 34], zoom: 1};
camera.flyTo(flyOptions);
});

t.end();
});

Expand Down