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

git-svn-id: http://svn.openlayers.org/trunk/openlayers@5452 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2007-12-17 03:12:57 +00:00
parent 5884c02683
commit 428710e3af
4 changed files with 66 additions and 0 deletions

View File

@@ -494,6 +494,16 @@
}
function test_Bounds_transform(t) {
t.plan( 3 );
bounds = new OpenLayers.Bounds(10, -10, 20, 10);
bounds.transform(new OpenLayers.Projection("foo"), new OpenLayers.Projection("Bar"));
t.eq(bounds.toBBOX(), "10,-10,20,10", "null transform okay");
bounds.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913"));
t.eq(bounds.toBBOX(), "1113194.907778,-1118889.974702,2226389.815556,1118889.974702", "bounds for spherical mercator transform are correct");
bounds.transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));
t.eq(bounds.toBBOX(), "10,-10,20,10", "bounds for inverse spherical mercator transform are correct");
}
function test_17_Bounds_add(t) {
t.plan( 8 );

View File

@@ -102,6 +102,20 @@
t.ok( lonlat.equals(ll), "lonlat is set correctly");
}
function test_LonLat_transform(t) {
t.plan( 6 );
lonlat = new OpenLayers.LonLat(10, -10);
lonlat.transform(new OpenLayers.Projection("foo"), new OpenLayers.Projection("Bar"));
t.eq(lonlat.lon, 10, "lon for null transform is the same")
t.eq(lonlat.lat, -10, "lat for null transform is the same")
lonlat.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913"));
t.eq(Math.round(lonlat.lon), 1113195, "lon for spherical mercator transform is correct");
t.eq(Math.round(lonlat.lat), -1118890, "lat for spherical mercator correct")
lonlat.transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));
t.eq(lonlat.lon, 10, "lon for inverse spherical mercator transform is correct");
t.eq(Math.round(lonlat.lat), -10, "lat for inverse spherical mercator correct")
}
function test_08_LonLat_wrapDateLine(t) {
t.plan( 6 );