diff --git a/src/ol/View.js b/src/ol/View.js index e114b8e715..ebb4e78395 100644 --- a/src/ol/View.js +++ b/src/ol/View.js @@ -345,13 +345,12 @@ class View extends BaseObject { if (options.resolution !== undefined) { this.setResolution(options.resolution); } else if (options.zoom !== undefined) { - this.setResolution(this.constrainResolution( - this.maxResolution_, options.zoom - this.minZoom_)); - if (this.resolutions_) { // in case map zoom is out of min/max zoom range - this.setResolution(clamp( - Number(this.getResolution() || properties[ViewProperty.RESOLUTION]), + const resolution = this.getResolutionForZoom(options.zoom); + this.setResolution(clamp(resolution, this.minResolution_, this.maxResolution_)); + } else { + this.setZoom(options.zoom); } } diff --git a/src/ol/interaction/DragRotateAndZoom.js b/src/ol/interaction/DragRotateAndZoom.js index 328e135d4b..5225d73001 100644 --- a/src/ol/interaction/DragRotateAndZoom.js +++ b/src/ol/interaction/DragRotateAndZoom.js @@ -4,7 +4,7 @@ import {disable} from '../rotationconstraint.js'; import ViewHint from '../ViewHint.js'; import {shiftKeyOnly, mouseOnly} from '../events/condition.js'; -import {rotate, rotateWithoutConstraints, zoom, zoomWithoutConstraints} from './Interaction.js'; +import {rotate, rotateWithoutConstraints, zoom} from './Interaction.js'; import PointerInteraction from './Pointer.js'; @@ -95,7 +95,7 @@ class DragRotateAndZoom extends PointerInteraction { this.lastAngle_ = theta; if (this.lastMagnitude_ !== undefined) { const resolution = this.lastMagnitude_ * (view.getResolution() / magnitude); - zoomWithoutConstraints(view, resolution); + zoom(view, resolution); } if (this.lastMagnitude_ !== undefined) { this.lastScaleDelta_ = this.lastMagnitude_ / magnitude; diff --git a/src/ol/interaction/Interaction.js b/src/ol/interaction/Interaction.js index 09eb70a397..9a7b817525 100644 --- a/src/ol/interaction/Interaction.js +++ b/src/ol/interaction/Interaction.js @@ -177,8 +177,25 @@ export function rotateWithoutConstraints(view, rotation, opt_anchor, opt_duratio * assumed. */ export function zoom(view, resolution, opt_anchor, opt_duration, opt_direction) { - resolution = view.constrainResolution(resolution, 0, opt_direction); - zoomWithoutConstraints(view, resolution, opt_anchor, opt_duration); + if (resolution) { + const currentResolution = view.getResolution(); + const currentCenter = view.getCenter(); + if (currentResolution !== undefined && currentCenter && + resolution !== currentResolution && opt_duration) { + view.animate({ + resolution: resolution, + anchor: opt_anchor, + duration: opt_duration, + easing: easeOut + }); + } else { + if (opt_anchor) { + const center = view.calculateCenterZoom(resolution, opt_anchor); + view.setCenter(center); + } + view.setResolution(resolution); + } + } } @@ -234,33 +251,4 @@ export function zoomByDelta(view, delta, opt_anchor, opt_duration) { } } - -/** - * @param {import("../View.js").default} view View. - * @param {number|undefined} resolution Resolution to go to. - * @param {import("../coordinate.js").Coordinate=} opt_anchor Anchor coordinate. - * @param {number=} opt_duration Duration. - */ -export function zoomWithoutConstraints(view, resolution, opt_anchor, opt_duration) { - if (resolution) { - const currentResolution = view.getResolution(); - const currentCenter = view.getCenter(); - if (currentResolution !== undefined && currentCenter && - resolution !== currentResolution && opt_duration) { - view.animate({ - resolution: resolution, - anchor: opt_anchor, - duration: opt_duration, - easing: easeOut - }); - } else { - if (opt_anchor) { - const center = view.calculateCenterZoom(resolution, opt_anchor); - view.setCenter(center); - } - view.setResolution(resolution); - } - } -} - export default Interaction; diff --git a/src/ol/interaction/PinchZoom.js b/src/ol/interaction/PinchZoom.js index b6ced12d60..885e69b492 100644 --- a/src/ol/interaction/PinchZoom.js +++ b/src/ol/interaction/PinchZoom.js @@ -3,7 +3,7 @@ */ import ViewHint from '../ViewHint.js'; import {FALSE} from '../functions.js'; -import {zoom, zoomWithoutConstraints} from './Interaction.js'; +import {zoom} from './Interaction.js'; import PointerInteraction, {centroid as centroidFromPointers} from './Pointer.js'; @@ -116,7 +116,7 @@ class PinchZoom extends PointerInteraction { // scale, bypass the resolution constraint map.render(); - zoomWithoutConstraints(view, newResolution, this.anchor_); + zoom(view, newResolution, this.anchor_); } /**