[GIS] What’s wrong with the Proj4 transformation

javascriptproj

I am having trouble converting a projected coordinate EPSG:28355 to WGS84 EPSG:4326 using Proj4js. I know by default Proj4 will not convert to EPSG:28355 so I went to spatialreference.org and got the proj4js format and placed it in my defs.

Now I know it can work because when I have the code below:

    var gridCoordinate = new Proj4js.Point(easting,northing);

alert(gridCoordinate);

var wgsPoint = new Proj4js.transform(theZone, wgs84, gridCoordinate);

alert(wgsPoint);

I get these results – same order as the alerts called above.

enter image description here

enter image description here

To me that looks like it has worked.

Then for some reason when I was done checking that it worked I removed the alerts so that my code looked like this

var gridCoordinate = new Proj4js.Point(easting,northing);
//alert(gridCoordinate);
var wgsPoint = Proj4js.transform(theZone, wgs84, gridCoordinate);
//alert(wgsPoint);

The thing stops working and gives me a projected coordinate on the WGS84 basemap which blows me off the edge of the earth.

So I kept playing around and put in one alert to see what the final coordinate looked liek (code below)

var gridCoordinate = new Proj4js.Point(easting,northing);
//alert(gridCoordinate);
var wgsPoint = Proj4js.transform(theZone, wgs84, gridCoordinate);
alert(wgsPoint);

And I got the following result

enter image description here

Same as the starting coordinate it looks like the conversion has not worked at all. Why on earth would an alert call be affecting the output of this conversion? Have I declared or am I setting my variables incorrectly?

Thanks

Ando

Best Answer

This may be an issue of loading time (if you are using proj4js.js). Through the alerts there is enough time for loading the complete script. You could try to use proj4js-compressed.js instead.