From 76a9f805452406b832a87963c8ff57e3c1379b6d Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Mon, 22 Apr 2013 15:16:59 +0200 Subject: [PATCH] Update ol.interaction.DragRotateAndZoom --- src/objectliterals.jsdoc | 5 ++ .../dragrotateandzoominteraction.js | 49 ++++++++++++++++--- 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/src/objectliterals.jsdoc b/src/objectliterals.jsdoc index 2c955719c8..8450016ed5 100644 --- a/src/objectliterals.jsdoc +++ b/src/objectliterals.jsdoc @@ -175,6 +175,11 @@ * @property {ol.interaction.ConditionType|undefined} condition Condition. */ +/** + * @typedef {Object} ol.interaction.DragRotateAndZoomOptions + * @property {ol.interaction.ConditionType|undefined} condition Condition. + */ + /** * Interactions for the map. Default is true for all options. * @typedef {Object} ol.interaction.DefaultsOptions diff --git a/src/ol/interaction/dragrotateandzoominteraction.js b/src/ol/interaction/dragrotateandzoominteraction.js index 4e67f01c27..f19ca10e7d 100644 --- a/src/ol/interaction/dragrotateandzoominteraction.js +++ b/src/ol/interaction/dragrotateandzoominteraction.js @@ -7,15 +7,24 @@ goog.require('goog.math.Vec2'); goog.require('ol.interaction.ConditionType'); goog.require('ol.interaction.Drag'); goog.require('ol.interaction.Interaction'); +goog.require('ol.interaction.condition'); + + +/** + * @define {number} Animation duration. + */ +ol.interaction.DRAGROTATEANDZOOM_ANIMATION_DURATION = 400; /** * @constructor * @extends {ol.interaction.Drag} - * @param {ol.interaction.ConditionType} condition Condition. + * @param {ol.interaction.DragRotateAndZoomOptions=} opt_options Options. */ -ol.interaction.DragRotateAndZoom = function(condition) { +ol.interaction.DragRotateAndZoom = function(opt_options) { + + var options = goog.isDef(opt_options) ? opt_options : {}; goog.base(this); @@ -23,7 +32,8 @@ ol.interaction.DragRotateAndZoom = function(condition) { * @private * @type {ol.interaction.ConditionType} */ - this.condition_ = condition; + this.condition_ = goog.isDef(options.condition) ? + options.condition : ol.interaction.condition.shiftKeyOnly; /** * @private @@ -37,6 +47,12 @@ ol.interaction.DragRotateAndZoom = function(condition) { */ this.lastMagnitude_ = undefined; + /** + * @private + * @type {number} + */ + this.lastScaleDelta_ = 0; + }; goog.inherits(ol.interaction.DragRotateAndZoom, ol.interaction.Drag); @@ -57,22 +73,41 @@ ol.interaction.DragRotateAndZoom.prototype.handleDrag = // FIXME works for View2D only var view = map.getView().getView2D(); map.requestRenderFrame(); - // FIXME the calls to map.rotate and map.zoomToResolution should use - // map.withFrozenRendering but an assertion fails :-( if (goog.isDef(this.lastAngle_)) { var angleDelta = theta - this.lastAngle_; - ol.interaction.Interaction.rotate( + ol.interaction.Interaction.rotateWithoutConstraints( map, view, view.getRotation() - angleDelta); } this.lastAngle_ = theta; if (goog.isDef(this.lastMagnitude_)) { var resolution = this.lastMagnitude_ * (view.getResolution() / magnitude); - ol.interaction.Interaction.zoom(map, view, resolution); + ol.interaction.Interaction.zoomWithoutConstraints(map, view, resolution); + } + if (goog.isDef(this.lastMagnitude_)) { + this.lastScaleDelta_ = this.lastMagnitude_ / magnitude; } this.lastMagnitude_ = magnitude; }; +/** + * @inheritDoc + */ +ol.interaction.DragRotateAndZoom.prototype.handleDragEnd = + function(mapBrowserEvent) { + var map = mapBrowserEvent.map; + var view = map.getView().getView2D(); + var direction = this.lastScaleDelta_ - 1; + map.withFrozenRendering(function() { + ol.interaction.Interaction.rotate(map, view, view.getRotation()); + ol.interaction.Interaction.zoom(map, view, view.getResolution(), undefined, + ol.interaction.DRAGROTATEANDZOOM_ANIMATION_DURATION, direction); + }); + this.lastScaleDelta_ = 0; + return true; +}; + + /** * @inheritDoc */