From 0474103f6b2687ac67c56935f06cba8d17c6bd0e Mon Sep 17 00:00:00 2001 From: Sam Matthews Date: Fri, 11 Nov 2016 10:01:25 -0800 Subject: [PATCH] min and max zoom getters (#3592) --- js/ui/map.js | 15 +++++++++++++++ test/js/ui/map.test.js | 16 ++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/js/ui/map.js b/js/ui/map.js index 62aa217aa07..5e8e779552a 100755 --- a/js/ui/map.js +++ b/js/ui/map.js @@ -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, @@ -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. diff --git a/test/js/ui/map.test.js b/test/js/ui/map.test.js index 142f0364980..938ac550666 100755 --- a/test/js/ui/map.test.js +++ b/test/js/ui/map.test.js @@ -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(() => { @@ -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(() => {