Add support for transformation functions without using proj4js, and make

the SphericalMercator mixin register two transformations to/from EPSG:900913,
EPSG:4326. Thanks to Tim for the feedback and review. (Closes #1210)

This allows us to transform points to/from SphericalMercator 
without proj4js support -- and if other projects need similar functionality, 
they can write their own custom transformation functions rather than 
modifying proj4js to support some custom projection.


git-svn-id: http://svn.openlayers.org/trunk/openlayers@5410 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2007-12-14 20:45:42 +00:00
parent 9dd5d0e6da
commit a170e3fdf6
6 changed files with 158 additions and 12 deletions

View File

@@ -1,4 +1,5 @@
/** @requires OpenLayers/Layer.js
* @requires OpenLayers/Projection.js
*
* Class: OpenLayers.Layer.SphericalMercator
* A mixin for layers that wraps up the pieces neccesary to have a coordinate
@@ -101,6 +102,55 @@ OpenLayers.Layer.SphericalMercator = {
lat = 180/Math.PI * (2 * Math.atan(Math.exp(lat * Math.PI / 180)) - Math.PI / 2);
return new OpenLayers.LonLat(lon, lat);
},
/**
* Method: projectForward
* Given an object with x and y properties in EPSG:4326, modify the x,y
* properties on the object to be the Spherical Mercator projected
* coordinates.
*
* Parameters:
* point - {Object} An object with x and y properties.
*
* Returns:
* {Object} The point, with the x and y properties transformed to spherical
* mercator.
*/
projectForward: function(point) {
var lonlat = OpenLayers.Layer.SphericalMercator.forwardMercator(point.x, point.y);
point.x = lonlat.lon;
point.y = lonlat.lat;
return point;
},
/**
* Method: projectForward
* Given an object with x and y properties in Spherical Mercator, modify
* the x,y properties on the object to be the unprojected coordinates.
*
* Parameters:
* point - {Object} An object with x and y properties.
*
* Returns:
* {Object} The point, with the x and y properties transformed from
* spherical mercator to unprojected coordinates..
*/
projectInverse: function(point) {
var lonlat = OpenLayers.Layer.SphericalMercator.inverseMercator(point.x, point.y);
point.x = lonlat.lon;
point.y = lonlat.lat;
return point;
}
};
/**
* Note: Two transforms declared
* Transforms from EPSG:4326 to EPSG:900913 and from EPSG:900913 to EPSG:4326
* are set by this class.
*/
OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:900913",
OpenLayers.Layer.SphericalMercator.projectForward);
OpenLayers.Projection.addTransform("EPSG:900913", "EPSG:4326",
OpenLayers.Layer.SphericalMercator.projectInverse);