Skip to content

Commit

Permalink
Merge pull request #1226 from OpenGeoscience/endclamp-transition-option
Browse files Browse the repository at this point in the history
perf: Make clamping at the end of a map transition optional.
  • Loading branch information
manthey authored Jun 22, 2022
2 parents 4deaf91 + b597811 commit b37bd83
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,18 +407,22 @@ var map = function (arg) {
* center.
* @param {boolean} [ignoreDiscreteZoom] If `true`, ignore the discreteZoom
* option when determining the new view.
* @param {boolean} [ignoreClampBounds] If `true`, ignore the clampBounds
* option when determining the new view.
* @returns {number|this}
* @fires geo.event.zoom
* @fires geo.event.pan
*/
this.zoom = function (val, origin, ignoreDiscreteZoom) {
this.zoom = function (val, origin, ignoreDiscreteZoom, ignoreClampBounds) {
if (val === undefined) {
return m_zoom;
}
var evt, bounds;
/* If we are zooming around a point, ignore the clamp bounds */
var aroundPoint = (origin && (origin.mapgcs || origin.geo) && origin.map);
var ignoreClampBounds = aroundPoint;
if (aroundPoint) {
ignoreClampBounds = true;
}

/* The ignoreDiscreteZoom flag is intended to allow non-integer zoom values
* during animation. */
Expand Down Expand Up @@ -446,7 +450,7 @@ var map = function (arg) {
m_this.pan({x: origin.map.x - shifted.x, y: origin.map.y - shifted.y},
ignoreDiscreteZoom, true);
} else {
m_this.pan({x: 0, y: 0}, ignoreDiscreteZoom);
m_this.pan({x: 0, y: 0}, ignoreDiscreteZoom, ignoreClampBounds);
}
return m_this;
};
Expand Down Expand Up @@ -1101,6 +1105,8 @@ var map = function (arg) {
* a value based on what canceled a transition, `transition`: the current
* transition that just completed, `next`: a boolean if another transition
* follows immediately.
* @param {boolean} [opts.endClamp=true] If `false`, the last center change
* will not clamp to the bounds and zoom values.
* @param {string|geo.transform|null} [gcs] Input gcs. `undefined` to use
* the interface gcs, `null` to use the map gcs, or any other transform.
* Applies only to `opts.center` and to converting zoom values to height,
Expand Down Expand Up @@ -1205,7 +1211,8 @@ var map = function (arg) {
zCoord: opts.zCoord,
done: opts.done,
duration: opts.duration,
zoomOrigin: opts.zoomOrigin
zoomOrigin: opts.zoomOrigin,
endClamp: opts.endClamp
};

m_transition.interp = opts.interp([
Expand Down Expand Up @@ -1260,9 +1267,10 @@ var map = function (arg) {
if (!next) {
if (m_transition.end.center) {
var needZoom = m_zoom !== m_this._fix_zoom(m_transition.end.zoom);
m_this.center(m_transition.end.center, null, needZoom, needZoom);
var noEndClamp = needZoom || opts.endClamp === false;
m_this.center(m_transition.end.center, null, noEndClamp, noEndClamp);
}
m_this.zoom(m_transition.end.zoom, m_transition.zoomOrigin);
m_this.zoom(m_transition.end.zoom, m_transition.zoomOrigin, opts.endClamp === false, opts.endClamp === false);
m_this.rotation(fix_rotation(m_transition.end.rotation));
}

Expand Down Expand Up @@ -1297,7 +1305,7 @@ var map = function (arg) {
}, null, true, true);
} else {
m_center = m_this.gcsToWorld({x: p[0], y: p[1]}, null);
m_this.zoom(p[2], m_transition.zoomOrigin, true);
m_this.zoom(p[2], m_transition.zoomOrigin, true, true);
}
m_this.rotation(p[3], undefined, true);

Expand Down

0 comments on commit b37bd83

Please sign in to comment.