Move mercator transforms to Projection.js.
The SphericalMercator mixin is not required for coordinate transforms. Default transforms included whenever Projection.js is included.
This commit is contained in:
@@ -195,10 +195,14 @@ OpenLayers.Projection.transform = function(point, source, dest) {
|
||||
}
|
||||
if (source.proj && dest.proj) {
|
||||
point = Proj4js.transform(source.proj, dest.proj, point);
|
||||
} else if (OpenLayers.Projection.transforms[source.getCode()] &&
|
||||
OpenLayers.Projection.transforms[source.getCode()][dest.getCode()]) {
|
||||
OpenLayers.Projection.transforms[source.getCode()][dest.getCode()](point);
|
||||
}
|
||||
} else {
|
||||
var sourceCode = source.getCode();
|
||||
var destCode = dest.getCode();
|
||||
var transforms = OpenLayers.Projection.transforms;
|
||||
if (transforms[sourceCode] && transforms[sourceCode][destCode]) {
|
||||
transforms[sourceCode][destCode](point);
|
||||
}
|
||||
}
|
||||
}
|
||||
return point;
|
||||
};
|
||||
@@ -209,10 +213,6 @@ OpenLayers.Projection.transform = function(point, source, dest) {
|
||||
* proj4js is not available:
|
||||
*
|
||||
* (code)
|
||||
* OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:3857",
|
||||
* OpenLayers.Layer.SphericalMercator.projectForward);
|
||||
* OpenLayers.Projection.addTransform("EPSG:3857", "EPSG:3857",
|
||||
* OpenLayers.Layer.SphericalMercator.projectInverse);
|
||||
* OpenLayers.Projection.addTransform("EPSG:3857", "EPSG:900913",
|
||||
* OpenLayers.Projection.nullTransform);
|
||||
* OpenLayers.Projection.addTransform("EPSG:900913", "EPSG:3857",
|
||||
@@ -222,3 +222,47 @@ OpenLayers.Projection.transform = function(point, source, dest) {
|
||||
OpenLayers.Projection.nullTransform = function(point) {
|
||||
return point;
|
||||
};
|
||||
|
||||
/**
|
||||
* Note: Transforms for web mercator <-> EPSG:4326
|
||||
* 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
|
||||
*/
|
||||
(function() {
|
||||
|
||||
var pole = 20037508.34;
|
||||
|
||||
function inverseMercator(xy) {
|
||||
xy.x = 180 * xy.x / pole;
|
||||
xy.y = 180 / Math.PI * (2 * Math.atan(Math.exp((xy.y / pole) * Math.PI)) - Math.PI / 2);
|
||||
return xy;
|
||||
}
|
||||
|
||||
function forwardMercator(xy) {
|
||||
xy.x = xy.x * pole / 180;
|
||||
xy.y = Math.log(Math.tan((90 + xy.y) * Math.PI / 360)) / Math.PI * pole;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user