OpenLayers OpenLayers

Ticket #1210: 1210.patch

File 1210.patch, 4.8 kB (added by crschmidt, 1 year ago)

Support for alternative transformation functions in the case of lack of proj4js support

  • lib/OpenLayers/Projection.js

    old new  
    9393});      
    9494 
    9595/** 
     96 * APIProperty: transformations 
     97 * Transformations is an object, with from properties, each of which may 
     98 * have a to property. This allows you to define projections without  
     99 * requiring support for proj4js to be included. 
     100 * 
     101 * This object has keys which correspond to a 'source' projection object.  The 
     102 * keys should be strings, corresponding to the projection.getCode() value. 
     103 * Each source projection object should have a set of destination projection 
     104 * keys included in the object.  
     105 *  
     106 * Each value in the destination object should be a transformation function, 
     107 * where the function is expected to be passed an object with a .x and a .y 
     108 * property.  The function should return the object, with the .x and .y 
     109 * transformed according to the transformation function. 
     110 *  
     111 * For an example of usage, see the OpenLayers.Layer.SphericalMercator file. 
     112 */ 
     113OpenLayers.Projection.transformations = {};  
     114 
     115/** 
    96116 * APIMethod: transform 
    97117 * Read data from a string, and return an object whose type depends on the 
    98118 * subclass.  
     
    108128OpenLayers.Projection.transform = function(point, source, dest) { 
    109129    if (source.proj && dest.proj) { 
    110130        point = Proj4js.transform(source.proj, dest.proj, point); 
    111     } 
     131    } else if (source && dest &&  
     132               OpenLayers.Projection.transformations[source.getCode()] &&  
     133               OpenLayers.Projection.transformations[source.getCode()][dest.getCode()]) { 
     134       point = OpenLayers.Projection.transformations[source.getCode()][dest.getCode()](point)  
     135    }            
     136                
    112137    return point; 
    113138}; 
  • lib/OpenLayers/Layer/SphericalMercator.js

    old new  
    11/** @requires OpenLayers/Layer.js 
     2 * @requires OpenLayers/Projection.js 
    23 * 
    34 * Class: OpenLayers.Layer.SphericalMercator 
    45 * A mixin for layers that wraps up the pieces neccesary to have a coordinate 
     
    101102        lat = 180/Math.PI * (2 * Math.atan(Math.exp(lat * Math.PI / 180)) - Math.PI / 2); 
    102103         
    103104        return new OpenLayers.LonLat(lon, lat); 
     105    }, 
     106 
     107    /** 
     108     * APIMethod: projectForward  
     109     * Given an object with x and y properties in EPSG:4326, modify the x,y 
     110     * properties on the object to be the Spherical Mercator projected 
     111     * coordinates. 
     112     * 
     113     * Parameters: 
     114     * point - {Object} An object with x and y properties.  
     115     *  
     116     * Returns: 
     117     * {Object} The point, with the x and y properties transformed to spherical 
     118     * mercator. 
     119     */ 
     120    projectForward: function(point) { 
     121        var lonlat = OpenLayers.Layer.SphericalMercator.forwardMercator(point.x, point.y); 
     122        point.x = lonlat.lon; 
     123        point.y = lonlat.lat; 
     124        return point; 
     125    }, 
     126     
     127    /** 
     128     * APIMethod: projectForward  
     129     * Given an object with x and y properties in Spherical Mercator, modify 
     130     * the x,y properties on the object to be the unprojected coordinates. 
     131     * 
     132     * Parameters: 
     133     * point - {Object} An object with x and y properties.  
     134     *  
     135     * Returns: 
     136     * {Object} The point, with the x and y properties transformed from 
     137     * spherical mercator to unprojected coordinates.. 
     138     */ 
     139    projectInverse: function(point) { 
     140        var lonlat = OpenLayers.Layer.SphericalMercator.inverseMercator(point.x, point.y); 
     141        point.x = lonlat.lon; 
     142        point.y = lonlat.lat; 
     143        return point; 
    104144    } 
    105145 
    106146}; 
     147 
     148// Define transforms to/from spherical mercator projection. 
     149 
     150OpenLayers.Projection.transformations['EPSG:4326'] = {  
     151  'EPSG:900913': OpenLayers.Layer.SphericalMercator.projectForward 
     152};   
     153OpenLayers.Projection.transformations['EPSG:900913'] = { 
     154  'EPSG:4326': OpenLayers.Layer.SphericalMercator.projectInverse 
     155 
  • lib/OpenLayers.js

    old new  
    7878            "Rico/Color.js", 
    7979            "OpenLayers/Ajax.js", 
    8080            "OpenLayers/Events.js", 
     81            "OpenLayers/Projection.js", 
    8182            "OpenLayers/Map.js", 
    8283            "OpenLayers/Layer.js", 
    8384            "OpenLayers/Icon.js", 
     
    175176            "OpenLayers/Layer/WFS.js", 
    176177            "OpenLayers/Control/MouseToolbar.js", 
    177178            "OpenLayers/Control/NavToolbar.js", 
    178             "OpenLayers/Control/EditingToolbar.js", 
    179             "OpenLayers/Projection.js" 
     179            "OpenLayers/Control/EditingToolbar.js" 
    180180        ); // etc. 
    181181 
    182182