Total Length of Polyline

917
1
11-11-2019 02:47 AM
kawishabbas
New Contributor III

Hi 

I am confused to calculate total length of line feature with arcgis API for java script.

any one can help me...???

I found following code but it's not working.

let geometryService = new GeometryService({
                    url:url
                })
                geometryService.simplify([line]).then(function (line) {
                    var areasAndLengthParams = new LengthsParameters({
                        lengthUnit: "kilometers",
                        polylines: line
                    });
                    console.log(areasAndLengthParams)
                   /*  geometryService.Length(areasAndLengthParams).then(function (results) {
                        console.log("area: ", results.areas[0]);
                        console.log("length: ", results.lengths[0]);
                    }); */
                });
0 Kudos
1 Reply
Noah-Sager
Esri Regular Contributor

You can use the geometryEngine for this:

var length = geometryEngine.geodesicLength(polyline, "meters");

sample

https://codepen.io/noash/pen/BaaPqNv?editors=1000#0 

Or, you could also use the measurement widget to make this measurement in the app itself:

Measurement widget | ArcGIS API for JavaScript 4.13 

0 Kudos