[OpenLayers-Users] Reproject co-ordinate points

Smaran Harihar smaran.harihar at gmail.com
Wed Aug 29 09:39:50 PDT 2012


Hi Phil,

It seems I misunderstood. So the lonLat.projection is setting the lonLat to
the 900913 lat and lon right? and then when we use transform(), that is
when we are converting it to 4326. So i did not need project.

                      var lonLat = evt.xy;
                      var proj = new OpenLayers.Projection("EPSG:4326");
                      var nlonLat = new
OpenLayers.LonLat(panel.map.getLonLatFromViewPortPx(lonLat).lon,
panel.map.getLonLatFromViewPortPx(lonLat).lat);
                      nlonLat.transform(panel.map.getProjectionObject(),
panel.map.displayProjection);

Works great.

Thanks,
Smaran

On Sun, Aug 26, 2012 at 6:13 PM, Phil Scadden <p.scadden at gns.cri.nz> wrote:

> its very easy to do the transform in js, especially between 4326 and
> 900913. eg
>                  var lonLat = this.map.getLonLatFromPixel(e.xy);
>                  if (this.map.displayProjection) {
>                      lonLat.transform(this.map.getProjectionObject(),
>                          this.map.displayProjection );
>                  }
> If you look at docs for LonLat, you will see the transform method. It
> needs two projection objects. Create one for 4326
> eg var p4326 = new OpenLayers.Projection("EPSG:4326");
>
> and then the other will be the map projection. Code might something like:
> var p4326 = new OpenLayers.Projection("EPSG:4326");
> lonLat = new OpenLayers.LonLat(lon,lat);
> lonLat.project(p4326,map.getProjectionObject());
>
>
>
> Notice: This email and any attachments are confidential. If received in
> error please destroy and immediately notify us. Do not copy or disclose the
> contents.
>
> _______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>



-- 
Thanks & Regards
Smaran Harihar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20120829/0203a722/attachment.html>


More information about the Users mailing list