Skip to content

Commit

Permalink
min and max zoom getters
Browse files Browse the repository at this point in the history
lint errors
  • Loading branch information
mapsam committed Nov 11, 2016
1 parent 47a0e69 commit 169d62f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
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

0 comments on commit 169d62f

Please sign in to comment.