From b383e0ecb256641e736b187f7ddac64df8b4a314 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 19 Feb 2017 17:09:41 -0700 Subject: [PATCH] Add view.getMaxZoom() and view.getMinZoom() --- src/ol/view.js | 20 ++++++++++++++++++++ test/spec/ol/view.test.js | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/src/ol/view.js b/src/ol/view.js index b83a2e28d4..7b6c206d21 100644 --- a/src/ol/view.js +++ b/src/ol/view.js @@ -528,6 +528,26 @@ ol.View.prototype.getMinResolution = function() { }; +/** + * Get the maximum zoom level for the view. + * @return {number} The maximum zoom level. + * @api + */ +ol.View.prototype.getMaxZoom = function() { + return /** @type {number} */ (this.getZoomForResolution(this.minResolution_)); +}; + + +/** + * Get the minimum zoom level for the view. + * @return {number} The minimum zoom level. + * @api + */ +ol.View.prototype.getMinZoom = function() { + return /** @type {number} */ (this.getZoomForResolution(this.maxResolution_)); +}; + + /** * Get the view projection. * @return {ol.proj.Projection} The projection of the view. diff --git a/test/spec/ol/view.test.js b/test/spec/ol/view.test.js index 4196cac145..d12505d538 100644 --- a/test/spec/ol/view.test.js +++ b/test/spec/ol/view.test.js @@ -904,6 +904,38 @@ describe('ol.View', function() { }); + describe('#getMaxZoom', function() { + + it('returns the zoom level for the min resolution', function() { + var view = new ol.View(); + expect(view.getMaxZoom()).to.be(view.getZoomForResolution(view.getMinResolution())); + }); + + it('works for a view configured with a maxZoom', function() { + var view = new ol.View({ + maxZoom: 10 + }); + expect(view.getMaxZoom()).to.be(10); + }); + + }); + + describe('#getMinZoom', function() { + + it('returns the zoom level for the max resolution', function() { + var view = new ol.View(); + expect(view.getMinZoom()).to.be(view.getZoomForResolution(view.getMaxResolution())); + }); + + it('works for views configured with a minZoom', function() { + var view = new ol.View({ + minZoom: 3 + }); + expect(view.getMinZoom()).to.be(3); + }); + + }); + describe('#calculateExtent', function() { it('returns the expected extent', function() { var view = new ol.View({