Move rotate from View2D to Interaction

This commit is contained in:
Éric Lemoine
2013-04-09 18:05:19 +02:00
parent 51094139a8
commit dbca68650c
5 changed files with 70 additions and 61 deletions

View File

@@ -43,3 +43,59 @@ ol.interaction.Interaction.pan = function(
view.setCenter([currentCenter[0] + delta[0], currentCenter[1] + delta[1]]);
}
};
/**
* @param {ol.Map} map Map.
* @param {ol.View2D} view View.
* @param {number|undefined} rotation Rotation.
* @param {ol.Coordinate=} opt_anchor Anchor coordinate.
* @param {number=} opt_duration Duration.
*/
ol.interaction.Interaction.rotate =
function(map, view, rotation, opt_anchor, opt_duration) {
rotation = view.constrainRotation(rotation, 0);
ol.interaction.Interaction.rotateWithoutConstraints(
map, view, rotation, opt_anchor, opt_duration);
};
/**
* @param {ol.Map} map Map.
* @param {ol.View2D} view View.
* @param {number|undefined} rotation Rotation.
* @param {ol.Coordinate=} opt_anchor Anchor coordinate.
* @param {number=} opt_duration Duration.
*/
ol.interaction.Interaction.rotateWithoutConstraints =
function(map, view, rotation, opt_anchor, opt_duration) {
if (goog.isDefAndNotNull(rotation)) {
var currentRotation = view.getRotation();
var currentCenter = view.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: ol.easing.easeOut
}));
if (goog.isDef(opt_anchor)) {
map.addPreRenderFunction(ol.animation.pan({
source: currentCenter,
duration: opt_duration,
easing: ol.easing.easeOut
}));
}
}
if (goog.isDefAndNotNull(opt_anchor)) {
var center = view.calculateCenterRotate(rotation, opt_anchor);
map.withFrozenRendering(function() {
view.setCenter(center);
view.setRotation(rotation);
});
} else {
view.setRotation(rotation);
}
}
};