From 91dda5e5cac771b114b69b4341a5a5484b66f06f Mon Sep 17 00:00:00 2001 From: Olivier Guyot Date: Mon, 25 Mar 2019 11:50:45 +0100 Subject: [PATCH] View / refactor initialization with resolution constraint This also makes it possible to call `solveConstraints_` with a duration of 0, which means the target values are modified straight away without triggering an animation or leaving the current flow. --- src/ol/View.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/ol/View.js b/src/ol/View.js index 6342888e37..b9c694c48d 100644 --- a/src/ol/View.js +++ b/src/ol/View.js @@ -375,17 +375,13 @@ class View extends BaseObject { if (options.resolution !== undefined) { this.setResolution(options.resolution); } else if (options.zoom !== undefined) { - if (this.resolutions_) { // in case map zoom is out of min/max zoom range - const resolution = this.getResolutionForZoom(options.zoom); - this.setResolution(clamp(resolution, - this.minResolution_, this.maxResolution_)); - } else { - this.setZoom(options.zoom); - } + this.setZoom(options.zoom); } + this.resolveConstraints_(0); this.setProperties(properties); + /** * @private * @type {ViewOptions} @@ -1283,6 +1279,8 @@ class View extends BaseObject { /** * If any constraints need to be applied, an animation will be triggered. * This is typically done on interaction end. + * Note: calling this with a duration of 0 will apply the constrained values straight away, + * without animation. * @param {number=} opt_duration The animation duration in ms. * @param {number=} opt_resolutionDirection Which direction to zoom. * @param {import("./coordinate.js").Coordinate=} opt_anchor The origin of the transformation. @@ -1297,6 +1295,14 @@ class View extends BaseObject { const newResolution = this.constraints_.resolution(this.targetResolution_, direction, size); const newCenter = this.constraints_.center(this.targetCenter_, newResolution, size); + if (duration === 0) { + this.targetResolution_ = newResolution; + this.targetRotation_ = newRotation; + this.targetCenter_ = newCenter; + this.applyTargetState_(); + return; + } + if (this.getResolution() !== newResolution || this.getRotation() !== newRotation || !this.getCenter() ||