Merge pull request #1602 from twpayne/configurable-rotation-constraints
Configurable rotation constraints
This commit is contained in:
@@ -91,6 +91,13 @@
|
|||||||
* The coordinate system for the center is specified with the `projection`
|
* The coordinate system for the center is specified with the `projection`
|
||||||
* option. Default is `undefined`, and layer sources will not be fetched if
|
* option. Default is `undefined`, and layer sources will not be fetched if
|
||||||
* this is not set.
|
* 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,
|
* @property {ol.Extent|undefined} extent The extent that constrains the center,
|
||||||
* in other words, center cannot be set outside this extent.
|
* in other words, center cannot be set outside this extent.
|
||||||
* Default is `undefined`.
|
* Default is `undefined`.
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
goog.provide('ol.RotationConstraint');
|
goog.provide('ol.RotationConstraint');
|
||||||
goog.provide('ol.RotationConstraintType');
|
goog.provide('ol.RotationConstraintType');
|
||||||
|
|
||||||
|
goog.require('goog.math');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {function((number|undefined), number): (number|undefined)}
|
* @typedef {function((number|undefined), number): (number|undefined)}
|
||||||
@@ -8,6 +10,20 @@ goog.provide('ol.RotationConstraintType');
|
|||||||
ol.RotationConstraintType;
|
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|undefined} rotation Rotation.
|
||||||
* @param {number} delta Delta.
|
* @param {number} delta Delta.
|
||||||
@@ -50,7 +66,7 @@ ol.RotationConstraint.createSnapToN = function(n) {
|
|||||||
* @return {ol.RotationConstraintType} Rotation constraint.
|
* @return {ol.RotationConstraintType} Rotation constraint.
|
||||||
*/
|
*/
|
||||||
ol.RotationConstraint.createSnapToZero = function(opt_tolerance) {
|
ol.RotationConstraint.createSnapToZero = function(opt_tolerance) {
|
||||||
var tolerance = opt_tolerance || 0.1;
|
var tolerance = opt_tolerance || goog.math.toRadians(5);
|
||||||
return (
|
return (
|
||||||
/**
|
/**
|
||||||
* @param {number|undefined} rotation Rotation.
|
* @param {number|undefined} rotation Rotation.
|
||||||
|
|||||||
+17
-2
@@ -573,6 +573,21 @@ ol.View2D.createResolutionConstraint_ = function(options) {
|
|||||||
* @return {ol.RotationConstraintType} Rotation constraint.
|
* @return {ol.RotationConstraintType} Rotation constraint.
|
||||||
*/
|
*/
|
||||||
ol.View2D.createRotationConstraint_ = function(options) {
|
ol.View2D.createRotationConstraint_ = function(options) {
|
||||||
// FIXME rotation constraint is not configurable at the moment
|
var enableRotation = goog.isDef(options.enableRotation) ?
|
||||||
return ol.RotationConstraint.createSnapToZero();
|
options.enableRotation : true;
|
||||||
|
if (enableRotation) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user