Select to view content in your preferred language

How to create a closed polyline?

09-15-2015 10:45 PM
by Anonymous User
Not applicable

Hi all

Say I want to create a rectangle polyline that is closed. I start my line, create lines to each new point, but then how to close? the code I thought would be something like:

newLine.startPath( x, y);

  newLine.lineTo(x1, y1) //next coordinate

  newLine.lineTo(x2, y2) //etc

  newLine.lineTo(x3, y3)

  newLine.closePathWithLine(); // OR the next line...


        console.log("is the new waterway closed? ", newLine.isClosedPath(0))

Both the close path lines of code cause the isClosedPath property to change to true, but the actual polyline is only three sides, the fourth closing line is (as per the documentation below) not a actual line.

A closed path has a virtual segment that connects the last and the first points of the path. The first point is not duplicated to close the path.

I tried adding a line of code at the end to draw a line back to the starting point:

newLine.lineTo(x, y)

If I include this line WITHOUT any closePath lines of code, it creates a four sided polyline but it is not "closed". If I include this last line of code plus also the code to closePath - it seems to only create three sides again.

How to create a polyline that DOES have all four sides including one back to the start point, but is closed?



0 Kudos
0 Replies