I have an image map with multiple areas defined, all as polygons
I would like to calculate the distance from a point on the image (typically given by the user clicking on the image) to the closes point on the outer edge of a given area.
For my case one can make the assumption that none of the edges of the polygon intersect, thus making the task a bit easyer
Detecting if the point is inside, on or outside the area/polygon is also interesting, eg by having a negative distance if the point is inside the polygon, 0 if its on the edge.
But this is not that important for me, as it easy to detect this given that the point is given by the user clicking on the image.
The generic solution for this problem is given here - but i wonder if anyone already have a implementation in javascript for solving this with image maps and areas
I would like to do something like:
var distance = calculateDistancePointToArea( xCoord, yCoord, areaId );
And it would be an extra bonus if this worked for all the shapes possible for an area: rect, circle and poly