Add and use ol.Constraints

This commit is contained in:
Tom Payne
2012-08-04 15:27:23 +02:00
parent eaca7d0a8c
commit 0fd122a1ed
13 changed files with 163 additions and 147 deletions
+11 -9
View File
@@ -7,6 +7,7 @@ goog.require('ol.Map');
goog.require('ol.MapProperty');
goog.require('ol.Projection');
goog.require('ol.control.CenterConstraint');
goog.require('ol.control.Constraints');
goog.require('ol.control.DblClickZoom');
goog.require('ol.control.DragPan');
goog.require('ol.control.KeyboardPan');
@@ -77,21 +78,22 @@ ol.createMap = function(target, opt_values, opt_rendererHints) {
goog.object.extend(values, opt_values);
}
var centerConstraint = ol.control.CenterConstraint.snapToPixel;
// FIXME this should be a configuration option
var centerConstraint = ol.control.CenterConstraint.snapToPixel;
var resolutionConstraint = ol.control.ResolutionConstraint.createSnapToPower(
2, ol.Projection.EPSG_3857_HALF_SIZE / 128);
var constraints = new ol.control.Constraints(
centerConstraint, resolutionConstraint);
if (!goog.object.containsKey(values, ol.MapProperty.CONTROLS)) {
var controls = new ol.Collection();
controls.push(new ol.control.DblClickZoom(resolutionConstraint));
controls.push(new ol.control.DragPan(centerConstraint));
controls.push(new ol.control.KeyboardPan(centerConstraint));
controls.push(new ol.control.KeyboardZoom(resolutionConstraint));
controls.push(new ol.control.MouseWheelZoom(resolutionConstraint));
controls.push(new ol.control.ShiftDragRotateAndZoom(resolutionConstraint));
controls.push(new ol.control.ShiftDragZoom(resolutionConstraint));
controls.push(new ol.control.DblClickZoom(constraints));
controls.push(new ol.control.DragPan(constraints));
controls.push(new ol.control.KeyboardPan(constraints));
controls.push(new ol.control.KeyboardZoom(constraints));
controls.push(new ol.control.MouseWheelZoom(constraints));
controls.push(new ol.control.ShiftDragRotateAndZoom(constraints));
controls.push(new ol.control.ShiftDragZoom(constraints));
values[ol.MapProperty.CONTROLS] = controls;
}