Do you have "listener" elements in the SVG file that overlap each other? or are they going to be clearly separated? If they are separated, you may do a MouseEvent listening routine on the SVG elements while you are drawing the sketch in the overlay, and thus, you have nearest element.

But, if the situation is that you have multiple 'listener' elements that overlap each other and the sketch may be in some cases a path circling the element in question, with perhaps a glyph in the middle to indicate zoom into this one, etc. Then the MouseEvent approach may not work, because the element in question is inside the area indicated by the path but during the actual drawing of the path, the mouse was never on top of the element in question, and thus the MouseEvent for that element was never triggered. If this is the case, then the i see two options:
a. ) Traverse your DOM manually, and perform a check of each element's center, with the centroid you have found out.


b.) Programatically generate a DOM MouseEvent with your centroid coordinates, to trigger the MouseEvent on the desired Element. I have done no research on how to do this second approach, but it makes a lot of sense to me, to tell the DOM to trigger a mouse event with specific coordinates, so the underlying routines select the receiver target and trigger the event.
Thomas: Can this be done?


Whatever the approach, you need to make sure the coordinates indicated in your centroid are in SVG coordinate space, as indicated in the Drag tutorial.

Regards,
Andres.


On Apr 30, 2005, at 3:34 PM, Archie Cobbs wrote:

Brian Johnson wrote:
I'm new to Batik and naive in Java, though experienced in older languages and graphics environments. I have a student who is working to combine various technologies into a Java application--including SVG files and sketch recognition. The basic strategy is to load an externally generated SVG file which has associated style ID's with <g> elements, display this graphpic, allow the user to sketch marks on top of the SVG, categorize the sketch gesture, identify what was "under" the sketch, and then produce a folllow-up action. We're now at the point where we need to identify the element. We know where (in terms of the overlayed Java Graphics world) the centroid of the sketch was and want to query the SVG for the ID of the nearest element "under" this sketch.

You can use the org.w3c.dom.events.EventTarget and org.w3c.dom.events.MouseEvent classes to detect mouse over, mouse click, etc. events by registering the appropriate listener(s). Pretty much any SVGElement in the DOM can be cast to an EventTarget.

-Archie

_______________________________________________________________________ ___
Archie Cobbs * CTO, Awarix * http://www.awarix.com


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to