OpenLayers.getPixelFromLonLat don't return the correct values

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

OpenLayers.getPixelFromLonLat don't return the correct values

waelinsat
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: OpenLayers.getPixelFromLonLat don't return the correct values

jezaustin
Have you tried using map.getLayerPxFromViewPortPx? I found I needed this in my click handlers.

map.getLonLatFromPixel(
 map.getLayerPxFromViewPortPx(
  map.getPixelFromLonLat(
   new OpenLayers.LonLat(9.55,35.23)
  )
 )
);
Reply | Threaded
Open this post in threaded view
|

Re: OpenLayers.getPixelFromLonLat don't return the correct values

Andreas Hocevar-2
In reply to this post by waelinsat
This is a matter of resolution. Think of a pixel and a geographic location (o) inside the pixel:

 -------
|    o  |
|       |
|       |
 -------

This location is not in the center of the pixel. When you call getPixelFromLonLat, you get the pixel in the above image. And when you then call getLonLatFromPixel with the resulting pixel, you get the center of the pixel as location:

 -------
|       |
|   o   |
|       |
 -------

This is the difference you're seeing, and there is no way to resolve it other than doing this conversion at a resolution that is higher than your desired accuracy of geographic coordinates.

Andreas.


On Tue, May 14, 2013 at 10:57 PM, waelinsat <[hidden email]> wrote:
Hi All;

I just need some help. It seems like the OpenLayers.getPixelFromLonLat don't
return a correct values, there's always a little difference.

For example :

map.getLonLatFromPixel( map.getPixelFromLonLat( new
OpenLayers.LonLat(9.55,35.23) ) ) in a normal case returns the same long/lat
which is (9.55,35.23) but this is not the result, i always had values like
9.59874, 35.60154 ... i know that it's not too far but i should resolve it.

There 's any solution for this ?

regards,



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/OpenLayers-getPixelFromLonLat-don-t-return-the-correct-values-tp5053241.html
Sent from the OpenLayers Dev mailing list archive at Nabble.com.
_______________________________________________
Dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-dev



--
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.

_______________________________________________
Dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-dev