~flavour/sahana-eden/trunk

« back to all changes in this revision

Viewing changes to static/scripts/gis/openlayers/lib/OpenLayers/Projection.js

  • Committer: Fran Boon
  • Date: 2012-01-21 16:10:49 UTC
  • Revision ID: fran@aidiq.com-20120121161049-u2ytuiymn1t312c6
JS upgrade: jQuery, jQueryUI, OpenLayers, Ext, GeoExt

Show diffs side-by-side

added added

removed removed

Lines of Context:
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. */
9
9
 */
10
10
 
11
11
/**
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
 
17
 *     on usage.
 
18
 *
 
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 
 
22
 *     definitions.
 
23
 *
 
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.
16
27
 */
17
28
OpenLayers.Projection = OpenLayers.Class({
18
29
 
195
206
        }
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); 
201
 
        }        
 
209
        } else {
 
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);
 
215
            }
 
216
        }
202
217
    }
203
218
    return point;
204
219
};
209
224
 * proj4js is not available:
210
225
 *
211
226
 * (code)
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) {
223
234
    return point;
224
235
};
 
236
 
 
237
/**
 
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
 
244
 */
 
245
(function() {
 
246
 
 
247
    var pole = 20037508.34;
 
248
 
 
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);
 
252
        return xy;
 
253
    }
 
254
 
 
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;
 
258
        return xy;
 
259
    }
 
260
 
 
261
    // list of equivalent codes for web mercator
 
262
    var codes = ["EPSG:900913", "EPSG:3857", "EPSG:102113", "EPSG:102100"];
 
263
 
 
264
    var add = OpenLayers.Projection.addTransform;
 
265
    var same = OpenLayers.Projection.nullTransform;
 
266
 
 
267
    var i, len, code, other, j;
 
268
    for (i=0, len=codes.length; i<len; ++i) {
 
269
        code = codes[i];
 
270
        add("EPSG:4326", code, forwardMercator);
 
271
        add(code, "EPSG:4326", inverseMercator);
 
272
        for (j=i+1; j<len; ++j) {
 
273
            other = codes[j];
 
274
            add(code, other, same);
 
275
            add(other, code, same);
 
276
        }
 
277
    }
 
278
 
 
279
})();