W3C home > Mailing lists > Public > www-svg@w3.org > January 2002

Mapping client pixel coordinates to global coordinates

From: Michael Bjerregaard Pedersen <mbp@back-bone.dk>
Date: Wed, 9 Jan 2002 15:35:12 +0100
Message-ID: <C16B4EC7E611D411A88600D0B75AC2DA460F56@server01.int>
To: "'www-svg@w3.org'" <www-svg@w3.org>
The archive search doesn't work at the moment, so forgive me if this
question has been asked 100 times before.

I'm using the Adobe SVG client.
When I click on something I get an onClick event and is able to get the
mouse coordinates relative to the clients window. How can I map/translate
these to coordinates that are relative to the drawings (0,0)?

I have found example code for the most obvious problems, like scale, scroll
and pan, but I can't figure out how I make the client give enough
information to let me calculate the ratio between a client pixel and the
drawing.
On example I found did the following:

	var viewbox = new String(SVGRoot.getAttribute("viewBox"));
	var viewboxes = viewbox.split(' ');
	ulXCorner = viewboxes[0];
	ulYCorner = viewboxes[1];
	var width = viewboxes[2];
	var height = viewboxes[3];
	var pixWidth = SVGRoot.getAttribute("width");
	var pixHeight = SVGRoot.getAttribute("height");
	origPixSize = width / pixWidth;

but this only works if the width and height attributes does not have units.
Unfortunately my SVG-files (converted from AutoCad) specifies units for the
aforementioned attributes as shown here:

<svg onload="SVGinit(evt)" onfocusin="SVGfocusin(evt)"
onfocusout="SVGfocusout(evt)" onactivate="SVGactivate(evt)"
onclick="SVGclick(evt)" onmousemove="SVGmousemove(evt)"
onmouseup="SVGmouseup(evt)" onmousedown="SVGmousedown(evt)"
onmouseover="SVGmouseover(evt)" onmouseout="SVGmouseout(evt)"
onscroll="SVGscroll(evt)" onzoom="SVGzoom(evt)" onresize="SVGresize(evt)"
style = "shape-rendering:optimizeSpeed; text-rendering:optimizeSpeed;
image-rendering:optimizeSpeed" width = "9in" height = "6in" viewBox =
"-139766 -83868.2 339501 252740" preserveAspectRatio = "xMidYMid"><script
type="text/javascript" xlink:href="/js/svg.js"/><rect x = "-139766" y =
"-83868.2" style = "fill:#FFFFFF" width = "339501" height = "252740"/> 

Any ideas?

TIA
Regards
Michael Bjerregaard-Pedersen
Backbone
Received on Wednesday, 9 January 2002 09:35:48 GMT

This archive was generated by hypermail 2.3.1 : Friday, 8 March 2013 15:54:21 GMT