[GIS] OpenLayers.Bounds transform not working as expected

openlayers-2

I have problem with transforming bounds. It is not working for the first time, later it works just fine. At first i thought that something was still loading butsearching in firebug shows that nothing gets loaded and i think everything is provided for it to work:

Here is the code:

        Proj4js.defs["EPSG:2180"] = "+proj=tmerc +lat_0=0 +lon_0=19 +k=0.9993 +x_0=500000 +y_0=-5300000 +ellps=GRS80 +units=m +no_defs";

        var proj2180 = new OpenLayers.Projection("EPSG:2180");
        var proj4326 = new OpenLayers.Projection("EPSG:4326");

        var bounds = OpenLayers.Bounds.fromArray(record.get("llbbox"));
        bounds.transform(proj4326, proj2180);
        console.log(bounds);

This code is placed in function. When i run it for the first time i get following console output:
13.897781645001,48.960416159343,24.621296204369,54.83756633314

when second time i get:
143457.09623933677,137520.1675486639,876176.7241084952,786832.4073041743

Best Answer

try to use:

Proj4js.defs["EPSG:2180"] = "+proj=tmerc +lat_0=0 +lon_0=19 +k=0.9993 +x_0=500000 
                             +y_0=-5300000 +ellps=GRS80 +units=m +no_defs";

var proj2180 = new OpenLayers.Projection("EPSG:2180");
var proj4326 = new OpenLayers.Projection("EPSG:4326");

var bounds = map.getExtent();
bounds.transform(proj4326, proj2180);
console.log(bounds);

and

map.getExtent().toGeometry().toString() returns you to Polygon...

i hope it helps you...