[OpenLayers-Users] Strange behaviour after panning

Christopher Schmidt crschmidt at metacarta.com
Wed Apr 9 07:06:55 EDT 2008


On Tue, Apr 08, 2008 at 07:28:24PM -0700, Pedro Simonetti wrote:
> 
> After some investigations, I found how to fix it.
> 
> I've changed the piece of the code where it calculates the coordinates,
> from:
> 
>   var lonlat = map.getLonLatFromLayerPx(evt.xy);
> 
> To:
> 
>   var lonlat = map.getLonLatFromViewPortPx(evt.xy);
> 
> Now it works fine. 
> 
> I'm just wondering, what's the difference of "getLonLatFromLayerPx", and
> "getLonLatFromViewPortPx"? I've looked at the docs but I still don't get it.
> At first glance, I thought that these methods were similars.

The answer is actually: "THey're the same insofar as you shouldn't need
to use either one of them" :)

Both of these are really designed to be internal methods: I've just
changed their definition from APIMethod to Method. The one you *shoul*
be using is the more nicely named getLonLatFromPixel: this hides the
fact that you have to worry about any of this stuff.

In reality, "FromLayerPx" is designed to work in the pixels of the
layer: the pixels of the layer are *not* shifted when you drag, but are
instead kept the same until you zoom (only the map container is shifted
when you drag). End result is that you'll be off until you zoom, if you 
use the FromLayerPx.

In any case: We providedd getLonLatFromPixel as the main 'API' property
so that people wouldn't have to use a funky-named property: it's a
wrapper around getLonLatFromViewPortPx.

Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list