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

1 Answer 1

3

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...

3
  • Thanks for your answer but it wont work. I am transforming bounds to put it into maxExtent of a map, so i dont have map object yet. I want the WMS request to be sent with BBOX of transformed coordinates, the llbbox returns them in 4326. The map is created after pressing a button. When i press it for the first time maxExtent is with the coords in latlon but when i press it second time it works.
    – gisit
    Commented Aug 8, 2012 at 13:28
  • 1
    Strange but i managed to fix it. Just declared proj2180 and proj4326 earlier in my app and it started working. Maybe its take some time to initialize these variables and if they are not initialized, transform will just do nothing.
    – gisit
    Commented Aug 8, 2012 at 14:33
  • it is good to hear that your code is working :)
    – urcm
    Commented Aug 8, 2012 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.