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; }