Openlayers.Bounds().transform() not doing transform

2.1k views Asked by At

Solved. See http://osgeo-org.1560.n6.nabble.com/Openlayers-Bounds-transform-not-doing-transform-td3912787.html .

I am trying to do a coordinate transform of bounds in Openlayers, and have tried the following, which, for both console.log() statements, gives me the same bounds in both cases (but I expect the second statement to give me bounds in EPGS:4326):

http://pastebin.com/ADRwjLAy

In both console.log() statements, I get the following object (c&p from Chrome javascript debugger):

Class
bottom: 4816289.746171
centerLonLat: null
left: 189775.37995
right: 761662.354535
top: 5472414.143295
__proto__: Object

I read the documentation for proj4js with openlayers at trac.osgeo.org/openlayers/wiki/Documentation/Dev/proj4js , and it tells me:

OpenLayers integrates with Proj4js if the library is available. This will make using it a bit easier. Having it in the same folder as OpenLayers.js will make it available.

Which I did via a symlink:

matt@xxxxxxxx:/var/www/xxxxx$ ll /var/www/OpenLayers-2.10/
total 1008
drwxr-xr-x 13 matt matt   4096 Nov  1 01:49 .
drwxrwxrwx 30 root root   4096 Nov  1 01:43 ..
-rw-r--r--  1 matt matt 945828 Sep  9  2010 OpenLayers.js
...
lrwxrwxrwx  1 matt matt     31 Nov  1 01:49 proj4js.js -> /var/www/proj4js/lib/proj4js.js
...

Can someone help me diagnose what I'm doing wrong here?

Thanks, Matt

1

There are 1 answers

2
TomH On

Well the main problem is that your page doesn't load proj4js.js at all. You are presumably assuming that OpenLayers will load it automatically, but it doesn't, so you need to load it yourself.

As OpenLayers doesn't have EPSG:26915 support built in it needs proj4js in order to do the transform you want.

A second issue is that you way want to define EPSG:26915 explicitly by adding a line to your javascript that looks like this:

Proj4js.defs["EPSG:26915"] = "+proj=utm +zone=15 +ellps=GRS80 +datum=NAD83 +units=m +no_defs";

Without that I think proj4js should try and load the definition from spatialreference.org but that didn't seem to be working for me when I tried it.