[postgis-users] How can i get accurate world coordinate (WGS84) with mouse click?

Alex Chew alex_chew at 163.com
Thu Nov 23 19:53:10 PST 2006


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





More information about the postgis-users mailing list