Skip to content

Commit

Permalink
Merge e745c63 into 5ed2f32
Browse files Browse the repository at this point in the history
  • Loading branch information
cs09g committed Nov 28, 2017
2 parents 5ed2f32 + e745c63 commit f54c1fd
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/ol/interaction/interaction.js
Expand Up @@ -6,6 +6,7 @@ goog.require('ol');
goog.require('ol.Object');
goog.require('ol.easing');
goog.require('ol.interaction.Property');
goog.require('ol.math');


/**
Expand Down Expand Up @@ -181,6 +182,14 @@ ol.interaction.Interaction.zoomByDelta = function(view, delta, opt_anchor, opt_d
var currentResolution = view.getResolution();
var resolution = view.constrainResolution(currentResolution, delta, 0);

if (resolution !== undefined) {
var resolutions = view.getResolutions();
resolution = ol.math.clamp(
resolution,
view.getMinResolution() || resolutions[resolutions.length - 1],
view.getMaxResolution() || resolutions[0]);
}

// If we have a constraint on center, we need to change the anchor so that the
// new center is within the extent. We first calculate the new center, apply
// the constraint to it, and then calculate back the anchor
Expand Down
13 changes: 10 additions & 3 deletions src/ol/view.js
Expand Up @@ -180,6 +180,12 @@ ol.View.prototype.applyOptions_ = function(options) {
} else if (options.zoom !== undefined) {
properties[ol.ViewProperty.RESOLUTION] = this.constrainResolution(
this.maxResolution_, options.zoom - this.minZoom_);

if (this.resolutions_) { // in case map zoom is out of min/max zoom range
properties[ol.ViewProperty.RESOLUTION] = ol.math.clamp(
Number(this.getResolution() || properties[ol.ViewProperty.RESOLUTION]),
this.minResolution_, this.maxResolution_);
}
}
properties[ol.ViewProperty.ROTATION] =
options.rotation !== undefined ? options.rotation : 0;
Expand Down Expand Up @@ -815,7 +821,7 @@ ol.View.prototype.getZoomForResolution = function(resolution) {
var max, zoomFactor;
if (this.resolutions_) {
var nearest = ol.array.linearFindNearest(this.resolutions_, resolution, 1);
offset += nearest;
offset = nearest;
max = this.resolutions_[nearest];
if (nearest == this.resolutions_.length - 1) {
zoomFactor = 2;
Expand Down Expand Up @@ -1103,8 +1109,9 @@ ol.View.createResolutionConstraint_ = function(options) {

if (options.resolutions !== undefined) {
var resolutions = options.resolutions;
maxResolution = resolutions[0];
minResolution = resolutions[resolutions.length - 1];
maxResolution = resolutions[minZoom];
minResolution = resolutions[maxZoom] !== undefined ?
resolutions[maxZoom] : resolutions[resolutions.length - 1];
resolutionConstraint = ol.ResolutionConstraint.createSnapToResolutions(
resolutions);
} else {
Expand Down
51 changes: 50 additions & 1 deletion test/spec/ol/view.test.js
Expand Up @@ -1147,6 +1147,56 @@ describe('ol.View', function() {

});

describe('#setMaxZoom', function() {
describe('with resolutions property in view', function() {
it('changes the zoom level when the level is over max zoom', function() {
var view = new ol.View({
resolutions: [100000, 50000, 25000, 12500, 6250, 3125],
zoom: 4
});

view.setMaxZoom(2);
expect(view.getZoom()).to.be(2);
});
});

describe('with no resolutions property in view', function() {
it('changes the zoom level when the level is over max zoom', function() {
var view = new ol.View({
zoom: 4
});

view.setMaxZoom(2);
expect(view.getZoom()).to.be(2);
});
});
});

describe('#setMinZoom', function() {
describe('with resolutions property in view', function() {
it('changes the zoom level when the level is under min zoom', function() {
var view = new ol.View({
resolutions: [100000, 50000, 25000, 12500, 6250, 3125],
zoom: 4
});

view.setMinZoom(5);
expect(view.getZoom()).to.be(5);
});
});

describe('with no resolutions property in view', function() {
it('changes the zoom level when the level is under min zoom', function() {
var view = new ol.View({
zoom: 4
});

view.setMinZoom(5);
expect(view.getZoom()).to.be(5);
});
});
});

describe('#calculateExtent', function() {
it('returns the expected extent', function() {
var view = new ol.View({
Expand Down Expand Up @@ -1438,5 +1488,4 @@ describe('ol.View.isNoopAnimation()', function() {
expect(noop).to.equal(c.noop);
});
});

});

0 comments on commit f54c1fd

Please sign in to comment.