I am using SVG getIntersectionList() to get the list of objects at a point clicked with a mouse.
svg.on("click", function () {
var loc = d3.mouse(this);
var rpos = svg[0][0].createSVGRect();
rpos.x = loc[0];
rpos.y = loc[1];
rpos.width = rpos.height = 1;
var elements = svg[0][0].getIntersectionList(rpos, null);
// do something with elements
});
This works well if svg has no viewBox. But I need viewBox to handle window resize automatically.
With viewBox the intersectionList is wrong quite often. For example I sometimes click inside a circle
but the circle is not in the intersected list or I click outside the circle and the circle is selected
anyway.
I am assuming that I shouldn't use the mouse coordinates loc[0] and loc[1] directly while
building rectangle rpos. Probably I need to transform those coordinates to a local (or global?) coordinate system, but I have no idea how to get the transformation matrix and how to apply it.
Any help will be appreciated.
Thanks,
Artan