Get closest element in SVG using JavaScript

I am using Verovio to render sheet music in SVG and render them in the browser.

For my project I need to get the closest SVG element of a certain type to the mouse pointer. Calculating distances for all elements (e.g. using d3.js) is not a viable solution due to performance issues.

Is there an elegant way to do this?

+3


source to share


1 answer


You can use Quadtree Nearest Neighbor Algorithm.

http://bl.ocks.org/patricksurry/6478178



The performance is not bad.

+2


source







All Articles