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);
}
Solved! Go to Solution.
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);
})
})
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);
})
})
Hi @JamesIng, thank you. your answer is what i was looking for