Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

share|improve this question
add comment

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

share|improve this answer
    
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. –  Patryk Sosinski Aug 8 '12 at 13:28
    
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. –  Patryk Sosinski Aug 8 '12 at 14:33
    
it is good to hear that your code is working :) –  Aragon Aug 8 '12 at 14:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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