Merge pull request #2019 from fredj/device-orientation-example

Add an extent constraint to the device-orientation example
This commit is contained in:
Frédéric Junod
2014-05-26 13:54:56 +02:00
2 changed files with 11 additions and 6 deletions

View File

@@ -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));
});

View File

@@ -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
@@ -184,8 +183,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);
@@ -193,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`.