OpenLayers OpenLayers

Ticket #1035: projections.patch

File projections.patch, 9.6 kB (added by crschmidt, 1 year ago)

projection patch that does nothing

  • tests/list-tests.html

    old new  
    8787    <li>Handler/test_Path.html</li> 
    8888    <li>Handler/test_Polygon.html</li> 
    8989    <li>Handler/test_RegularPolygon.html</li> 
     90    <li>test_Projection.html</li> 
    9091    <li>test_Map.html</li> 
    9192</ul> 
  • tests/test_Projection.html

    old new  
     1<html> 
     2<head> 
     3  <script src="../lib/OpenLayers.js"></script> 
     4  <script type="text/javascript"> 
     5 
     6    function test_01_Projection_constructor(t) { 
     7        t.plan(7); 
     8     
     9        var options = {'foo': 'bar'}; 
     10        var projection = new OpenLayers.Projection("code", options); 
     11        t.ok(projection instanceof OpenLayers.Projection, 
     12             "new OpenLayers.Projection returns object" ); 
     13        t.eq(projection.projCode, "code", "The proj code is maintained");  
     14        t.eq(projection.getCode(), "code", "The proj code is maintained.");  
     15        t.eq(projection.getUnits(), null, "Null units with no proj4js library.");  
     16        t.eq(projection.foo, "bar", "constructor sets options correctly"); 
     17        var projection2 = new OpenLayers.Projection("epsg:4325", options); 
     18        out = OpenLayers.Projection.transform({'x':10,'y':12}, projection, projection2); 
     19        t.eq(out.x, 10, "Null transform has no effect"); 
     20        t.eq(out.y, 12, "Null transform has no effect"); 
     21    } 
     22 
     23  </script> 
     24</head> 
     25<body> 
     26</body> 
     27</html> 
  • lib/OpenLayers/Layer.js

    old new  
    126126 
    127127    /** 
    128128     * APIProperty: projection 
    129      * {String} Set in the layer options to override the default projection 
    130      *     string this layer - also set maxExtent, maxResolution, and units if 
    131      *     appropriate. 
     129     * {<OpenLayers.Projection>} or {<String>} Set in the layer options to 
     130     *     override the default projection string this layer - also set maxExtent, 
     131     *     maxResolution, and units if appropriate. Can be either a string or 
     132     *     an <OpenLayers.Projection> object when created -- will be converted 
     133     *     to an object when setMap is called if a string is passed.   
    132134     */ 
    133135    projection: null,     
    134136     
     
    267269        if (this.map != null) { 
    268270            this.map.removeLayer(this, setNewBaseLayer); 
    269271        } 
     272        this.projection = null; 
    270273        this.map = null; 
    271274        this.name = null; 
    272275        this.div = null; 
     
    410413            //  been set 
    411414            this.maxExtent = this.maxExtent || this.map.maxExtent; 
    412415            this.projection = this.projection || this.map.projection; 
    413             this.units = this.units || this.map.units; 
    414416             
     417            if (this.projection && typeof this.projection == "string") { 
     418                this.projection = new OpenLayers.Projection(this.projection); 
     419            } 
     420             
     421            // Check the projection to see if we can get units -- if not, refer 
     422            // to properties. 
     423            this.units = this.projection.getUnits() || 
     424                         this.units || this.map.units; 
     425             
    415426            this.initResolutions(); 
    416427             
    417428            if (!this.isBaseLayer) { 
  • lib/OpenLayers/Projection.js

    old new  
     1/* Copyright (c) 2006-2007 MetaCarta, Inc., published under a modified BSD license. 
     2 * See http://svn.openlayers.org/trunk/openlayers/repository-license.txt  
     3 * for the full text of the license. */ 
     4 
     5/** 
     6 * @requires OpenLayers/Util.js 
     7 *  
     8 * Class: OpenLayers.Projection 
     9 * Class for coordinate transformations between coordinate systems. 
     10 * Depends on the proj4js library. If proj4js is not available,  
     11 * then this is just an empty stub. 
     12 */ 
     13OpenLayers.Projection = OpenLayers.Class({ 
     14     
     15    /** 
     16     * Constructor: OpenLayers.Projection 
     17     * This class offers several methods for interacting with a wrapped  
     18     * pro4js projection object.  
     19     * 
     20     * Parameters: 
     21     * options - {Object} An optional object with properties to set on the 
     22     *           format 
     23     * 
     24     * Returns: 
     25     * An instance of OpenLayers.Projection 
     26     */ 
     27    initialize: function(projCode, options) { 
     28        OpenLayers.Util.extend(this, options); 
     29        this.projCode = projCode; 
     30        if (window.Proj4js) { 
     31            this.proj = new Proj4js.Proj(projCode); 
     32        } 
     33         
     34    }, 
     35     
     36    /** 
     37     * APIMethod: getCode 
     38     * Get the string SRS code. 
     39     */ 
     40    getCode: function() { 
     41        return this.proj ? this.proj.srsCode : this.projCode; 
     42    }, 
     43     
     44    /** 
     45     * APIMethod: getUnits 
     46     * Get the units string for the projection -- returns null if  
     47     * proj4js is not available.. 
     48     */ 
     49    getUnits: function() { 
     50        return this.proj ? this.proj.units : null; 
     51    }, 
     52 
     53    /** 
     54     * Method: toString 
     55     * Convert projection to string (getCode wrapper). 
     56     */ 
     57    toString: function() { 
     58        return this.getCode(); 
     59    }, 
     60 
     61    equals: function(projection) { 
     62        if (this.getCode() == projection.getCode()) { 
     63            return true; 
     64        } 
     65        return false; 
     66    }, 
     67 
     68    /* Method: destroy 
     69     * Destroy projection object. 
     70     */ 
     71    destroy: function() { 
     72        delete this.proj; 
     73        delete this.projCode; 
     74    }, 
     75     
     76    CLASS_NAME: "OpenLayers.Projection"  
     77 
     78});      
     79 
     80/** 
     81 * APIMethod: transform 
     82 * Read data from a string, and return an object whose type depends on the 
     83 * subclass.  
     84 *  
     85 * Parameters: 
     86 * point - {object} input horizontal coodinate 
     87 * sourceProj - {OpenLayers.Projection} source map coordinate system 
     88 * destProj - {OpenLayers.Projection} destination map coordinate system 
     89 * 
     90 * Returns: 
     91 * point - {object} trasnformed coordinate 
     92 */ 
     93OpenLayers.Projection.transform = function(point, source, dest) { 
     94    if (source.proj && dest.proj) { 
     95        point = Proj4js.transform(source.proj, dest.proj, point); 
     96    } 
     97    return point; 
     98}; 
  • lib/OpenLayers/Format/GeoJSON.js

    old new  
    443443                    if(geojson.type == null) { 
    444444                        geojson.type = "FeatureCollection"; 
    445445                        if(element.layer && element.layer.projection) { 
    446                             var proj = element.layer.projection
     446                            var proj = element.layer.projection.toString()
    447447                            if(proj.match(/epsg:/i)) { 
    448448                                geojson.crs = { 
    449449                                    "type": "EPSG", 
     
    473473        } else if (obj instanceof OpenLayers.Feature.Vector) { 
    474474            geojson = this.extract.feature.apply(this, [obj]); 
    475475            if(obj.layer && obj.layer.projection) { 
    476                 var proj = obj.layer.projection
     476                var proj = obj.layer.projection.toString()
    477477                if(proj.match(/epsg:/i)) { 
    478478                    geojson.crs = { 
    479479                        "type": "EPSG", 
  • lib/OpenLayers/Map.js

    old new  
    12361252     
    12371253    /** 
    12381254     * APIMethod: getProjection 
     1255     * This method returns a string representing the projection. In  
     1256     * the case of projection support, this will be the srsCode which 
     1257     * is loaded -- otherwise it will simply be the string value that 
     1258     * was passed to the projection at startup. 
     1259     * FIXME: In 3.0, we will remove getProjectionObject, and instead 
     1260     * return a Projection object from this function.  
    12391261     *  
    12401262     * Returns: 
    1241      * {String} The Projection of the base layer. 
     1263     * {String} The Projection string from the base layer or null.  
    12421264     */ 
    12431265    getProjection: function() { 
     1266        var projection = this.getProjectionObject(); 
     1267        return projection ? projection.getCode() : null; 
     1268    }, 
     1269     
     1270    /** 
     1271     * APIMethod: getProjectionObject 
     1272     * Returns the projection obect from the baselayer. 
     1273     * 
     1274     * Returns: 
     1275     * {<OpenLayers.Projection>} The Projection of the base layer. 
     1276     */ 
     1277    getProjectionObject: function() { 
    12441278        var projection = null; 
    12451279        if (this.baseLayer != null) { 
    12461280            projection = this.baseLayer.projection; 
  • lib/OpenLayers.js

    old new  
    175175            "OpenLayers/Layer/WFS.js", 
    176176            "OpenLayers/Control/MouseToolbar.js", 
    177177            "OpenLayers/Control/NavToolbar.js", 
    178             "OpenLayers/Control/EditingToolbar.js" 
     178            "OpenLayers/Control/EditingToolbar.js", 
     179            "OpenLayers/Projection.js" 
    179180        ); // etc. 
    180181 
    181182