Below is a code snippet I am using to draw a simple square (though the shape will get much more complex further in the project as it is meant to visualize DWG files imported from a back-end).
I have however hit a wall in trying to get the SVG segment that is clicked.
What I am looking to do in the current setup is:
- User clicks on a segment of the SVG
- The segment closest to it (with some margin) is captured
- I can use that captured information in my code (preferably 4 number values, representing the x1, x2, y1 and y2)
The problem I am having is that I don’t know how to identify the segments, while I can see that they advance with an [x1, y1, x2, y2, x3, y3, x4, y4] pattern.
var draw = svg.SVG().addTo('body').size(300, 300);
var arr = new svg.Array([0, 0, 0, 100, 100, 100, 100, 0])
draw.polygon(arr).fill("0x000000");
An example of what I want to be able to do:
get the line along the point [50, 0] which should be in the first segment of the shape drawn in the snippet above. I need to correctly identify the segment the user has selected so I can work with that information. If I can somehow get the begin and end coordinate of the segment that was clicked that would probably lead me to a successful solution.