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.
This commit is contained in:
@@ -375,17 +375,13 @@ class View extends BaseObject {
|
|||||||
if (options.resolution !== undefined) {
|
if (options.resolution !== undefined) {
|
||||||
this.setResolution(options.resolution);
|
this.setResolution(options.resolution);
|
||||||
} else if (options.zoom !== undefined) {
|
} else if (options.zoom !== undefined) {
|
||||||
if (this.resolutions_) { // in case map zoom is out of min/max zoom range
|
this.setZoom(options.zoom);
|
||||||
const resolution = this.getResolutionForZoom(options.zoom);
|
|
||||||
this.setResolution(clamp(resolution,
|
|
||||||
this.minResolution_, this.maxResolution_));
|
|
||||||
} else {
|
|
||||||
this.setZoom(options.zoom);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
this.resolveConstraints_(0);
|
||||||
|
|
||||||
this.setProperties(properties);
|
this.setProperties(properties);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {ViewOptions}
|
* @type {ViewOptions}
|
||||||
@@ -1283,6 +1279,8 @@ class View extends BaseObject {
|
|||||||
/**
|
/**
|
||||||
* If any constraints need to be applied, an animation will be triggered.
|
* If any constraints need to be applied, an animation will be triggered.
|
||||||
* This is typically done on interaction end.
|
* 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_duration The animation duration in ms.
|
||||||
* @param {number=} opt_resolutionDirection Which direction to zoom.
|
* @param {number=} opt_resolutionDirection Which direction to zoom.
|
||||||
* @param {import("./coordinate.js").Coordinate=} opt_anchor The origin of the transformation.
|
* @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 newResolution = this.constraints_.resolution(this.targetResolution_, direction, size);
|
||||||
const newCenter = this.constraints_.center(this.targetCenter_, newResolution, 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 ||
|
if (this.getResolution() !== newResolution ||
|
||||||
this.getRotation() !== newRotation ||
|
this.getRotation() !== newRotation ||
|
||||||
!this.getCenter() ||
|
!this.getCenter() ||
|
||||||
|
|||||||
Reference in New Issue
Block a user