Move rotate from View2D to Interaction
This commit is contained in:
@@ -7,6 +7,7 @@ goog.require('goog.math.Vec2');
|
|||||||
goog.require('ol.View2D');
|
goog.require('ol.View2D');
|
||||||
goog.require('ol.interaction.ConditionType');
|
goog.require('ol.interaction.ConditionType');
|
||||||
goog.require('ol.interaction.Drag');
|
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 :-(
|
// map.withFrozenRendering but an assertion fails :-(
|
||||||
if (goog.isDef(this.lastAngle_)) {
|
if (goog.isDef(this.lastAngle_)) {
|
||||||
var angleDelta = theta - 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;
|
this.lastAngle_ = theta;
|
||||||
if (goog.isDef(this.lastMagnitude_)) {
|
if (goog.isDef(this.lastMagnitude_)) {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ goog.require('ol.View2D');
|
|||||||
goog.require('ol.ViewHint');
|
goog.require('ol.ViewHint');
|
||||||
goog.require('ol.interaction.ConditionType');
|
goog.require('ol.interaction.ConditionType');
|
||||||
goog.require('ol.interaction.Drag');
|
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
|
// FIXME supports View2D only
|
||||||
goog.asserts.assertInstanceof(view, ol.View2D);
|
goog.asserts.assertInstanceof(view, ol.View2D);
|
||||||
map.requestRenderFrame();
|
map.requestRenderFrame();
|
||||||
view.rotateWithoutConstraints(map, view.getRotation() - delta);
|
ol.interaction.Interaction.rotateWithoutConstraints(
|
||||||
|
map, view, view.getRotation() - delta);
|
||||||
}
|
}
|
||||||
this.lastAngle_ = theta;
|
this.lastAngle_ = theta;
|
||||||
};
|
};
|
||||||
@@ -69,7 +71,7 @@ ol.interaction.DragRotate.prototype.handleDragEnd = function(mapBrowserEvent) {
|
|||||||
// FIXME supports View2D only
|
// FIXME supports View2D only
|
||||||
var view = map.getView();
|
var view = map.getView();
|
||||||
goog.asserts.assertInstanceof(view, ol.View2D);
|
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);
|
ol.interaction.DRAGROTATE_ANIMATION_DURATION);
|
||||||
view.setHint(ol.ViewHint.INTERACTING, -1);
|
view.setHint(ol.ViewHint.INTERACTING, -1);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -43,3 +43,59 @@ ol.interaction.Interaction.pan = function(
|
|||||||
view.setCenter([currentCenter[0] + delta[0], currentCenter[1] + delta[1]]);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ goog.require('goog.asserts');
|
|||||||
goog.require('goog.style');
|
goog.require('goog.style');
|
||||||
goog.require('ol.View');
|
goog.require('ol.View');
|
||||||
goog.require('ol.ViewHint');
|
goog.require('ol.ViewHint');
|
||||||
|
goog.require('ol.interaction.Interaction');
|
||||||
goog.require('ol.interaction.Touch');
|
goog.require('ol.interaction.Touch');
|
||||||
|
|
||||||
|
|
||||||
@@ -86,7 +87,6 @@ ol.interaction.TouchRotate.prototype.handleTouchMove =
|
|||||||
this.lastAngle_ = angle;
|
this.lastAngle_ = angle;
|
||||||
|
|
||||||
var map = mapBrowserEvent.map;
|
var map = mapBrowserEvent.map;
|
||||||
var view = map.getView();
|
|
||||||
|
|
||||||
// rotate anchor point.
|
// rotate anchor point.
|
||||||
// FIXME: should be the intersection point between the lines:
|
// FIXME: should be the intersection point between the lines:
|
||||||
@@ -99,8 +99,9 @@ ol.interaction.TouchRotate.prototype.handleTouchMove =
|
|||||||
|
|
||||||
// rotate
|
// rotate
|
||||||
if (this.rotating_) {
|
if (this.rotating_) {
|
||||||
view.rotateWithoutConstraints(map, view.getRotation() + rotationDelta,
|
var view = map.getView().getView2D();
|
||||||
anchor);
|
ol.interaction.Interaction.rotateWithoutConstraints(map, view,
|
||||||
|
view.getRotation() + rotationDelta, anchor);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -112,9 +113,10 @@ ol.interaction.TouchRotate.prototype.handleTouchEnd =
|
|||||||
function(mapBrowserEvent) {
|
function(mapBrowserEvent) {
|
||||||
if (this.targetTouches.length < 2) {
|
if (this.targetTouches.length < 2) {
|
||||||
var map = mapBrowserEvent.map;
|
var map = mapBrowserEvent.map;
|
||||||
var view = map.getView();
|
var view = map.getView().getView2D();
|
||||||
if (this.rotating_) {
|
if (this.rotating_) {
|
||||||
view.rotate(map, view.getRotation(), undefined,
|
ol.interaction.Interaction.rotate(
|
||||||
|
map, view, view.getRotation(), undefined,
|
||||||
ol.interaction.TOUCHROTATE_ANIMATION_DURATION);
|
ol.interaction.TOUCHROTATE_ANIMATION_DURATION);
|
||||||
}
|
}
|
||||||
view.setHint(ol.ViewHint.INTERACTING, -1);
|
view.setHint(ol.ViewHint.INTERACTING, -1);
|
||||||
|
|||||||
@@ -376,59 +376,6 @@ goog.exportProperty(
|
|||||||
ol.View2D.prototype.setRotation);
|
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 {ol.Map} map Map.
|
||||||
* @param {number|undefined} resolution Resolution to go to.
|
* @param {number|undefined} resolution Resolution to go to.
|
||||||
|
|||||||
Reference in New Issue
Block a user