Get coordinates of polyline

257
2
Jump to solution
04-15-2024 08:40 AM
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 Solution

Accepted Solutions
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

View solution in original post

2 Replies
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
Vakhtang_Zubiashvili
Occasional Contributor III

Hi @JamesIng, thank you. your answer is what i was looking for

0 Kudos