Refactor constraints static methods to module functions
This commit is contained in:
37
src/ol/centerconstraint.js
Normal file
37
src/ol/centerconstraint.js
Normal file
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* @module ol/centerconstraint
|
||||
*/
|
||||
import {clamp} from './math.js';
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Extent} extent Extent.
|
||||
* @return {ol.CenterConstraintType} The constraint.
|
||||
*/
|
||||
export function createExtent(extent) {
|
||||
return (
|
||||
/**
|
||||
* @param {ol.Coordinate|undefined} center Center.
|
||||
* @return {ol.Coordinate|undefined} Center.
|
||||
*/
|
||||
function(center) {
|
||||
if (center) {
|
||||
return [
|
||||
clamp(center[0], extent[0], extent[2]),
|
||||
clamp(center[1], extent[1], extent[3])
|
||||
];
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Coordinate|undefined} center Center.
|
||||
* @return {ol.Coordinate|undefined} Center.
|
||||
*/
|
||||
export function none(center) {
|
||||
return center;
|
||||
}
|
||||
Reference in New Issue
Block a user