From 824302349d6a0261a63894d2b833cb64715d2c18 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Mon, 28 Apr 2014 14:35:30 +0200 Subject: [PATCH 1/3] Export ol.View2D.prototype.constrainCenter function --- src/ol/view2d.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ol/view2d.js b/src/ol/view2d.js index 68061b2676..4bc7500936 100644 --- a/src/ol/view2d.js +++ b/src/ol/view2d.js @@ -184,8 +184,10 @@ ol.View2D.prototype.calculateCenterZoom = function(resolution, anchor) { /** + * Get the constrained center of this view. * @param {ol.Coordinate|undefined} center Center. * @return {ol.Coordinate|undefined} Constrained center. + * @todo api */ ol.View2D.prototype.constrainCenter = function(center) { return this.constraints_.center(center); From ff1a9d420db1059163f0b0510de8584df0da1e81 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Mon, 28 Apr 2014 14:35:37 +0200 Subject: [PATCH 2/3] Add an extent constraint to the device-orientation example --- examples/device-orientation.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/device-orientation.js b/examples/device-orientation.js index fb64f82f2f..a8786b8252 100644 --- a/examples/device-orientation.js +++ b/examples/device-orientation.js @@ -3,10 +3,14 @@ goog.require('ol.Map'); goog.require('ol.View2D'); goog.require('ol.dom.Input'); goog.require('ol.layer.Tile'); +goog.require('ol.proj'); goog.require('ol.source.OSM'); +var projection = ol.proj.get('EPSG:3857'); var view = new ol.View2D({ center: [0, 0], + projection: projection, + extent: projection.getExtent(), zoom: 2 }); var map = new ol.Map({ @@ -41,5 +45,5 @@ deviceOrientation.on(['change:beta', 'change:gamma'], function(event) { center[0] -= resolution * gamma * 25; center[1] += resolution * beta * 25; - view.setCenter(center); + view.setCenter(view.constrainCenter(center)); }); From c15987a14d1533c93fb2e0e4d6edb789226f3841 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Mon, 26 May 2014 13:41:34 +0200 Subject: [PATCH 3/3] Add constrainCenter documentation --- src/ol/view2d.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/ol/view2d.js b/src/ol/view2d.js index 4bc7500936..bc0cdecabd 100644 --- a/src/ol/view2d.js +++ b/src/ol/view2d.js @@ -59,14 +59,13 @@ ol.View2DProperty = { * that is passed to a setter will effectively be the value set in the view, * and returned by the corresponding getter. * - * But an `ol.View2D` object also has a *resolution constraint* and a - * *rotation constraint*. There's currently no *center constraint*, but - * this may change in the future. + * But an `ol.View2D` object also has a *resolution constraint*, a + * *rotation constraint* and a *center constraint*. * * As said above no constraints are applied when the setters are used to set * new states for the view. Applying constraints is done explicitly through * the use of the `constrain*` functions (`constrainResolution` and - * `constrainRotation`). + * `constrainRotation` and `constrainCenter`). * * The main users of the constraints are the interactions and the * controls. For example, double-clicking on the map changes the view to @@ -195,7 +194,7 @@ ol.View2D.prototype.constrainCenter = function(center) { /** - * Get the constrained the resolution of this view. + * Get the constrained resolution of this view. * @param {number|undefined} resolution Resolution. * @param {number=} opt_delta Delta. Default is `0`. * @param {number=} opt_direction Direction. Default is `0`.