Add center constraint to ol.View2D
This commit is contained in:
committed by
Frederic Junod
parent
1c003b5ab1
commit
73b9b6b6a0
+27
-2
@@ -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