Select to view content in your preferred language

How to get length of each segment of polyline? (using SketchViewModel)

153
1
a month ago
Sparkles
New Contributor II

When I draw a polyline, I can see the length of each segment displayed with SketchViewModel. (as shown in screenshot)
How can I access these lengths from the event/argument in the SketchWidget's handleChange calllback?
The event is the geometry/polyline, but doesn't show the lengths/distances anhywhere in the data returned. Is there a way to add that data to the event returned in the callback?

Thanks so much for the help!

0 Kudos
1 Reply
JoelBennett
MVP Regular Contributor

The lengths of each segment aren't included in the event object, but if you have a reference to the polyline object, you can calculate them without much trouble.  You would just need to (1) step through the polyline's points 2 at a time (perhaps using getPoint), (2) create a new Polyline object from those two points, and then (3) get the distance for the new 2-point polyline from geometryEngine.geodesicLength.