netdjw
netdjw

Reputation: 5997

Raphael.js how to find click position on a path?

Is there any way to access a click-on-path coordinates? And one other: is possible to find out whitch is the previous closest corner on the path?

I was read this, but not so helpful: Raphaeljs: accessing the relative postion of a click on a closed path

Thanks for yout time!

Upvotes: 1

Views: 3176

Answers (1)

Ron van der Heijden
Ron van der Heijden

Reputation: 15070

Are you looking for something like this:

var paper = Raphael(10, 10, 400, 400);

var path = paper.path("M0 0L10 100L50 100L100 70").attr({"stroke": "#000", "stroke-width": "3"});
path.click(function(event) {
    console.log(this);
    console.log(event.x, event.y);
});

http://jsfiddle.net/sLmHd/2/

Edit

I only made a start for you. This is a way, not the only way.

I created an object with 2 arrays. x and y.

Every click I add the point. (You need to check on what index you want to push the point) Also you need to check what the closes corner is. This could be helpfull

I hope this will help you: http://jsfiddle.net/fvtPN/

Upvotes: 3

Related Questions