Merge pull request #9374 from jahow/fix-initialzoom

Fix view initialization with min/max resolution constraint
This commit is contained in:
Andreas Hocevar
2019-03-25 14:33:25 +01:00
committed by GitHub
5 changed files with 91 additions and 22 deletions

View File

@@ -964,6 +964,10 @@ class PluggableMap extends BaseObject {
* @private
*/
handleSizeChanged_() {
if (this.getView()) {
this.getView().resolveConstraints(0);
}
this.render();
}
@@ -1051,6 +1055,8 @@ class PluggableMap extends BaseObject {
this.viewChangeListenerKey_ = listen(
view, EventType.CHANGE,
this.handleViewPropertyChanged_, this);
view.resolveConstraints(0);
}
this.render();
}

View File

@@ -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}
@@ -648,7 +644,7 @@ class View extends BaseObject {
}
if (!this.getAnimating()) {
setTimeout(this.resolveConstraints_.bind(this), 0);
setTimeout(this.resolveConstraints.bind(this), 0);
}
}
@@ -1283,12 +1279,13 @@ 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.
* @private
*/
resolveConstraints_(opt_duration, opt_resolutionDirection, opt_anchor) {
resolveConstraints(opt_duration, opt_resolutionDirection, opt_anchor) {
const duration = opt_duration !== undefined ? opt_duration : 200;
const direction = opt_resolutionDirection || 0;
@@ -1297,6 +1294,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() ||
@@ -1336,7 +1341,7 @@ class View extends BaseObject {
endInteraction(opt_duration, opt_resolutionDirection, opt_anchor) {
this.setHint(ViewHint.INTERACTING, -1);
this.resolveConstraints_(opt_duration, opt_resolutionDirection, opt_anchor);
this.resolveConstraints(opt_duration, opt_resolutionDirection, opt_anchor);
}
/**