2DView refactoring
This refactoring makes animating zoom, as opposed to zoomByDelta, possible.
This commit is contained in:
+78
-67
@@ -263,26 +263,8 @@ goog.exportProperty(
|
|||||||
*/
|
*/
|
||||||
ol.View2D.prototype.rotate =
|
ol.View2D.prototype.rotate =
|
||||||
function(map, rotation, opt_anchor, opt_duration) {
|
function(map, rotation, opt_anchor, opt_duration) {
|
||||||
var currentRotation = this.getRotation();
|
|
||||||
var currentCenter = this.getCenter();
|
|
||||||
if (goog.isDef(currentRotation) && goog.isDef(currentCenter) &&
|
|
||||||
goog.isDef(opt_duration)) {
|
|
||||||
map.requestRenderFrame();
|
|
||||||
map.addPreRenderFunction(ol.animation.rotate({
|
|
||||||
rotation: currentRotation,
|
|
||||||
duration: opt_duration,
|
|
||||||
easing: goog.fx.easing.easeOut
|
|
||||||
}));
|
|
||||||
if (goog.isDef(opt_anchor)) {
|
|
||||||
map.addPreRenderFunction(ol.animation.pan({
|
|
||||||
source: currentCenter,
|
|
||||||
duration: opt_duration,
|
|
||||||
easing: goog.fx.easing.easeOut
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
rotation = this.constraints_.rotation(rotation, 0);
|
rotation = this.constraints_.rotation(rotation, 0);
|
||||||
this.rotateNoConstraint(map, rotation, opt_anchor);
|
this.rotateNoConstraint(map, rotation, opt_anchor, opt_duration);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -290,23 +272,45 @@ ol.View2D.prototype.rotate =
|
|||||||
* @param {ol.Map} map Map.
|
* @param {ol.Map} map Map.
|
||||||
* @param {number|undefined} rotation Rotation.
|
* @param {number|undefined} rotation Rotation.
|
||||||
* @param {ol.Coordinate=} opt_anchor Anchor coordinate.
|
* @param {ol.Coordinate=} opt_anchor Anchor coordinate.
|
||||||
|
* @param {number=} opt_duration Duration.
|
||||||
*/
|
*/
|
||||||
ol.View2D.prototype.rotateNoConstraint = function(map, rotation, opt_anchor) {
|
ol.View2D.prototype.rotateNoConstraint =
|
||||||
if (goog.isDefAndNotNull(opt_anchor)) {
|
function(map, rotation, opt_anchor, opt_duration) {
|
||||||
var anchor = opt_anchor;
|
if (goog.isDefAndNotNull(rotation)) {
|
||||||
var oldCenter = /** @type {!ol.Coordinate} */ (this.getCenter());
|
var currentRotation = this.getRotation();
|
||||||
var center = new ol.Coordinate(
|
var currentCenter = this.getCenter();
|
||||||
oldCenter.x - anchor.x,
|
if (goog.isDef(currentRotation) && goog.isDef(currentCenter) &&
|
||||||
oldCenter.y - anchor.y);
|
goog.isDef(opt_duration)) {
|
||||||
center.rotate(rotation - this.getRotation());
|
map.requestRenderFrame();
|
||||||
center.x += anchor.x;
|
map.addPreRenderFunction(ol.animation.rotate({
|
||||||
center.y += anchor.y;
|
rotation: currentRotation,
|
||||||
map.withFrozenRendering(function() {
|
duration: opt_duration,
|
||||||
this.setCenter(center);
|
easing: goog.fx.easing.easeOut
|
||||||
|
}));
|
||||||
|
if (goog.isDef(opt_anchor)) {
|
||||||
|
map.addPreRenderFunction(ol.animation.pan({
|
||||||
|
source: currentCenter,
|
||||||
|
duration: opt_duration,
|
||||||
|
easing: goog.fx.easing.easeOut
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (goog.isDefAndNotNull(opt_anchor)) {
|
||||||
|
var anchor = opt_anchor;
|
||||||
|
var oldCenter = /** @type {!ol.Coordinate} */ (this.getCenter());
|
||||||
|
var center = new ol.Coordinate(
|
||||||
|
oldCenter.x - anchor.x,
|
||||||
|
oldCenter.y - anchor.y);
|
||||||
|
center.rotate(rotation - this.getRotation());
|
||||||
|
center.x += anchor.x;
|
||||||
|
center.y += anchor.y;
|
||||||
|
map.withFrozenRendering(function() {
|
||||||
|
this.setCenter(center);
|
||||||
|
this.setRotation(rotation);
|
||||||
|
}, this);
|
||||||
|
} else {
|
||||||
this.setRotation(rotation);
|
this.setRotation(rotation);
|
||||||
}, this);
|
}
|
||||||
} else {
|
|
||||||
this.setRotation(rotation);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -315,10 +319,12 @@ ol.View2D.prototype.rotateNoConstraint = function(map, rotation, opt_anchor) {
|
|||||||
* @param {ol.Map} map Map.
|
* @param {ol.Map} map Map.
|
||||||
* @param {number|undefined} resolution Resolution to go to.
|
* @param {number|undefined} resolution Resolution to go to.
|
||||||
* @param {ol.Coordinate=} opt_anchor Anchor coordinate.
|
* @param {ol.Coordinate=} opt_anchor Anchor coordinate.
|
||||||
|
* @param {number=} opt_duration Duration.
|
||||||
*/
|
*/
|
||||||
ol.View2D.prototype.zoom = function(map, resolution, opt_anchor) {
|
ol.View2D.prototype.zoom =
|
||||||
|
function(map, resolution, opt_anchor, opt_duration) {
|
||||||
resolution = this.constraints_.resolution(resolution, 0);
|
resolution = this.constraints_.resolution(resolution, 0);
|
||||||
this.zoomNoConstraint(map, resolution, opt_anchor);
|
this.zoomNoConstraint(map, resolution, opt_anchor, opt_duration);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -331,25 +337,8 @@ ol.View2D.prototype.zoom = function(map, resolution, opt_anchor) {
|
|||||||
ol.View2D.prototype.zoomByDelta =
|
ol.View2D.prototype.zoomByDelta =
|
||||||
function(map, delta, opt_anchor, opt_duration) {
|
function(map, delta, opt_anchor, opt_duration) {
|
||||||
var currentResolution = this.getResolution();
|
var currentResolution = this.getResolution();
|
||||||
var currentCenter = this.getCenter();
|
|
||||||
if (goog.isDef(currentResolution) && goog.isDef(currentCenter) &&
|
|
||||||
goog.isDef(opt_duration)) {
|
|
||||||
map.requestRenderFrame();
|
|
||||||
map.addPreRenderFunction(ol.animation.zoom({
|
|
||||||
resolution: currentResolution,
|
|
||||||
duration: opt_duration,
|
|
||||||
easing: goog.fx.easing.easeOut
|
|
||||||
}));
|
|
||||||
if (goog.isDef(opt_anchor)) {
|
|
||||||
map.addPreRenderFunction(ol.animation.pan({
|
|
||||||
source: currentCenter,
|
|
||||||
duration: opt_duration,
|
|
||||||
easing: goog.fx.easing.easeOut
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var resolution = this.constraints_.resolution(currentResolution, delta);
|
var resolution = this.constraints_.resolution(currentResolution, delta);
|
||||||
this.zoomNoConstraint(map, resolution, opt_anchor);
|
this.zoomNoConstraint(map, resolution, opt_anchor, opt_duration);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -357,21 +346,43 @@ ol.View2D.prototype.zoomByDelta =
|
|||||||
* @param {ol.Map} map Map.
|
* @param {ol.Map} map Map.
|
||||||
* @param {number|undefined} resolution Resolution to go to.
|
* @param {number|undefined} resolution Resolution to go to.
|
||||||
* @param {ol.Coordinate=} opt_anchor Anchor coordinate.
|
* @param {ol.Coordinate=} opt_anchor Anchor coordinate.
|
||||||
|
* @param {number=} opt_duration Duration.
|
||||||
*/
|
*/
|
||||||
ol.View2D.prototype.zoomNoConstraint = function(map, resolution, opt_anchor) {
|
ol.View2D.prototype.zoomNoConstraint =
|
||||||
if (goog.isDefAndNotNull(resolution) && goog.isDefAndNotNull(opt_anchor)) {
|
function(map, resolution, opt_anchor, opt_duration) {
|
||||||
var anchor = opt_anchor;
|
if (goog.isDefAndNotNull(resolution)) {
|
||||||
var oldCenter = /** @type {!ol.Coordinate} */ (this.getCenter());
|
var currentResolution = this.getResolution();
|
||||||
var oldResolution = this.getResolution();
|
var currentCenter = this.getCenter();
|
||||||
var x = anchor.x - resolution * (anchor.x - oldCenter.x) / oldResolution;
|
if (goog.isDef(currentResolution) && goog.isDef(currentCenter) &&
|
||||||
var y = anchor.y - resolution * (anchor.y - oldCenter.y) / oldResolution;
|
goog.isDef(opt_duration)) {
|
||||||
var center = new ol.Coordinate(x, y);
|
map.requestRenderFrame();
|
||||||
map.withFrozenRendering(function() {
|
map.addPreRenderFunction(ol.animation.zoom({
|
||||||
this.setCenter(center);
|
resolution: currentResolution,
|
||||||
|
duration: opt_duration,
|
||||||
|
easing: goog.fx.easing.easeOut
|
||||||
|
}));
|
||||||
|
if (goog.isDef(opt_anchor)) {
|
||||||
|
map.addPreRenderFunction(ol.animation.pan({
|
||||||
|
source: currentCenter,
|
||||||
|
duration: opt_duration,
|
||||||
|
easing: goog.fx.easing.easeOut
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (goog.isDefAndNotNull(opt_anchor)) {
|
||||||
|
var anchor = opt_anchor;
|
||||||
|
var oldCenter = /** @type {!ol.Coordinate} */ (this.getCenter());
|
||||||
|
var oldResolution = this.getResolution();
|
||||||
|
var x = anchor.x - resolution * (anchor.x - oldCenter.x) / oldResolution;
|
||||||
|
var y = anchor.y - resolution * (anchor.y - oldCenter.y) / oldResolution;
|
||||||
|
var center = new ol.Coordinate(x, y);
|
||||||
|
map.withFrozenRendering(function() {
|
||||||
|
this.setCenter(center);
|
||||||
|
this.setResolution(resolution);
|
||||||
|
}, this);
|
||||||
|
} else {
|
||||||
this.setResolution(resolution);
|
this.setResolution(resolution);
|
||||||
}, this);
|
}
|
||||||
} else {
|
|
||||||
this.setResolution(resolution);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user