You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Alex Chew <ch...@gmail.com> on 2006/11/24 10:31:54 UTC

How can i get accurate world coordinate (WGS84) with mouse click?

Hi,gentlmen,
 I am not sure it is fit to ask such a question here. It puzzled me several
days.Thanks a lot to your kindly advise.
 Using svg and javascript I build a simple GIS application. GIS data are
under WGS84 coordinate. Data in my application falles in lat( 103.75-104.1
),lon(30.3-30.5), which descripts a Chinese city, Chengdu.
 For sake of simplification, I set svg attribute,
  viewBox = "103.75 -30.5 0.5 0.2"
  height = "600"
  width = "800"
 then, I changed viewBox to realize zoom and pan. It seems worked
well.Problems happened when  I try to mark user point on svg with mouse
click. I tried to convert screen points to world coordinate, but i could not
make it be accurate. It  seems number formate in javascript make such error.
code fragment,
 pointx = parseFloat(evt.getClientX());
 pointy = parseFloat(evt.getClientY());
 px = pointx/this.currentScale/this.ratioX;//translate screen point to world
one
 py = pointy/this.currentScale/this.ratioY;//translate screen point to world
one
 worldx = this.viewBoxX;
 worldy = this.viewBoxY;
 markx = worldx+px;
 marky = worldy+py;

What intrest me is when I look insight I found that markx is accurate while
marky not.
Would you please show me a hand?

Any advice are appreciated.
Thanks again
Alex

Re: How can i get accurate world coordinate (WGS84) with mouse click?

Posted by th...@kodak.com.
Hi Alex,

"Alex Chew" <ch...@gmail.com> wrote on 11/24/2006 04:31:54 AM:

>  For sake of simplification, I set svg attribute, 
>   viewBox = "103.75 -30.5 0.5 0.2"
>   height = "600"
>   width = "800" 
>  then, I changed viewBox to realize zoom and pan.

   This can be an expensive way to do zoom and pan. It would be better
to adjust a transform on a 'g'.

> I tried to convert screen points to world coordinate, but i could not 
make it be
> accurate.

   It is problematic to try and reproduce the SVG renderer's calculations
of coordinate system mapping.  I would strongly suggest using the
SVG method, "getScreenCTM",  to get the mapping from the local coordinate
system of an element in the document to screen pixels (such as returned
by getClientX/Y).

>  It  seems number formate in javascript make such error. code fragment, 
>  pointx = parseFloat(evt.getClientX());
>  pointy = parseFloat(evt.getClientY());
>  px = pointx/this.currentScale/this.ratioX;//translate screen point to 
world one
>  py = pointy/this.currentScale/this.ratioY;//translate screen point to 
world one 
>  worldx = this.viewBoxX;
>  worldy = this.viewBoxY;
>  markx = worldx+px;
>  marky = worldy+py; 
> What intrest me is when I look insight I found that markx is accurate 
while marky not.
> Would you please show me a hand?
> Any advice are appreciated.
> Thanks again
> Alex

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org