New OpenLayers.Projection.defaults property.

This allows us to simplify the map and layer configuration, because now the projection also defines defaults for maxExtent, maxResolution and units.
This change also adds transforms for SRS aliases for EPSG:4326 and centralizes axis order information in OpenLayers.Projection.defaults.
This commit is contained in:
ahocevar
2012-02-15 11:09:55 +01:00
parent da3dc76a6d
commit 11966d231f
11 changed files with 127 additions and 78 deletions

View File

@@ -8,6 +8,7 @@
* @requires OpenLayers/Util.js
* @requires OpenLayers/Events.js
* @requires OpenLayers/Tween.js
* @requires OpenLayers/Projection.js
*/
/**
@@ -248,17 +249,19 @@ OpenLayers.Map = OpenLayers.Class({
/**
* APIProperty: projection
* {String} Set in the map options to override the default projection
* string this map - also set maxExtent, maxResolution, and
* units if appropriate. Default is "EPSG:4326".
* string this map. When using a projection other than EPSG:4326
* (CRS:84, Geographic) or EPSG:3857 (EPSG:900913, Web Mercator),
* also set maxExtent and maxResolution. Default is "EPSG:4326".
*/
projection: "EPSG:4326",
/**
* APIProperty: units
* {String} The map units. Defaults to 'degrees'. Possible values are
* 'degrees' (or 'dd'), 'm', 'ft', 'km', 'mi', 'inches'.
* {String} The map units. Possible values are 'degrees' (or 'dd'), 'm',
* 'ft', 'km', 'mi', 'inches'. Only required if the projection default
* should be overridden.
*/
units: 'degrees',
units: null,
/**
* APIProperty: resolutions
@@ -271,12 +274,10 @@ OpenLayers.Map = OpenLayers.Class({
/**
* APIProperty: maxResolution
* {Float} Default max is 360 deg / 256 px, which corresponds to
* zoom level 0 on gmaps. Specify a different value in the map
* options if you are not using a geographic projection and
* displaying the whole world.
* {Float} Specify if you are not using a geographic projection or Web
* Mercator and displaying the whole world.
*/
maxResolution: 1.40625,
maxResolution: null,
/**
* APIProperty: minResolution
@@ -342,7 +343,8 @@ OpenLayers.Map = OpenLayers.Class({
/**
* APIProperty: displayProjection
* {<OpenLayers.Projection>} Requires proj4js support.Projection used by
* {<OpenLayers.Projection>} Requires proj4js support for projections other
* than EPSG:4326 or EPSG:900913/EPSG:3857. Projection used by
* several controls to display data to user. If this property is set,
* it will be set on any control which has a null displayProjection
* property at the time the control is added to the map.
@@ -471,8 +473,6 @@ OpenLayers.Map = OpenLayers.Class({
this.tileSize = new OpenLayers.Size(OpenLayers.Map.TILE_WIDTH,
OpenLayers.Map.TILE_HEIGHT);
this.maxExtent = new OpenLayers.Bounds(-180, -90, 180, 90);
this.paddingForPopups = new OpenLayers.Bounds(15, 15, 15, 15);
this.theme = OpenLayers._getScriptLocation() +
@@ -481,6 +481,10 @@ OpenLayers.Map = OpenLayers.Class({
// now override default options
OpenLayers.Util.extend(this, options);
var projCode = this.projection instanceof OpenLayers.Projection ?
this.projection.projCode : this.projection;
OpenLayers.Util.applyDefaults(this, OpenLayers.Projection.defaults[projCode]);
// allow extents to be arrays
if (this.maxExtent && !(this.maxExtent instanceof OpenLayers.Bounds)) {
this.maxExtent = new OpenLayers.Bounds(this.maxExtent);