[OpenLayers-Users] setCenter not working with EPSG:900913 projection

Christopher Schmidt crschmidt at metacarta.com
Sun Jan 4 20:01:13 EST 2009


On Mon, Jan 05, 2009 at 09:37:38AM +1300, Robert Connolly wrote:
> 
> Hi Everyone,
> 
> I sent the following message before Christmas via Nabble, however I am
> unable to track down the reply I received. Can anyone help with my
> problem?
> 
> Regards,
> 
> Rob Connolly
> 
> --Original Message--
> 
> Hi, 
> 
> I'm having trouble using the setCenter method when using a EPSG:900913
> projection for a Google map layer, see my code below: 
> 
> map = new OpenLayers.Map('map', {projection: new
> OpenLayers.Projection("EPSG:900913")}); 
> var gmap = new OpenLayers.Layer.Google("Google Streets",
> { sphericalMercator: true }); // streets is the default 
> 
> map.addLayers([gmap]); 
> 
> 
> var center = new OpenLayers.LonLat(-41.27, 173.28); 

                              ^^^^^^

Lon,Lat is X,Y: you want 173.28, -41.27.

-- Chris

> alert('['+center.lon+','+center.lat+']'); 
> var proj = new OpenLayers.Projection("EPSG:4326"); 
> center.transform(proj, map.getProjectionObject()); 
> alert('['+center.lon+','+center.lat+']'); 
> map.setCenter(center, 13); 
> 
> I have the proj4js library installed and included on the page. It
> appears that the conversion is working (from the data being shown by my
> alert statements), however the center of the map remains on the
> equator/prime meridian intersection, when it should be over Nelson, New
> Zealand! 
> 
> Can anyone help? 
> 
> Regards, 
> 
> Rob Connolly
> 
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users

-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list