2DView refactoring

This refactoring makes animating zoom, as opposed to zoomByDelta, possible.
This commit is contained in:
Éric Lemoine
2013-03-04 20:51:45 +01:00
committed by Tim Schaub
parent b9a286fb7a
commit a4c47edd9d
+36 -25
View File
@@ -263,6 +263,20 @@ goog.exportProperty(
*/
ol.View2D.prototype.rotate =
function(map, rotation, opt_anchor, opt_duration) {
rotation = this.constraints_.rotation(rotation, 0);
this.rotateNoConstraint(map, rotation, opt_anchor, opt_duration);
};
/**
* @param {ol.Map} map Map.
* @param {number|undefined} rotation Rotation.
* @param {ol.Coordinate=} opt_anchor Anchor coordinate.
* @param {number=} opt_duration Duration.
*/
ol.View2D.prototype.rotateNoConstraint =
function(map, rotation, opt_anchor, opt_duration) {
if (goog.isDefAndNotNull(rotation)) {
var currentRotation = this.getRotation();
var currentCenter = this.getCenter();
if (goog.isDef(currentRotation) && goog.isDef(currentCenter) &&
@@ -281,17 +295,6 @@ ol.View2D.prototype.rotate =
}));
}
}
rotation = this.constraints_.rotation(rotation, 0);
this.rotateNoConstraint(map, rotation, opt_anchor);
};
/**
* @param {ol.Map} map Map.
* @param {number|undefined} rotation Rotation.
* @param {ol.Coordinate=} opt_anchor Anchor coordinate.
*/
ol.View2D.prototype.rotateNoConstraint = function(map, rotation, opt_anchor) {
if (goog.isDefAndNotNull(opt_anchor)) {
var anchor = opt_anchor;
var oldCenter = /** @type {!ol.Coordinate} */ (this.getCenter());
@@ -308,6 +311,7 @@ ol.View2D.prototype.rotateNoConstraint = function(map, rotation, opt_anchor) {
} else {
this.setRotation(rotation);
}
}
};
@@ -315,10 +319,12 @@ ol.View2D.prototype.rotateNoConstraint = function(map, rotation, opt_anchor) {
* @param {ol.Map} map Map.
* @param {number|undefined} resolution Resolution to go to.
* @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);
this.zoomNoConstraint(map, resolution, opt_anchor);
this.zoomNoConstraint(map, resolution, opt_anchor, opt_duration);
};
@@ -331,6 +337,21 @@ ol.View2D.prototype.zoom = function(map, resolution, opt_anchor) {
ol.View2D.prototype.zoomByDelta =
function(map, delta, opt_anchor, opt_duration) {
var currentResolution = this.getResolution();
var resolution = this.constraints_.resolution(currentResolution, delta);
this.zoomNoConstraint(map, resolution, opt_anchor, opt_duration);
};
/**
* @param {ol.Map} map Map.
* @param {number|undefined} resolution Resolution to go to.
* @param {ol.Coordinate=} opt_anchor Anchor coordinate.
* @param {number=} opt_duration Duration.
*/
ol.View2D.prototype.zoomNoConstraint =
function(map, resolution, opt_anchor, opt_duration) {
if (goog.isDefAndNotNull(resolution)) {
var currentResolution = this.getResolution();
var currentCenter = this.getCenter();
if (goog.isDef(currentResolution) && goog.isDef(currentCenter) &&
goog.isDef(opt_duration)) {
@@ -348,18 +369,7 @@ ol.View2D.prototype.zoomByDelta =
}));
}
}
var resolution = this.constraints_.resolution(currentResolution, delta);
this.zoomNoConstraint(map, resolution, opt_anchor);
};
/**
* @param {ol.Map} map Map.
* @param {number|undefined} resolution Resolution to go to.
* @param {ol.Coordinate=} opt_anchor Anchor coordinate.
*/
ol.View2D.prototype.zoomNoConstraint = function(map, resolution, opt_anchor) {
if (goog.isDefAndNotNull(resolution) && goog.isDefAndNotNull(opt_anchor)) {
if (goog.isDefAndNotNull(opt_anchor)) {
var anchor = opt_anchor;
var oldCenter = /** @type {!ol.Coordinate} */ (this.getCenter());
var oldResolution = this.getResolution();
@@ -373,6 +383,7 @@ ol.View2D.prototype.zoomNoConstraint = function(map, resolution, opt_anchor) {
} else {
this.setResolution(resolution);
}
}
};