Hi, I'm trying to get the milepost on a road segment returned from Identity Task (or some other way) in JavaScript. The road segment has Beginning MP and Ending MP as attributes. is there a tool that can calculate (or return) where I clicked on the road? Do you I need to change how road layer is published (using routing)?
Solved! Go to Solution.
John,
something like this:
IdentifyTask.execute (paramters, function (idResults) { if (idResults.length > 0) { var polyl; for(var r=idResults.length-1; r >= 0; r--){ polyl = idResults.feature.geometry; for(var l=polyl.paths.length-1; l >= 0; l--){ var pathArray = []; for (j = 0; j < polyl.paths.length; j++){ mp = polyl.getPoint(l,j); //mp is a point object so you can use x and y properties on it. } } } } });
Although I am not a JavaScript expert, I guess you could use the nearestCoordinate(geometry, inputPoint) (see: esri/geometry/geometryEngine | API Reference | ArcGIS API for JavaScript or esri/geometry/geometryEngineAsync | API Reference | ArcGIS API for JavaScript ) to obtain the coordinate of the point on the line (nearest to where the user clicked) and then loop through the vertice pairs of the line and sum the length until you reach the point. (see: Polyline | API Reference | ArcGIS API for JavaScript )
Use the summed length divided by the total line length multiplied with the MP difference to get the MP of the point clicked.
In arcpy (python), ArcObjects and other Runtime SDK's the geometry library seems to be a lot larger and these type of analysis are standard. So, I'm not sure if this is the way you should do this.
Maybe Kelly Hutchins can advise on this?
Thank you Xander, do you know what property of the line I would loop through to get the vertice pairs?
John,
Once you have the lines geometry (i.e a Polyline Object) you can use the getPoint method in a array.
Thanks Robert Scheitlin, GISP for jumping in.
Thank you Robert,
I have feature set of results from Identify task. Do I define a Polyline then set the geometry equal to the geometry of the found feature?
IdentifyTask.execute (paramters, function (idResults) {
if (idResults.length > 0) {function (result) {
var foundroadgeometry = result.feature.geometry;
var feature = result.feature;
var polyline = new esri.geometry.Polyline(map.spatialReference);
polyline.geometry = foundroadgeometry;
}
});
Like that?
John,
something like this:
IdentifyTask.execute (paramters, function (idResults) { if (idResults.length > 0) { var polyl; for(var r=idResults.length-1; r >= 0; r--){ polyl = idResults.feature.geometry; for(var l=polyl.paths.length-1; l >= 0; l--){ var pathArray = []; for (j = 0; j < polyl.paths.length; j++){ mp = polyl.getPoint(l,j); //mp is a point object so you can use x and y properties on it. } } } } });
I guess you have to use the path property (Polyline | API Reference | ArcGIS API for JavaScript ) which is of type Number[][][] (but I'm really getting out of my comfort zone right now...)