KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: SVG Find element ID by coordinates gets the top-most object
PRODUCT: 4D | VERSION: 11.3 | PLATFORM: Mac & Win
Published On: March 25, 2009

The 4D SVG Component method, SVG Find element ID by coordinates, returns the element ID of the SVG element at the position specified in the parameters passed to the command. Tech Tip 75223, Responding to a User Click on an SVG Image, has more information on using this command.

It is important to note that the command returns the ID of the top-most SVG object at the given coordinates. Use the following SVG image as an example:



In this image, there are two SVG objects: A gray rectangle and a text object (103). You could change the color of the rectangle in code when it is clicked using the ID returned by SVG Find element ID by coordinates. But if the user clicks on the text object then that would be the element's color that is changed. Be sure to manage your naming conventions so as to take this into account.

In this specific application you could give the rectangle an ID such as "SVG_object1_rect" and the text an ID such as "SVG_object1_text". Then parse the clicked object ID for "SVG_object1_@" and change the color of the "SVG_object1_rect" for a click on either object. This is just one way to handle clicks in SVG areas, but be sure to account for the fact that the top-most object will be the ID returned by SVG Find element ID by coordinates.

Commented by Atanas Atanassov on March 27, 2009 at 4:50 PM
Also, this can be done by assigning a Boolean flag to the rectangle object. Set the flag value "True" when the user clicks on the rectangle object and change colors only if the flag's value is "True".