[ka-Map-users] pixToGeo question
Paul Spencer
pspencer at dmsolutions.ca
Sun Sep 11 22:18:48 EDT 2005
Hi Brent,
you have unwittingly uncovered one of my skeletons ... this code is
pretty raw, I got it to work one day without truely understanding why it
was working and ... well, its not pretty ...
When you add an object using addObjectGeo, it doesn't follow quite the
same logic as you have applied.
addObjectPix subtracts the xOrigin and yOrigin values from the pixel
location to get the actual display location (xOrigin and yOrigin were
required to prevent problems with the pixel location of the images
becoming so large that some browsers switched to scientific notation and
started truncating the numbers). So in case two, the object will be
positioned at -xOrigin, -yOrigin.
In case one, pixToGeo is adding the xOrigin and yOrigin offsets if you
pass true ... so the actual location is +xOrigin, +yOrigin ... hence the
difference.
If you pass false to pixToGeo, it should return you the right numbers to
match case two. However ... one of the problems that I know about is
with signs ... something weird happens and stuff gets the wrong sign, I
haven't figured it out yet. I don't think that is the case here though,
since you should be getting 0,0 in both cases (and sign shouldn't matter).
I think the real problem is that you aren't really supposed to use
addObjectPix because of the xOrigin,yOrigin shift. What you would
really need to do to get both cases to work would be:
map.addObjectGeo( oCanvas, 0, 0, o1 );
map.addObjectPix( oCanvas, -map.xOrigin, -map.yOrigin, o2 );
Not sure if my explanation is coherent ...
Cheers
Paul
Brent Pedersen wrote:
> hi, i don't understand what's going on in my test script. i expect case
> 1 and case 2 to show up in the same location: they dont.
>
> map = new kaMap('viewport');
>
> oCanvas = map.createDrawingCanvas(5);
> var o1 = document.createElement('img');
> var o2 = document.createElement('img');
> o1.src = 'images/up.jpg' ;
> o2.src = 'images/up.jpg' ;
>
>
> // case 1: convert pixel (0,0 to geo and addObjectGeo):
> var xg = map.pixToGeo(0,0,true);
> map.addObjectGeo( oCanvas, xg[0], xg[1], o1 );
>
> // case 2: just addObject Pix
> var xp = [0,0];
> map.addObjectPix( oCanvas, xp[0], xp[1], o2 );
>
>
> i have tried pixToGeo with and without the 3rd arg.
>
> what am i missing? i'm using the default omap example mapfile and the
> CVS version of kamap.
>
> maybe i just need a primer on how these relate??
>
> thanks for any suggestions,
> -brent
>
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> 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/|
+-----------------------------------------------------------------+
More information about the ka-Map-users
mailing list