[OpenLayers-Users] transform help please

Dash jimlug at co.clackamas.or.us
Thu Nov 19 13:12:51 EST 2009


Aloha Thursday folks,

I am banging my head against the problem for the last several hours.  I have
went through numerous examples and utilized OpenLayers tutorial on
reprojecting points without any success.  I've even used the Proj4js Wiki
without any help.  Could some please shed some light on what I am doing
wrong?

Here is the scenario.  I am trying to transform some coordinates from
EPSG:2913 to EPSG:900913.  I've also tried a simplified version using
EPSG:4326 -> EPSG:900913.  Anyway, the transform is not happening for some
odd reason.  I do have the proj4js library within my code and I have added
EPSG definition to my /proj4js/lib/def directory.  I am checking if the
projection by using the getUnits function of the projection class within
OpenLayers.  If the units come back null, then the proj4js library is
unavailable.  Why is this?  I'm so confused.  This should be rather straight
forward.  Anyway, here is some of my code.  Hopefully someone can help me
out.  Thanks.

<head>
<script src="http://openlayers.org/dev/lib/OpenLayers.js"
type="text/javascript"></script>
<script src="./proj4js/lib/proj4js.js"></script>
<script src="proj4js/lib/defs/EPSG2913.js"></script>
<script src="proj4js/lib/defs/EPSG900913.js"></script>
<script src="proj4js/lib/defs/EPSG4326.js"></script>
</head>

<script type="text/javascript">
var map;
function init(){
	var options = {
		//projection: new OpenLayers.Projection("EPSG:900913"),		// Map projection
		projection: "EPSG:900913",
		displayProjection: new OpenLayers.Projection("EPSG:4326"),	// Display
projection
		units: "m",
		numZoomLevels: 5,
		maxResolution: 156543.0339,
        maxExtent: new OpenLayers.Bounds(-13698618.8209569, 5595988.4768255,
-13521569.8682338, 5701506.49106001)
	};

	// Initiate Map Controls
	map.addControl(new OpenLayers.Control.LayerSwitcher());
	map.addControl(new OpenLayers.Control.MousePosition());
	
	// Create Google Mercator Layers
	var gmap = new OpenLayers.Layer.Google("Google
Streets",{'sphericalMercator': true, numZoomLevels: 20});
	var gphy = new OpenLayers.Layer.Google("Google Physical",
{'sphericalMercator': true, type: G_PHYSICAL_MAP, numZoomLevels: 20});
    var gsat = new OpenLayers.Layer.Google("Google
Satellite",{'sphericalMercator': true, type: G_SATELLITE_MAP, numZoomLevels:
20});
    var ghyb = new OpenLayers.Layer.Google("Google
Hybrid",{'sphericalMercator': true, type: G_HYBRID_MAP, numZoomLevels: 20});

map.addLayers([gmap, gphy, gsat, ghyb]);

var srcProj = new OpenLayers.Projection("EPSG:4326");
alert(srcProj.getUnits());
var point = new OpenLayers.LonLat(-71, 42);
point.transform(srcProj, map.getProjectionObject());

if(point.transformed)
	{
		alert("point already transformed");
	}

Proj4js.transform(srcProj, map.getProjectionObject(), point);

Any suggestions would be greatly appreciated.  THANKS...
-- 
View this message in context: http://n2.nabble.com/transform-help-please-tp4033462p4033462.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.



More information about the Users mailing list