Get coordinates of polyline

190
1
2 weeks ago
Vakhtang_Zubiashvili
Occasional Contributor III

Hi all,

I want to get screenPoints of polyline (maybe array of points, no problem). For point features i use code:

 

projection.load().then(function () {
let screenPoint = view.toScreen(feature.geometry);
console.log(screenPoint.x, screenPoint.y);
}
 
and it works fine, but how can achieve this for polyline?
 
Thanks in advance 
0 Kudos
1 Reply
JamesIng
New Contributor III

A polyLine is just a series of points inside a 'paths' array.

You can just use a javascript .forEach() to go through each point in the array create a new Point from the coordinates and to output the screenPoint.
Note polyLines can have multiple line segments so you'll want to check each line segment as well.

//pseduoCode example
const polyLine = feature.geometry // Your polyLine feature.
 polyLine.paths.forEach((path) => { //for each line segment inside your polyLine
path.forEach((coordinates) => { //for each coordinate in your line segment
const newPoint = new Point(...) //create a new Point using the path coordinates
let screenPoint = view.toScreen(newPoint );
console.log(screenPoint.x, screenPoint.y);
})
})

James from www.landkind.com
0 Kudos