[OpenLayers-Users] Reproject co-ordinate points

Smaran Harihar smaran.harihar at gmail.com
Sun Aug 26 18:43:47 PDT 2012


I am trying out this code,

                      var lonLat = evt.xy;
                      console.log(lonLat.lon, lonLat.lat);
                      var proj = new OpenLayers.Projection("EPSG:4326");
                      lonLat = new OpenLayers.LonLat(lonLat.lon,
lonLat.lat);
                      lonLat.project(proj, map.getProjectionObject());

And I keep getting this error,

undefined undefined (for the lonLat.lon, lonLat.lat)
Uncaught TypeError: Object lon=NaN,lat=NaN has no method 'project'
(for  lonLat.project(proj, map.getProjectionObject());)

What should I correct?

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/20120826/ea887a52/attachment-0001.html>


More information about the Users mailing list