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:
@@ -142,7 +142,7 @@ OpenLayers.Projection = OpenLayers.Class({
|
||||
|
||||
/**
|
||||
* Property: transforms
|
||||
* Transforms is an object, with from properties, each of which may
|
||||
* {Object} Transforms is an object, with from properties, each of which may
|
||||
* have a to property. This allows you to define projections without
|
||||
* requiring support for proj4js to be included.
|
||||
*
|
||||
@@ -162,6 +162,34 @@ OpenLayers.Projection = OpenLayers.Class({
|
||||
*/
|
||||
OpenLayers.Projection.transforms = {};
|
||||
|
||||
/**
|
||||
* APIProperty: defaults
|
||||
* {Object} Defaults for the SRS codes known to OpenLayers (currently
|
||||
* EPSG:4326, CRS:84, urn:ogc:def:crs:EPSG:6.6:4326, EPSG:900913, EPSG:3857,
|
||||
* EPSG:102113 and EPSG:102100). Keys are the SRS code, values are units,
|
||||
* maxExtent (the validity extent for the SRS), maxResolution (the maximum
|
||||
* resolution commonly used in grid sets for this SRS) and yx (true if this
|
||||
* SRS is known to have a reverse axis order).
|
||||
*/
|
||||
OpenLayers.Projection.defaults = {
|
||||
"EPSG:4326": {
|
||||
units: "degrees",
|
||||
maxExtent: [-180, -90, 180, 90],
|
||||
maxResolution: 1.40625,
|
||||
yx: true
|
||||
},
|
||||
"CRS:84": {
|
||||
units: "degrees",
|
||||
maxExtent: [-180, -90, 180, 90],
|
||||
maxResolution: 1.40625
|
||||
},
|
||||
"EPSG:900913": {
|
||||
units: "m",
|
||||
maxExtent: [-20037508.34, -20037508.34, 20037508.34, 20037508.34],
|
||||
maxResolution: 156543.03390625
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* APIMethod: addTransform
|
||||
* Set a custom transform method between two projections. Use this method in
|
||||
@@ -176,6 +204,12 @@ OpenLayers.Projection.transforms = {};
|
||||
* in place. The original point should be modified.
|
||||
*/
|
||||
OpenLayers.Projection.addTransform = function(from, to, method) {
|
||||
if (method === OpenLayers.Projection.nullTransform) {
|
||||
var defaults = OpenLayers.Projection.defaults[from];
|
||||
if (defaults && !OpenLayers.Projection.defaults[to]) {
|
||||
OpenLayers.Projection.defaults[to] = defaults;
|
||||
}
|
||||
}
|
||||
if(!OpenLayers.Projection.transforms[from]) {
|
||||
OpenLayers.Projection.transforms[from] = {};
|
||||
}
|
||||
@@ -235,12 +269,15 @@ OpenLayers.Projection.nullTransform = function(point) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Note: Transforms for web mercator <-> EPSG:4326
|
||||
* Note: Transforms for web mercator <-> geographic
|
||||
* OpenLayers recognizes EPSG:3857, EPSG:900913, EPSG:102113 and EPSG:102100.
|
||||
* OpenLayers originally started referring to EPSG:900913 as web mercator.
|
||||
* The EPSG has declared EPSG:3857 to be web mercator.
|
||||
* ArcGIS 10 recognizes the EPSG:3857, EPSG:102113, and EPSG:102100 as
|
||||
* equivalent. See http://blogs.esri.com/Dev/blogs/arcgisserver/archive/2009/11/20/ArcGIS-Online-moving-to-Google-_2F00_-Bing-tiling-scheme_3A00_-What-does-this-mean-for-you_3F00_.aspx#12084
|
||||
* equivalent. See http://blogs.esri.com/Dev/blogs/arcgisserver/archive/2009/11/20/ArcGIS-Online-moving-to-Google-_2F00_-Bing-tiling-scheme_3A00_-What-does-this-mean-for-you_3F00_.aspx#12084.
|
||||
* For geographic, OpenLayers recognizes EPSG:4326, CRS:84 and
|
||||
* urn:ogc:def:crs:EPSG:6.6:4326. OpenLayers also knows about the reverse axis
|
||||
* order for EPSG:4326.
|
||||
*/
|
||||
(function() {
|
||||
|
||||
@@ -258,22 +295,31 @@ OpenLayers.Projection.nullTransform = function(point) {
|
||||
return xy;
|
||||
}
|
||||
|
||||
// list of equivalent codes for web mercator
|
||||
var codes = ["EPSG:900913", "EPSG:3857", "EPSG:102113", "EPSG:102100"];
|
||||
|
||||
var add = OpenLayers.Projection.addTransform;
|
||||
var same = OpenLayers.Projection.nullTransform;
|
||||
|
||||
var i, len, code, other, j;
|
||||
for (i=0, len=codes.length; i<len; ++i) {
|
||||
code = codes[i];
|
||||
add("EPSG:4326", code, forwardMercator);
|
||||
add(code, "EPSG:4326", inverseMercator);
|
||||
for (j=i+1; j<len; ++j) {
|
||||
other = codes[j];
|
||||
add(code, other, same);
|
||||
add(other, code, same);
|
||||
function map(base, codes) {
|
||||
var add = OpenLayers.Projection.addTransform;
|
||||
var same = OpenLayers.Projection.nullTransform;
|
||||
var i, len, code, other, j;
|
||||
for (i=0, len=codes.length; i<len; ++i) {
|
||||
code = codes[i];
|
||||
add(base, code, forwardMercator);
|
||||
add(code, base, inverseMercator);
|
||||
for (j=i+1; j<len; ++j) {
|
||||
other = codes[j];
|
||||
add(code, other, same);
|
||||
add(other, code, same);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// list of equivalent codes for web mercator
|
||||
var mercator = ["EPSG:900913", "EPSG:3857", "EPSG:102113", "EPSG:102100"],
|
||||
geographic = ["CRS:84", "urn:ogc:def:crs:EPSG:6.6:4326", "EPSG:4326"],
|
||||
i;
|
||||
for (i=mercator.length-1; i>=0; --i) {
|
||||
map(mercator[i], geographic);
|
||||
}
|
||||
for (i=geographic.length-1; i>=0; --i) {
|
||||
map(geographic[i], mercator);
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user