@@ -6,6 +6,7 @@ goog.require('ol');
|
||||
goog.require('ol.Object');
|
||||
goog.require('ol.easing');
|
||||
goog.require('ol.interaction.Property');
|
||||
goog.require('ol.math');
|
||||
|
||||
|
||||
/**
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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 {
|
||||
|
||||
@@ -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({
|
||||
@@ -1438,5 +1488,4 @@ describe('ol.View.isNoopAnimation()', function() {
|
||||
expect(noop).to.equal(c.noop);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user