Add center constraint to ol.View2D
This commit is contained in:
committed by
Frederic Junod
parent
1c003b5ab1
commit
73b9b6b6a0
@@ -101,6 +101,7 @@
|
||||
* @property {ol.Coordinate|undefined} center The initial center for the view.
|
||||
* The coordinate system for the center is specified with the `projection`
|
||||
* option.
|
||||
* @property {ol.Extent|undefined} extent The extent to constraint the center to.
|
||||
* @property {number|undefined} maxResolution The maximum resolution used to
|
||||
* determine the resolution constraint. It is used together with `maxZoom`
|
||||
* and `zoomFactor`. If unspecified it is calculated in such a way that the
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
goog.provide('ol.Constraints');
|
||||
|
||||
goog.require('ol.CenterConstraintType');
|
||||
goog.require('ol.ResolutionConstraintType');
|
||||
goog.require('ol.RotationConstraintType');
|
||||
|
||||
@@ -7,12 +8,19 @@ goog.require('ol.RotationConstraintType');
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {ol.CenterConstraintType} centerConstraint Center constraint.
|
||||
* @param {ol.ResolutionConstraintType} resolutionConstraint
|
||||
* Resolution constraint.
|
||||
* @param {ol.RotationConstraintType} rotationConstraint
|
||||
* Rotation constraint.
|
||||
*/
|
||||
ol.Constraints = function(resolutionConstraint, rotationConstraint) {
|
||||
ol.Constraints =
|
||||
function(centerConstraint, resolutionConstraint, rotationConstraint) {
|
||||
|
||||
/**
|
||||
* @type {ol.CenterConstraintType}
|
||||
*/
|
||||
this.center = centerConstraint;
|
||||
|
||||
/**
|
||||
* @type {ol.ResolutionConstraintType}
|
||||
|
||||
@@ -4,6 +4,7 @@ goog.provide('ol.View2D');
|
||||
goog.provide('ol.View2DProperty');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('ol.CenterConstraint');
|
||||
goog.require('ol.Constraints');
|
||||
goog.require('ol.IView2D');
|
||||
goog.require('ol.IView3D');
|
||||
@@ -112,6 +113,7 @@ ol.View2D = function(opt_options) {
|
||||
*/
|
||||
this.minResolution_ = resolutionConstraintInfo.minResolution;
|
||||
|
||||
var centerConstraint = ol.View2D.createCenterConstraint_(options);
|
||||
var resolutionConstraint = resolutionConstraintInfo.constraint;
|
||||
var rotationConstraint = ol.View2D.createRotationConstraint_(options);
|
||||
|
||||
@@ -119,8 +121,8 @@ ol.View2D = function(opt_options) {
|
||||
* @private
|
||||
* @type {ol.Constraints}
|
||||
*/
|
||||
this.constraints_ = new ol.Constraints(resolutionConstraint,
|
||||
rotationConstraint);
|
||||
this.constraints_ = new ol.Constraints(
|
||||
centerConstraint, resolutionConstraint, rotationConstraint);
|
||||
|
||||
if (goog.isDef(options.resolution)) {
|
||||
values[ol.View2DProperty.RESOLUTION] = options.resolution;
|
||||
@@ -172,6 +174,15 @@ ol.View2D.prototype.calculateCenterZoom = function(resolution, anchor) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Coordinate|undefined} center Center.
|
||||
* @return {ol.Coordinate|undefined} Constrained center.
|
||||
*/
|
||||
ol.View2D.prototype.constrainCenter = function(center) {
|
||||
return this.constraints_.center(center);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the constrained the resolution of this view.
|
||||
* @param {number|undefined} resolution Resolution.
|
||||
@@ -472,6 +483,20 @@ ol.View2D.prototype.setZoom = function(zoom) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.View2DOptions} options View2D options.
|
||||
* @private
|
||||
* @return {ol.CenterConstraintType}
|
||||
*/
|
||||
ol.View2D.createCenterConstraint_ = function(options) {
|
||||
if (goog.isDef(options.extent)) {
|
||||
return ol.CenterConstraint.createExtent(options.extent);
|
||||
} else {
|
||||
return ol.CenterConstraint.none;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {ol.View2DOptions} options View2D options.
|
||||
|
||||
Reference in New Issue
Block a user