Select to view content in your preferred language

How to find Begin and End points of a polyline using Arcgis  Javascript

5889
4
09-26-2013 05:07 AM
viteboardviteboard
Emerging Contributor
Hello All,

Can anyone say how to get the starting and ending points of a polyline when we draw using Arcgis Javascript api.
Using WebAdf we are having the facility of MapLineEventArgs.BeginMapPoint and  MapLineEventArgs.EndMapPoint.
I want to perform few validation basing on this start and end coordinates of polyline

Thank You
Aravind
0 Kudos
4 Replies
JasonZou
Frequent Contributor
You can use polyline.getPoint(pathIndex,pointIndex) function to get the point you need. For instance,

First point of the first path:
polyline.getPoint(0,0)


Last point of the first path: 
var lastIdx = polyline.paths[0].length - 1;
var lastPnt = polyline.getPoint(0, lastIdx)
0 Kudos
viteboardviteboard
Emerging Contributor
Thank you..It solved my problem.
0 Kudos
JasonZou
Frequent Contributor
Glad to help. Please consider mark your thread as "Answered" so other people may find it helpful. Thanks.
0 Kudos
JohnGrayson
Esri Regular Contributor
Careful, the previous solution assumes the geometry is a single-part polyline, which seems to be ok for this use case, but might not work in all situations, like when the geometry is retrieved from an external source like a Map or Feature Service.

var lastPartIdx =  polyline.paths.length-1;
var lastPntIdx = polyline.paths[lastPartIdx].length - 1;
var lastPnt = polyline.getPoint(lastPartIdx , lastPntIdx);