Add view.getZoomForResolution()
This commit is contained in:
+16
-2
@@ -659,8 +659,22 @@ ol.View.prototype.getState = function() {
|
|||||||
ol.View.prototype.getZoom = function() {
|
ol.View.prototype.getZoom = function() {
|
||||||
var zoom;
|
var zoom;
|
||||||
var resolution = this.getResolution();
|
var resolution = this.getResolution();
|
||||||
if (resolution !== undefined &&
|
if (resolution !== undefined) {
|
||||||
resolution >= this.minResolution_ && resolution <= this.maxResolution_) {
|
zoom = this.getZoomForResolution(resolution);
|
||||||
|
}
|
||||||
|
return zoom;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the zoom level for a resolution.
|
||||||
|
* @param {number} resolution The resolution.
|
||||||
|
* @return {number|undefined} The zoom level for the provided resolution.
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
ol.View.prototype.getZoomForResolution = function(resolution) {
|
||||||
|
var zoom;
|
||||||
|
if (resolution >= this.minResolution_ && resolution <= this.maxResolution_) {
|
||||||
var offset = this.minZoom_ || 0;
|
var offset = this.minZoom_ || 0;
|
||||||
var max, zoomFactor;
|
var max, zoomFactor;
|
||||||
if (this.resolutions_) {
|
if (this.resolutions_) {
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ goog.require('ol.extent');
|
|||||||
goog.require('ol.geom.LineString');
|
goog.require('ol.geom.LineString');
|
||||||
goog.require('ol.geom.Point');
|
goog.require('ol.geom.Point');
|
||||||
|
|
||||||
|
|
||||||
describe('ol.View', function() {
|
describe('ol.View', function() {
|
||||||
|
|
||||||
describe('constructor (defaults)', function() {
|
describe('constructor (defaults)', function() {
|
||||||
@@ -874,6 +873,37 @@ describe('ol.View', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#getZoomForResolution', function() {
|
||||||
|
|
||||||
|
it('returns correct zoom levels', function() {
|
||||||
|
var view = new ol.View();
|
||||||
|
var max = view.getMaxResolution();
|
||||||
|
|
||||||
|
expect(view.getZoomForResolution(max)).to.be(0);
|
||||||
|
|
||||||
|
expect(view.getZoomForResolution(max / 2)).to.be(1);
|
||||||
|
|
||||||
|
expect(view.getZoomForResolution(max / 4)).to.be(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns correct zoom levels for specifically configured resolutions', function() {
|
||||||
|
var view = new ol.View({
|
||||||
|
resolutions: [10, 8, 6, 4, 2]
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(view.getZoomForResolution(10)).to.be(0);
|
||||||
|
|
||||||
|
expect(view.getZoomForResolution(8)).to.be(1);
|
||||||
|
|
||||||
|
expect(view.getZoomForResolution(6)).to.be(2);
|
||||||
|
|
||||||
|
expect(view.getZoomForResolution(4)).to.be(3);
|
||||||
|
|
||||||
|
expect(view.getZoomForResolution(2)).to.be(4);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
describe('#calculateExtent', function() {
|
describe('#calculateExtent', function() {
|
||||||
it('returns the expected extent', function() {
|
it('returns the expected extent', function() {
|
||||||
var view = new ol.View({
|
var view = new ol.View({
|
||||||
|
|||||||
Reference in New Issue
Block a user