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 Dylan Browne <db...@mango-solutions.com> on 2006/06/13 15:44:23 UTC

Accessing event coordinates when zoomed

Hi,

(Not strictly a Batik Posting, although I am using Batik DOM to create my
SVG, so I hope that almost counts...!)

I am using JavaScript "evt.clientX" and "evt.clientY" (I have also tried
"screenX") to retrieve the co-ordinates of a mouseover event, and some extra
code then displays a label using these coordinates. (In essence, I'm
creating a souped-up tool-tip). 

This works fine in standard view, but once the SVG document has been zoomed,
the co-ordinates returned are no longer relative to the original
document,(as, of course, I would expect :). I'd be grateful if someone could
point me towards the correct JS syntax so the coordinates I return are in
relation to my zoomed/panned document.

Thanks a lot in advance for any help,

Regards,
Dylan 


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


Re: Accessing event coordinates when zoomed

Posted by Andreas Neumann <ne...@karto.baug.ethz.ch>.
>Excellent, have it working now. Just for the info of others who may read
>this post and wish to use your mapApp class... I was trying to transform to
>a different position in the DOM hierarchy (exactly as your tooltips do), and
>I was neglecting to pass in an appropriate node to the function to allow the
>transform to work.
>  
>
ah, that explains it.

Andreas

-- 
----------------------------------------------
Andreas Neumann
Institute of Cartography
ETH Zurich
Wolfgang-Paulistrasse 15
CH-8093  Zurich, Switzerland

Phone: ++41-44-633 3031, Fax: ++41-44-633 1153
e-mail: neumann@karto.baug.ethz.ch
www: http://www.carto.net/neumann/
SVG.Open: http://www.svgopen.org/
Carto.net: http://www.carto.net/


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


RE: Accessing event coordinates when zoomed

Posted by Dylan Browne <db...@mango-solutions.com>.
>if you use my "mapApp" object it should just work.....

Excellent, have it working now. Just for the info of others who may read
this post and wish to use your mapApp class... I was trying to transform to
a different position in the DOM hierarchy (exactly as your tooltips do), and
I was neglecting to pass in an appropriate node to the function to allow the
transform to work.

Many thanks for all the help,

Cheers,
Dylan



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


Re: Accessing event coordinates when zoomed

Posted by Andreas Neumann <ne...@karto.baug.ethz.ch>.
>We only need to support Adobe Viewer, so I've tried to use some JS similar
>to that in the mapApp.js as suggested.
>
>  
>
if you use my "mapApp" object it should just work.

