Change view.rotate params: rotation and optional anchor.

This commit is contained in:
Frederic Junod
2013-02-13 17:03:06 +01:00
parent 83a00c13fa
commit 34975428c4
3 changed files with 53 additions and 42 deletions

View File

@@ -23,9 +23,9 @@ ol.interaction.DragRotate = function(condition) {
/**
* @private
* @type {number}
* @type {number|undefined}
*/
this.startRotation_ = 0;
this.lastAngle_;
};
goog.inherits(ol.interaction.DragRotate, ol.interaction.Drag);
@@ -39,14 +39,16 @@ ol.interaction.DragRotate.prototype.handleDrag = function(mapBrowserEvent) {
var map = mapBrowserEvent.map;
var size = map.getSize();
var offset = mapBrowserEvent.getPixel();
var theta = Math.atan2(
size.height / 2 - offset.y,
offset.x - size.width / 2);
// FIXME supports View2D only
var view = map.getView();
goog.asserts.assert(view instanceof ol.View2D);
map.requestRenderFrame();
view.rotate(map, this.startRotation_, -theta);
var theta = Math.atan2(size.height / 2 - offset.y, offset.x - size.width / 2);
if (goog.isDef(this.lastAngle_)) {
var delta = theta - this.lastAngle_;
var view = map.getView();
// FIXME supports View2D only
goog.asserts.assert(view instanceof ol.View2D);
map.requestRenderFrame();
view.rotate(map, view.getRotation() - delta);
}
this.lastAngle_ = theta;
};
@@ -56,18 +58,13 @@ ol.interaction.DragRotate.prototype.handleDrag = function(mapBrowserEvent) {
ol.interaction.DragRotate.prototype.handleDragStart =
function(mapBrowserEvent) {
var browserEvent = mapBrowserEvent.browserEvent;
var map = mapBrowserEvent.map;
// FIXME supports View2D only
var view = map.getView();
goog.asserts.assert(view instanceof ol.View2D);
if (browserEvent.isMouseActionButton() && this.condition_(browserEvent)) {
var map = mapBrowserEvent.map;
// FIXME supports View2D only
var view = map.getView();
goog.asserts.assert(view instanceof ol.View2D);
map.requestRenderFrame();
var size = map.getSize();
var offset = mapBrowserEvent.getPixel();
var theta = Math.atan2(
size.height / 2 - offset.y,
offset.x - size.width / 2);
this.startRotation_ = view.getRotation() + theta;
this.lastAngle_ = undefined;
return true;
} else {
return false;