[ka-Map-users] GeoCoordinates to Pixel position

ramesh karra karrarm at yahoo.com
Fri May 12 16:44:44 EDT 2006


The existing method sequence (which I mentioned the
earlier mail) of
GeoToPix()
adjustPixelPosition() 
does not seem to work when extents  are changed. 

Actually, I found this when using
Tooltips(kaToolTip.js). the moveGeo() method does not
seem to move correctly. The adjustPixelPosition() used
in this method does not seem to return correct pixel
co-ordinates because. Upon some investigation I found
that it works better if adjustPixelPosition() is
modified to not to add 'offsetLeft' and 'offsetTop'
but  then it would break other places where this
method is used. But by writing a new method that is
used only in kaToolTip.moveGeo() I was able to fix
this issue.

Thanks
Ramesh

--- Paul Spencer <pspencer at dmsolutions.ca> wrote:

> Hi,
> 
> this is tricky math :)  The correct pixel position
> needs to be  
> calculated in a number of steps depending on how you
> want to use the  
> pixel position.
> 
> The math for taking a geographic position and
> calculating its pixel  
> position is handled starting with addObjectGeo ...
> you can trace the  
> calls from there.
> 
> The simple calculation is to take the geographic
> coordinates and  
> multiply by the cellsize (geographic coordinates per
> pixel).
> 
> var px = gx * this.cellSize;
> var py = gy * this.cellSize; //or myKaMap.cellSize
> 
> now you have to convert from geographic space to
> browser space  
> because in the real world up is positive and in
> browser space, down  
> is positive
> 
> py = -1 * py;
> 
> now you have to convert to viewport coordinates,
> which are mirrored  
> on x/y to get the image to show up in the viewport:
> 
> px = -1*px;
> py = -1*py;
> 
> now you have to adjust for a variable origin
> 
> px = px - this.xOrigin;
> py = py - this.yOrigin;  // or maybe it is +?
> 
> px and py are now relative to the top, left of the
> viewport element.   
> If you want page-relative coordinates, you need to
> find the top/left  
> of the viewport and add px/py.
> 
> I may not have this exactly right, whenever I need
> to do something  
> like this I usually end up spending time in the
> debugger tracing the  
> values to figure out exactly which combination I
> need :(
> 
> The pixel coordinates are going to be different at
> every zoom scale  
> because the origin and cell size changes.
> 
> You can get notified of changes in the scale by
> registering for  
> KAMAP_SCALE_CHANGED event.
> 
> Cheers
> 
> Paul
> 
> PS not sure why you want to do this.  kaMap already
> includes  
> functions for doing most of this in the other
> direction.  Is there a  
> need for the reverse?
> 
> On 11-May-06, at 7:52 PM, Wei Yang, Ng - Wayne
> wrote:
> 
> > Hi Ramesh,
> >     I am doing similar stuff and I am having the
> same problem. (The  
> > map slides to anywhere else but the point that I
> want)A possible  
> > solution
> > (not tested) is to create a javascript function
> that kicks in when  
> > the zoom level changes. (a few events trigger a
> zoom level change  
> > eg. mouse scroll, icon click, KB +/-)
> > The function finds out(a set variable perhaps) if
> the map is  
> > supposed to zoom to a certain geographic
> coordinate and reinvokes  
> > the function(supplying lat/long of course) that
> moves/slides to it.  
> > This idea is based on the observation that while
> the map is  
> > sliding, I am able to interrupt the action by dbl
> clicking anywhere  
> > on the map.
> >
> > Cheers,
> > Wayne
> >> Hi,
> >>
> >> I am trying to figure out the correct pixel
> position
> >> for a given geo-coordinates in all zoom levels.
> >>
> >> I looked at the code, and it looks like the
> following
> >> sequence
> >> p = kaMap.geoToPix(geox,geoy) newxy =  
> >> kaMap.currentTool.adjustPixPosition(p[0]*-1,
> >> p[1]*-1)
> >>
> >> seem to work fine if the zoom level is not
> changed but
> >> only extents are changed.
> >>
> >> How do I calculate the correct pixel position
> when
> >> zoom level(or scales) change?
> >>
> >> Thanks
> >> Ramesh
> > _______________________________________________
> > ka-Map-users mailing list
> > ka-Map-users at lists.maptools.org
> >
>
http://lists.maptools.org/mailman/listinfo/ka-map-users
> 
>
+-----------------------------------------------------------------+
> |Paul Spencer                          
> pspencer at dmsolutions.ca   |
>
+-----------------------------------------------------------------+
> |Applications & Software Development                
>              |
> |DM Solutions Group Inc                
> http://www.dmsolutions.ca/|
>
+-----------------------------------------------------------------+
> 
> 
> 
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


More information about the ka-Map-users mailing list