1
/* Copyright (c) 2006-2011 by OpenLayers Contributors (see authors.txt for
1
/* Copyright (c) 2006-2012 by OpenLayers Contributors (see authors.txt for
2
2
* full list of contributors). Published under the Clear BSD license.
3
3
* See http://svn.openlayers.org/trunk/openlayers/license.txt for the
4
4
* full text of the license. */
12
* Class: OpenLayers.Projection
13
* Class for coordinate transforms between coordinate systems.
14
* Depends on the proj4js library. If proj4js is not available,
15
* then this is just an empty stub.
12
* Namespace: OpenLayers.Projection
13
* Methods for coordinate transforms between coordinate systems. By default,
14
* OpenLayers ships with the ability to transform coordinates between
15
* geographic (EPSG:4326) and web or spherical mercator (EPSG:900913 et al.)
16
* coordinate reference systems. See the <transform> method for details
19
* Additional transforms may be added by using the <proj4js at http://proj4js.org/>
20
* library. If the proj4js library is included, the <transform> method
21
* will work between any two coordinate reference systems with proj4js
24
* If the proj4js library is not included, or if you wish to allow transforms
25
* between arbitrary coordinate reference systems, use the <addTransform>
26
* method to register a custom transform method.
17
28
OpenLayers.Projection = OpenLayers.Class({
196
207
if (source.proj && dest.proj) {
197
208
point = Proj4js.transform(source.proj, dest.proj, point);
198
} else if (OpenLayers.Projection.transforms[source.getCode()] &&
199
OpenLayers.Projection.transforms[source.getCode()][dest.getCode()]) {
200
OpenLayers.Projection.transforms[source.getCode()][dest.getCode()](point);
210
var sourceCode = source.getCode();
211
var destCode = dest.getCode();
212
var transforms = OpenLayers.Projection.transforms;
213
if (transforms[sourceCode] && transforms[sourceCode][destCode]) {
214
transforms[sourceCode][destCode](point);
209
224
* proj4js is not available:
212
* OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:3857",
213
* OpenLayers.Layer.SphericalMercator.projectForward);
214
* OpenLayers.Projection.addTransform("EPSG:3857", "EPSG:3857",
215
* OpenLayers.Layer.SphericalMercator.projectInverse);
216
227
* OpenLayers.Projection.addTransform("EPSG:3857", "EPSG:900913",
217
228
* OpenLayers.Projection.nullTransform);
218
229
* OpenLayers.Projection.addTransform("EPSG:900913", "EPSG:3857",
222
233
OpenLayers.Projection.nullTransform = function(point) {
238
* Note: Transforms for web mercator <-> EPSG:4326
239
* OpenLayers recognizes EPSG:3857, EPSG:900913, EPSG:102113 and EPSG:102100.
240
* OpenLayers originally started referring to EPSG:900913 as web mercator.
241
* The EPSG has declared EPSG:3857 to be web mercator.
242
* ArcGIS 10 recognizes the EPSG:3857, EPSG:102113, and EPSG:102100 as
243
* 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
247
var pole = 20037508.34;
249
function inverseMercator(xy) {
250
xy.x = 180 * xy.x / pole;
251
xy.y = 180 / Math.PI * (2 * Math.atan(Math.exp((xy.y / pole) * Math.PI)) - Math.PI / 2);
255
function forwardMercator(xy) {
256
xy.x = xy.x * pole / 180;
257
xy.y = Math.log(Math.tan((90 + xy.y) * Math.PI / 360)) / Math.PI * pole;
261
// list of equivalent codes for web mercator
262
var codes = ["EPSG:900913", "EPSG:3857", "EPSG:102113", "EPSG:102100"];
264
var add = OpenLayers.Projection.addTransform;
265
var same = OpenLayers.Projection.nullTransform;
267
var i, len, code, other, j;
268
for (i=0, len=codes.length; i<len; ++i) {
270
add("EPSG:4326", code, forwardMercator);
271
add(code, "EPSG:4326", inverseMercator);
272
for (j=i+1; j<len; ++j) {
274
add(code, other, same);
275
add(other, code, same);