From 5ff2fcacb867c6697b7d591222fd86b57eb031ce Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Mon, 27 Jan 2014 14:39:40 +0100 Subject: [PATCH 1/4] Snap rotation when within 5 degrees instead of 0.1 radians --- src/ol/rotationconstraint.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ol/rotationconstraint.js b/src/ol/rotationconstraint.js index 820f6cf3c8..0f6e3d2dea 100644 --- a/src/ol/rotationconstraint.js +++ b/src/ol/rotationconstraint.js @@ -1,6 +1,8 @@ goog.provide('ol.RotationConstraint'); goog.provide('ol.RotationConstraintType'); +goog.require('goog.math'); + /** * @typedef {function((number|undefined), number): (number|undefined)} @@ -50,7 +52,7 @@ ol.RotationConstraint.createSnapToN = function(n) { * @return {ol.RotationConstraintType} Rotation constraint. */ ol.RotationConstraint.createSnapToZero = function(opt_tolerance) { - var tolerance = opt_tolerance || 0.1; + var tolerance = opt_tolerance || goog.math.toRadians(5); return ( /** * @param {number|undefined} rotation Rotation. From 0a5ab24a0cc60f2e6a6b96973fb6753b3648b28f Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Mon, 27 Jan 2014 14:49:08 +0100 Subject: [PATCH 2/4] Add ol.RotationConstraint.disable --- src/ol/rotationconstraint.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/ol/rotationconstraint.js b/src/ol/rotationconstraint.js index 0f6e3d2dea..fc73600f4e 100644 --- a/src/ol/rotationconstraint.js +++ b/src/ol/rotationconstraint.js @@ -10,6 +10,20 @@ goog.require('goog.math'); ol.RotationConstraintType; +/** + * @param {number|undefined} rotation Rotation. + * @param {number} delta Delta. + * @return {number|undefined} Rotation. + */ +ol.RotationConstraint.disable = function(rotation, delta) { + if (goog.isDef(rotation)) { + return 0; + } else { + return undefined; + } +}; + + /** * @param {number|undefined} rotation Rotation. * @param {number} delta Delta. From 07a717d9679e39e0d5aaa986311502b506d00399 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Mon, 27 Jan 2014 14:52:42 +0100 Subject: [PATCH 3/4] Add enableRotation option to ol.View2D --- src/objectliterals.jsdoc | 2 ++ src/ol/view2d.js | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/objectliterals.jsdoc b/src/objectliterals.jsdoc index 6c1c23e5f1..7963ec4487 100644 --- a/src/objectliterals.jsdoc +++ b/src/objectliterals.jsdoc @@ -91,6 +91,8 @@ * The coordinate system for the center is specified with the `projection` * option. Default is `undefined`, and layer sources will not be fetched if * this is not set. + * @property {boolean|undefined} enableRotation Enable rotation. Default is + * `true`. * @property {ol.Extent|undefined} extent The extent that constrains the center, * in other words, center cannot be set outside this extent. * Default is `undefined`. diff --git a/src/ol/view2d.js b/src/ol/view2d.js index 057337f514..c7001a5096 100644 --- a/src/ol/view2d.js +++ b/src/ol/view2d.js @@ -569,6 +569,11 @@ ol.View2D.createResolutionConstraint_ = function(options) { * @return {ol.RotationConstraintType} Rotation constraint. */ ol.View2D.createRotationConstraint_ = function(options) { - // FIXME rotation constraint is not configurable at the moment - return ol.RotationConstraint.createSnapToZero(); + var enableRotation = goog.isDef(options.enableRotation) ? + options.enableRotation : true; + if (enableRotation) { + return ol.RotationConstraint.createSnapToZero(); + } else { + return ol.RotationConstraint.disable; + } }; From 3196afb4c7ae21c8c94872354be858fd57ea753a Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Mon, 27 Jan 2014 15:13:50 +0100 Subject: [PATCH 4/4] Add constrainRotation option to ol.View2D --- src/objectliterals.jsdoc | 5 +++++ src/ol/view2d.js | 12 +++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/objectliterals.jsdoc b/src/objectliterals.jsdoc index 7963ec4487..d4b3f57f80 100644 --- a/src/objectliterals.jsdoc +++ b/src/objectliterals.jsdoc @@ -91,6 +91,11 @@ * The coordinate system for the center is specified with the `projection` * option. Default is `undefined`, and layer sources will not be fetched if * this is not set. + * @property {boolean|number|undefined} constrainRotation Rotation constraint. + * `false` means no constraint. `true` means no constraint, but snap to + * zero near zero. A number constraints the rotation to that number of + * values. For example, `4` will constrain the rotation to 0, 90, 180, and + * 270 degrees. The default is `true`. * @property {boolean|undefined} enableRotation Enable rotation. Default is * `true`. * @property {ol.Extent|undefined} extent The extent that constrains the center, diff --git a/src/ol/view2d.js b/src/ol/view2d.js index c7001a5096..6ddb3cd802 100644 --- a/src/ol/view2d.js +++ b/src/ol/view2d.js @@ -572,7 +572,17 @@ ol.View2D.createRotationConstraint_ = function(options) { var enableRotation = goog.isDef(options.enableRotation) ? options.enableRotation : true; if (enableRotation) { - return ol.RotationConstraint.createSnapToZero(); + var constrainRotation = options.constrainRotation; + if (!goog.isDef(constrainRotation) || constrainRotation === true) { + return ol.RotationConstraint.createSnapToZero(); + } else if (constrainRotation === false) { + return ol.RotationConstraint.none; + } else if (goog.isNumber(constrainRotation)) { + return ol.RotationConstraint.createSnapToN(constrainRotation); + } else { + goog.asserts.fail(); + return ol.RotationConstraint.none; + } } else { return ol.RotationConstraint.disable; }