Question

How could I access and enumerate through control points and their coordinates in svg/snapsvg path?

Something like:

 var myPath = s.path("M 18,0 4.5,9 13.5,9 9,18 0,36 18,36 36,0 z");

 myPath.attr("d").forEach(function(point)
 {
 console.log("x:"+point.x," y:"+point.y)
 }
Was it helpful?

Solution

You can get the segments of the path (the positions/coordinates you entered when creating the path) as such:

var numberOfItems = myPath.node.pathSegList.numberOfItems; // handy for loops
var firstCoordinate = myPath.node.pathSegList.getItem(0);
console.log firstCoordinate.x;
console.log firstCoordinate.y;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top