diff --git a/src/ol/interaction/dragrotateandzoominteraction.js b/src/ol/interaction/dragrotateandzoominteraction.js index 1dc1bd79ca..be44ef90a9 100644 --- a/src/ol/interaction/dragrotateandzoominteraction.js +++ b/src/ol/interaction/dragrotateandzoominteraction.js @@ -7,6 +7,7 @@ goog.require('goog.math.Vec2'); goog.require('ol.View2D'); goog.require('ol.interaction.ConditionType'); goog.require('ol.interaction.Drag'); +goog.require('ol.interaction.Interaction'); @@ -62,7 +63,8 @@ ol.interaction.DragRotateAndZoom.prototype.handleDrag = // map.withFrozenRendering but an assertion fails :-( if (goog.isDef(this.lastAngle_)) { var angleDelta = theta - this.lastAngle_; - view.rotate(map, view.getRotation() - angleDelta); + ol.interaction.Interaction.rotate( + map, view, view.getRotation() - angleDelta); } this.lastAngle_ = theta; if (goog.isDef(this.lastMagnitude_)) { diff --git a/src/ol/interaction/dragrotateinteraction.js b/src/ol/interaction/dragrotateinteraction.js index aa928d8beb..e922a31454 100644 --- a/src/ol/interaction/dragrotateinteraction.js +++ b/src/ol/interaction/dragrotateinteraction.js @@ -5,6 +5,7 @@ goog.require('ol.View2D'); goog.require('ol.ViewHint'); goog.require('ol.interaction.ConditionType'); goog.require('ol.interaction.Drag'); +goog.require('ol.interaction.Interaction'); /** @@ -54,7 +55,8 @@ ol.interaction.DragRotate.prototype.handleDrag = function(mapBrowserEvent) { // FIXME supports View2D only goog.asserts.assertInstanceof(view, ol.View2D); map.requestRenderFrame(); - view.rotateWithoutConstraints(map, view.getRotation() - delta); + ol.interaction.Interaction.rotateWithoutConstraints( + map, view, view.getRotation() - delta); } this.lastAngle_ = theta; }; @@ -69,7 +71,7 @@ ol.interaction.DragRotate.prototype.handleDragEnd = function(mapBrowserEvent) { // FIXME supports View2D only var view = map.getView(); goog.asserts.assertInstanceof(view, ol.View2D); - view.rotate(map, view.getRotation(), undefined, + ol.interaction.Interaction.rotate(map, view, view.getRotation(), undefined, ol.interaction.DRAGROTATE_ANIMATION_DURATION); view.setHint(ol.ViewHint.INTERACTING, -1); }; diff --git a/src/ol/interaction/interaction.js b/src/ol/interaction/interaction.js index fd51b430a5..af3ab89131 100644 --- a/src/ol/interaction/interaction.js +++ b/src/ol/interaction/interaction.js @@ -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); + } + } +}; diff --git a/src/ol/interaction/touchrotateinteraction.js b/src/ol/interaction/touchrotateinteraction.js index ac43b51f5a..c0d2e696cc 100644 --- a/src/ol/interaction/touchrotateinteraction.js +++ b/src/ol/interaction/touchrotateinteraction.js @@ -6,6 +6,7 @@ goog.require('goog.asserts'); goog.require('goog.style'); goog.require('ol.View'); goog.require('ol.ViewHint'); +goog.require('ol.interaction.Interaction'); goog.require('ol.interaction.Touch'); @@ -86,7 +87,6 @@ ol.interaction.TouchRotate.prototype.handleTouchMove = this.lastAngle_ = angle; var map = mapBrowserEvent.map; - var view = map.getView(); // rotate anchor point. // FIXME: should be the intersection point between the lines: @@ -99,8 +99,9 @@ ol.interaction.TouchRotate.prototype.handleTouchMove = // rotate if (this.rotating_) { - view.rotateWithoutConstraints(map, view.getRotation() + rotationDelta, - anchor); + var view = map.getView().getView2D(); + ol.interaction.Interaction.rotateWithoutConstraints(map, view, + view.getRotation() + rotationDelta, anchor); } }; @@ -112,9 +113,10 @@ ol.interaction.TouchRotate.prototype.handleTouchEnd = function(mapBrowserEvent) { if (this.targetTouches.length < 2) { var map = mapBrowserEvent.map; - var view = map.getView(); + var view = map.getView().getView2D(); if (this.rotating_) { - view.rotate(map, view.getRotation(), undefined, + ol.interaction.Interaction.rotate( + map, view, view.getRotation(), undefined, ol.interaction.TOUCHROTATE_ANIMATION_DURATION); } view.setHint(ol.ViewHint.INTERACTING, -1); diff --git a/src/ol/view2d.js b/src/ol/view2d.js index 6dd6b333b7..1990114237 100644 --- a/src/ol/view2d.js +++ b/src/ol/view2d.js @@ -376,59 +376,6 @@ goog.exportProperty( ol.View2D.prototype.setRotation); -/** - * @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.rotate = - function(map, rotation, opt_anchor, opt_duration) { - rotation = this.constrainRotation(rotation, 0); - this.rotateWithoutConstraints(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.rotateWithoutConstraints = - 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) && - 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 = this.calculateCenterRotate(rotation, opt_anchor); - map.withFrozenRendering(function() { - this.setCenter(center); - this.setRotation(rotation); - }, this); - } else { - this.setRotation(rotation); - } - } -}; - - /** * @param {ol.Map} map Map. * @param {number|undefined} resolution Resolution to go to.