OpenLayers OpenLayers

Changeset 5452

Show
Ignore:
Timestamp:
12/16/07 22:12:57 (1 year ago)
Author:
crschmidt
Message:

Add support for reprojection of lonlats/bounds. (Closes #1213)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/BaseTypes/Bounds.js

    r4985 r5452  
    426426        return quadrant;  
    427427    }, 
     428     
     429    /** 
     430     * APIMethod: transform 
     431     * Transform the Bounds object from source to dest.  
     432     * 
     433     * Parameters:  
     434     * source - {<OpenLayers.Projection>} Source projection.  
     435     * dest   - {<OpenLayers.Projection>} Destination projection.  
     436     * 
     437     * Returns: 
     438     * {<OpenLayers.Bounds>} Itself, for use in chaining operations. 
     439     */ 
     440    transform: function(source, dest) { 
     441        var ll = OpenLayers.Projection.transform( 
     442            {'x': this.left, 'y': this.bottom}, source, dest); 
     443        var ur = OpenLayers.Projection.transform( 
     444            {'x': this.right, 'y': this.top}, source, dest); 
     445        this.left   = ll.x; 
     446        this.bottom = ll.y; 
     447        this.right  = ur.x; 
     448        this.top    = ur.y; 
     449        return this; 
     450    }, 
    428451 
    429452    /** 
  • trunk/openlayers/lib/OpenLayers/BaseTypes/LonLat.js

    r4985 r5452  
    113113        return equals; 
    114114    }, 
     115 
     116    /** 
     117     * APIMethod: transform 
     118     * Transform the LonLat object from source to dest.  
     119     * 
     120     * Parameters:  
     121     * source - {<OpenLayers.Projection>} Source projection.  
     122     * dest   - {<OpenLayers.Projection>} Destination projection.  
     123     * 
     124     * Returns: 
     125     * {<OpenLayers.LonLat>} Itself, for use in chaining operations. 
     126     */ 
     127    transform: function(source, dest) { 
     128        var point = OpenLayers.Projection.transform( 
     129            {'x': this.lon, 'y': this.lat}, source, dest); 
     130        this.lon = point.x; 
     131        this.lat = point.y; 
     132        return this; 
     133    }, 
    115134     
    116135    /** 
  • trunk/openlayers/tests/BaseTypes/test_Bounds.html

    r4059 r5452  
    495495 
    496496      } 
     497    function test_Bounds_transform(t) { 
     498        t.plan( 3 ); 
     499        bounds = new OpenLayers.Bounds(10, -10, 20, 10); 
     500        bounds.transform(new OpenLayers.Projection("foo"), new OpenLayers.Projection("Bar"));  
     501        t.eq(bounds.toBBOX(), "10,-10,20,10", "null transform okay"); 
     502        bounds.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913"));  
     503        t.eq(bounds.toBBOX(), "1113194.907778,-1118889.974702,2226389.815556,1118889.974702", "bounds for spherical mercator transform are correct"); 
     504        bounds.transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));  
     505        t.eq(bounds.toBBOX(), "10,-10,20,10", "bounds for inverse spherical mercator transform are correct"); 
     506    } 
    497507 
    498508    function test_17_Bounds_add(t) { 
  • trunk/openlayers/tests/BaseTypes/test_LonLat.html

    r4059 r5452  
    103103    } 
    104104 
     105    function test_LonLat_transform(t) { 
     106        t.plan( 6 ); 
     107        lonlat = new OpenLayers.LonLat(10, -10); 
     108        lonlat.transform(new OpenLayers.Projection("foo"), new OpenLayers.Projection("Bar"));  
     109        t.eq(lonlat.lon, 10, "lon for null transform is the same") 
     110        t.eq(lonlat.lat, -10, "lat for null transform is the same") 
     111        lonlat.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913"));  
     112        t.eq(Math.round(lonlat.lon), 1113195, "lon for spherical mercator transform is correct"); 
     113        t.eq(Math.round(lonlat.lat), -1118890, "lat for spherical mercator correct") 
     114        lonlat.transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));  
     115        t.eq(lonlat.lon, 10, "lon for inverse spherical mercator transform is correct"); 
     116        t.eq(Math.round(lonlat.lat), -10, "lat for inverse spherical mercator correct") 
     117    } 
     118     
    105119    function test_08_LonLat_wrapDateLine(t) { 
    106120        t.plan( 6 );