You can probably do it by overlaying an SVG over your <img>
. D3 would render into this svg panel. You can create a polygon in the SVG based on the user clicks.
If you use the d3.event
mouse locations (mouseX
and mouseY
, I think), you can get click positions relative to the SVG element, and then use those as vertex locations on a polygon. Checking for click proximity to the original point will allow you to decide when to close the polygon.