Tech Tip: Responding to a User Click on an SVG Image
PRODUCT: 4D | VERSION: 11.3 | PLATFORM: Mac & Win
Published On: March 25, 2009
When using the 4D SVG component to create an SVG image that is meant to respond to a user click, you will need to assign a unique ID to the object's XML element within the Root Parent Element. This lets you later find the element in the XML tree by its ID. You assign that ID using:
SVG_SET_ID ($Element_Ref_T;$ElementID_T) |
Once a user clicks on the image there is no SVG component command to determine which element was clicked on. Instead you must use the 4D SVG command SVG Find element ID by coordinates as shown here:
$RefID_T:=SVG Find element ID by coordinates(MyPictVar;MouseX;MouseY) |
The value returned in $RefID_T will be the value assigned to $Element_Ref_T in $ElementID_T
To now get the element reference value, use the SVG component command SVG_Find_ID. With this command, use the Root Parent reference value and the ID returned by SVG Find element ID by coordinates as shown here:
$Element_Ref_T:=SVG_Find_ID (RootElement_Ref_A16;$RefID_T) |
You are now set to respond to the user's click on the correct element within the image.
Commented by Atanas Atanassov on March 27, 2009 at 4:40 PM
"DOM Find XML element by ID" command can be used in the same way as "SVG_Find_ID"