Seems to be a good Idea, this getIntersectionList with a 1pixel rect, isn't it?
I am looking at the Dom specification, but it seems that I have not the right
technic to sniff around W3C documentation (tell me how to search?).
Anyway, I have tried 2 codes:
ONE
I try to get a viewportElement (assuming that it is the displayed rect to pass
as an argument to the function.:
SVGElement viewportElement =
canvas.getSVGDocument().getRootElement().getViewportElement();
Unfortunately, it returns null. Do you know why ? what's the difference with
the getViewport()?
TWO
I pass the root element to the function. It fails with nullpointerexception.
Any idea?
While waiting, I'll try the Heidrun method.
De : [email protected] [mailto:[email protected]]
Envoyé : lundi 26 octobre 2009 13:44
À : [email protected]
Cc : [email protected]
Objet : Re: locate an SVG element using x, y position
Hi Heidrun, HODAC,
> On Mon, 26 Oct 2009 10:44:49 +0100, HODAC, Olivier wrote:
>
> >I'd like to add a mouse listener on my JSVGCanvas to select an element
> >of my rendered SVG.
> >How can I find the right node using x,y mouse postion?
I suggest following Heidrun's suggestion of adding a mouse
event listener (click, mouseOver, mouseExit, etc), although I would
suggest doing it a different way.
However another approach would be to use the 'getIntersectionList'
method available on the svg:svg element.
I suggest reading the DOM2 Events specification as it offers
everything most people need in this area:
http://www.w3.org/TR/DOM-Level-2-Events/
<http://www.w3.org/TR/DOM-Level-2-Events/>
Heidrun Beer <[email protected]> wrote on 10/26/2009 06:59:11 AM:
> You need to add an event listener to each element as
> you create it. If you load your drawing from a file,
> you need to loop through the whole element tree and
> add it to each element. It's not so much code, as
> you do it all in a loop.
Actually if you want to be notified of all mouse events
I would suggest registering one listener on the root
SVG element (probably during the capture phase). You can
then use the target field to know what element the
event is targeted for.
> I have the special situation that I skip the first element,
> which is a background rectangle that I don't want to be
> moveable. It is always the first in the document.
This can be handled with the one event listener by simply
skipping events that have the background rectangle as the
event target.
The one listener approach will also save considerably on
memory.
This mail has originated outside your organization, either from an external
partner or the Global Internet.
Keep this in mind if you answer this message.
The information in this e-mail is confidential. The contents may not be
disclosed or used by anyone other than the addressee. Access to this e-mail by
anyone else is unauthorised.
If you are not the intended recipient, please notify Airbus immediately and
delete this e-mail.
Airbus cannot accept any responsibility for the accuracy or completeness of
this e-mail as it has been sent over public networks. If you have any concerns
over the content of this message or its Accuracy or Integrity, please contact
Airbus immediately.
All outgoing e-mails from Airbus are checked using regularly updated virus
scanning software but you should take whatever measures you deem to be
appropriate to ensure that this message and any attachments are virus free.