Making extent optional for projections

The projection validity extent is used to generate a sensible
set of default resolutions and a sensible default tile grid.
By making it optional, we can still generate defaults - with
zoom levels that are similar to the default web mercator zoom
levels (based on fitting the world on a single tile, even if the
projection is not available for the whole world).
This commit is contained in:
ahocevar
2013-06-17 15:24:37 +02:00
parent d552d27a35
commit 37b369e0d7
4 changed files with 44 additions and 27 deletions
+30 -18
View File
@@ -4,10 +4,12 @@ goog.provide('ol.View2D');
goog.provide('ol.View2DProperty');
goog.require('goog.asserts');
goog.require('goog.math');
goog.require('ol.Constraints');
goog.require('ol.IView2D');
goog.require('ol.IView3D');
goog.require('ol.Projection');
goog.require('ol.ProjectionUnits');
goog.require('ol.ResolutionConstraint');
goog.require('ol.RotationConstraint');
goog.require('ol.RotationConstraintType');
@@ -57,18 +59,12 @@ ol.View2D = function(opt_options) {
options.center : null;
values[ol.View2DProperty.PROJECTION] = ol.proj.createProjection(
options.projection, 'EPSG:3857');
if (goog.isDef(options.resolution)) {
values[ol.View2DProperty.RESOLUTION] = options.resolution;
} else if (goog.isDef(options.zoom)) {
var projectionExtent = values[ol.View2DProperty.PROJECTION].getExtent();
var size = Math.max(
projectionExtent[1] - projectionExtent[0],
projectionExtent[3] - projectionExtent[2]);
values[ol.View2DProperty.RESOLUTION] =
size / (ol.DEFAULT_TILE_SIZE * Math.pow(2, options.zoom));
}
values[ol.View2DProperty.ROTATION] = options.rotation;
this.setValues(values);
/**
* @private
* @type {ol.Extent}
*/
this.maxExtent_ = goog.isDef(options.maxExtent) ? options.maxExtent : null;
var parts = ol.View2D.createResolutionConstraint_(options);
@@ -94,6 +90,14 @@ ol.View2D = function(opt_options) {
this.constraints_ = new ol.Constraints(resolutionConstraint,
rotationConstraint);
if (goog.isDef(options.resolution)) {
values[ol.View2DProperty.RESOLUTION] = options.resolution;
} else if (goog.isDef(options.zoom)) {
values[ol.View2DProperty.RESOLUTION] = resolutionConstraint(
this.maxResolution_, options.zoom);
}
values[ol.View2DProperty.ROTATION] = options.rotation;
this.setValues(values);
};
goog.inherits(ol.View2D, ol.View);
@@ -355,7 +359,10 @@ ol.View2D.prototype.isDef = function() {
* @param {ol.Coordinate|undefined} center Center.
*/
ol.View2D.prototype.setCenter = function(center) {
this.set(ol.View2DProperty.CENTER, center);
this.set(ol.View2DProperty.CENTER, goog.isNull(this.maxExtent_) ? center : [
goog.math.clamp(center[0], this.maxExtent_[0], this.maxExtent_[1]),
goog.math.clamp(center[1], this.maxExtent_[2], this.maxExtent_[3])
]);
};
goog.exportProperty(
ol.View2D.prototype,
@@ -421,11 +428,16 @@ ol.View2D.createResolutionConstraint_ = function(options) {
} else {
maxResolution = options.maxResolution;
if (!goog.isDef(maxResolution)) {
var projectionExtent = ol.proj.createProjection(
options.projection, 'EPSG:3857').getExtent();
maxResolution = Math.max(
projectionExtent[1] - projectionExtent[0],
projectionExtent[3] - projectionExtent[2]) / ol.DEFAULT_TILE_SIZE;
var projection = options.projection;
var projectionExtent = ol.proj.createProjection(projection, 'EPSG:3857')
.getExtent();
var size = goog.isNull(projectionExtent) ?
// use an extent that can fit the whole world if need be
360 * ol.METERS_PER_UNIT[ol.ProjectionUnits.DEGREES] /
ol.METERS_PER_UNIT[projection.getUnits()] :
Math.max(projectionExtent[1] - projectionExtent[0],
projectionExtent[3] - projectionExtent[2]);
maxResolution = size / ol.DEFAULT_TILE_SIZE;
}
var maxZoom = options.maxZoom;
if (!goog.isDef(maxZoom)) {