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

min and max zoom getters #3592

Merged
merged 1 commit into from
Nov 11, 2016
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
15 changes: 15 additions & 0 deletions js/ui/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,13 @@ class Map extends Camera {
} else throw new Error(`minZoom must be between ${defaultMinZoom} and the current maxZoom, inclusive`);
}

/**
* Returns the map's minimum allowable zoom level.
*
* @returns {number} minZoom
*/
getMinZoom() { return this.transform.minZoom; }

/**
* Sets or clears the map's maximum zoom level.
* If the map's current zoom level is higher than the new maximum,
Expand All @@ -445,6 +452,14 @@ class Map extends Camera {

} else throw new Error(`maxZoom must be between the current minZoom and ${defaultMaxZoom}, inclusive`);
}

/**
* Returns the map's maximum allowable zoom level.
*
* @returns {number} maxZoom
*/
getMaxZoom() { return this.transform.maxZoom; }

/**
* Returns a [`Point`](#Point) representing pixel coordinates, relative to the map's `container`,
* that correspond to the specified geographical location.
Expand Down
16 changes: 16 additions & 0 deletions test/js/ui/map.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,14 @@ test('Map', (t) => {
t.end();
});

t.test('#getMinZoom', (t) => {
const map = createMap({zoom: 0});
t.equal(map.getMinZoom(), 0, 'returns default value');
map.setMinZoom(10);
t.equal(map.getMinZoom(), 10, 'returns custom value');
t.end();
});

t.test('ignore minZooms over maxZoom', (t) => {
const map = createMap({zoom:2, maxZoom:5});
t.throws(() => {
Expand All @@ -485,6 +493,14 @@ test('Map', (t) => {
t.end();
});

t.test('#getMaxZoom', (t) => {
const map = createMap({zoom: 0});
t.equal(map.getMaxZoom(), 20, 'returns default value');
map.setMaxZoom(10);
t.equal(map.getMaxZoom(), 10, 'returns custom value');
t.end();
});

t.test('ignore maxZooms over minZoom', (t) => {
const map = createMap({minZoom:5});
t.throws(() => {
Expand Down