If you launch the tooltip example 
(http://www.carto.net/papers/svg/gui/tooltips/) and zoom in with the 
Adobe viewer, the tooltips still properly follow the mouse. They don't 
compensate for the scale (means that the tooltips scale) but they follow 
the mouse properly.

>I call it like this...
>
>function getMyCoords(evt){
>      // Pass in the event from the screen
>	var thePoint = calcCoord(evt);
>	// get the zoomed/panned values from the point      
>	x = thePoint.getX();
>      y = thePoint.getY();
>}
>  
>

calcCoord() is a method of the mapApp object, not a standalone function. 
Maybe if you rewrote the function it should work as well. But the mapApp 
object also takes into account the use of viewBoxes (I recommend to use 
viewBoxes anyway). What calcCoord returns is an SVGPoint.

Andreas

-- 
----------------------------------------------
Andreas Neumann
Institute of Cartography
ETH Zurich
Wolfgang-Paulistrasse 15
CH-8093  Zurich, Switzerland

Phone: ++41-44-633 3031, Fax: ++41-44-633 1153
e-mail: neumann@karto.baug.ethz.ch
www: http://www.carto.net/neumann/
SVG.Open: http://www.svgopen.org/
Carto.net: http://www.carto.net/


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


RE: Accessing event coordinates when zoomed

Posted by Dylan Browne <db...@mango-solutions.com>.
Thanks Andreas for the reply,

I've tried to put that into practice, but doesn't seem to be quite working.

I do need to develop these tooltips rather than use the existing supported
ones as they may become fairly intricate in the future.

We only need to support Adobe Viewer, so I've tried to use some JS similar
to that in the mapApp.js as suggested.

I call it like this...

function getMyCoords(evt){
      // Pass in the event from the screen
	var thePoint = calcCoord(evt);
	// get the zoomed/panned values from the point      
	x = thePoint.getX();
      y = thePoint.getY();
}

... is this the correct way to get the real values? Its doesn't seem to work
when zoomed or not. The values that are returned from this seem to very
small compared to the locations I'd expect in the document... EG values less
than 10 where I'd expect values in the hundreds. If this syntax is correct
I'll look elsewhere for where my problem lies.

Thanks again for any (more) help,

Kind regards,
Dylan.

-----Original Message-----
From: Andreas Neumann [mailto:neumann@karto.baug.ethz.ch] 
Sent: 13 June 2006 15:57
To: batik-users@xmlgraphics.apache.org
Subject: Re: Accessing event coordinates when zoomed

Hi Dylan,

.getScreenCTM() is your friend here.

Here is some code:

function calcCoord(evt) {
    var svgPoint = document.documentElement.createSVGPoint();
    svgPoint.x = evt.clientX;
    svgPoint.y = evt.clientY;
    var matrix = evt.target.getScreenCTM(); //alternatively use a 
different node reference here instead of evt.target, f.e. if you want to 
calculate to a different node in the hierarchy
    svgPoint = svgPoint.matrixTransform(matrix.inverse());
   return svgPoint;
}

If you need standard tooltips, Batik already provides tooltips.

Unfortunately, the Adobe SVG viewer version 3 neither supports tooltips 
nor .getScreenCTM.

For this viewer there is a workaround:
http://www.carto.net/papers/svg/gui/mapApp/

And here is a tooltip example that works in all browsers:
http://www.carto.net/papers/svg/gui/tooltips/index.svg

All the best,
Andreas

Dylan Browne wrote:

>Hi,
>
>(Not strictly a Batik Posting, although I am using Batik DOM to create my
>SVG, so I hope that almost counts...!)
>
>I am using JavaScript "evt.clientX" and "evt.clientY" (I have also tried
>"screenX") to retrieve the co-ordinates of a mouseover event, and some
extra
>code then displays a label using these coordinates. (In essence, I'm
>creating a souped-up tool-tip). 
>
>This works fine in standard view, but once the SVG document has been
zoomed,
>the co-ordinates returned are no longer relative to the original
>document,(as, of course, I would expect :). I'd be grateful if someone
could
>point me towards the correct JS syntax so the coordinates I return are in
>relation to my zoomed/panned document.
>
>Thanks a lot in advance for any help,
>
>Regards,
>Dylan 
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
>For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
>  
>


-- 
----------------------------------------------
Andreas Neumann
Institute of Cartography
ETH Zurich
Wolfgang-Paulistrasse 15
CH-8093  Zurich, Switzerland

Phone: ++41-44-633 3031, Fax: ++41-44-633 1153
e-mail: neumann@karto.baug.ethz.ch
www: http://www.carto.net/neumann/
SVG.Open: http://www.svgopen.org/
Carto.net: http://www.carto.net/


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


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


Re: Accessing event coordinates when zoomed

Posted by Andreas Neumann <ne...@karto.baug.ethz.ch>.
Hi Dylan,

.getScreenCTM() is your friend here.

Here is some code:

function calcCoord(evt) {
    var svgPoint = document.documentElement.createSVGPoint();
    svgPoint.x = evt.clientX;
    svgPoint.y = evt.clientY;
    var matrix = evt.target.getScreenCTM(); //alternatively use a 
different node reference here instead of evt.target, f.e. if you want to 
calculate to a different node in the hierarchy
    svgPoint = svgPoint.matrixTransform(matrix.inverse());
   return svgPoint;
}

If you need standard tooltips, Batik already provides tooltips.

Unfortunately, the Adobe SVG viewer version 3 neither supports tooltips 
nor .getScreenCTM.

For this viewer there is a workaround:
http://www.carto.net/papers/svg/gui/mapApp/

And here is a tooltip example that works in all browsers:
http://www.carto.net/papers/svg/gui/tooltips/index.svg

All the best,
Andreas

Dylan Browne wrote:

>Hi,
>
>(Not strictly a Batik Posting, although I am using Batik DOM to create my
>SVG, so I hope that almost counts...!)
>
>I am using JavaScript "evt.clientX" and "evt.clientY" (I have also tried
>"screenX") to retrieve the co-ordinates of a mouseover event, and some extra
>code then displays a label using these coordinates. (In essence, I'm
>creating a souped-up tool-tip). 
>
>This works fine in standard view, but once the SVG document has been zoomed,
>the co-ordinates returned are no longer relative to the original
>document,(as, of course, I would expect :). I'd be grateful if someone could
>point me towards the correct JS syntax so the coordinates I return are in
>relation to my zoomed/panned document.
>
>Thanks a lot in advance for any help,
>
>Regards,
>Dylan 
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
>For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
>  
>


-- 
----------------------------------------------
Andreas Neumann
Institute of Cartography
ETH Zurich
Wolfgang-Paulistrasse 15
CH-8093  Zurich, Switzerland

Phone: ++41-44-633 3031, Fax: ++41-44-633 1153
e-mail: neumann@karto.baug.ethz.ch
www: http://www.carto.net/neumann/
SVG.Open: http://www.svgopen.org/
Carto.net: http://www.carto.net/


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