Getting the coordinates of the closest facility

2224
5
04-27-2012 05:34 AM
ab1
by
Occasional Contributor II
Hello,
I have published a Network Analyst Service that calculates the closest facility (of Point type) to the click performed on the map. I would like to get the coordinates of that Point.
I tried to do that by exploring the property "facilities" of the solveResult object, but it seems that "facilities" contains all the elements of the layer where the closest facility is calculated.
Do you have any hint?

closestFacilityTask.solve(params,function(solveResult){
var vente = new esri.Graphic(solveResult.facilities[0]);
venteGraphicsLayer.add(vente);
});


Regards.
0 Kudos
5 Replies
MarkLewin2
New Contributor
Hi,

Are you saying that you want to retrieve the closest facility from several returned points?

I think you could do this by setting returnDirections to true and then examining the esri.tasks.DirectionFeatureSet object that will be returned in ClosestFacilitySolveResult.directions.

You can inspect this object for each route to find drive time or route length and map the quickest/shortest result to its corresponding entry in the ClosestFacilitySolveResult.facilities array.

HTH?

Mark Lewin
0 Kudos
ab1
by
Occasional Contributor II
Thank you Mark for your answer.
In fact, I want to retrieve the closest facility from a layer of points. That layer is not returned from any processing. It just exists as a "facilities class" in the NA service that is published in my map.
The closest facility analysis is launched when a click on the map is performed. That click generates a point that is stored in the "incidents class".
Finally, the closest facility analysis looks for the closest feature, in the "features class", to the the point contained in the "incidents class" and returns the routes from the incident to the facility found.
What I want is to retrieve the point in the "facilities class" found by the closest facility analysis => the closest facility to the click performed on the map.

The object esri.tasks.DirectionFeatureSet doesn't contain the closest facility found by the analysis, nor does the object esri.tasks.ClosestFacilitySolveResult.
0 Kudos
ab1
by
Occasional Contributor II
Has anyone any idea?
0 Kudos
JimColl
New Contributor II

My apologies for the necro-bump, but I'm currently attempting to do this same thing.  Is there any way to return either the lat/long or the address of the point so that I can feed it back into the directions widget?

0 Kudos
JimColl
New Contributor II

Got it, for future google reference, I reached into the output and extracted it by the id like so:

closestFacilityTask.solve(paramsCF, function(solveResult){

            array.forEach(solveResult.routes, function(route, index){

              var attr = array.map(solveResult.directions[index].features, function(feature){

                return feature.attributes.text;

              });

              route.setAttributes(attr);

              destination = route.attributes[route.attributes.length - 1];

              destinationArray = destination.split(" ");

              destinationId = destinationArray[3];

              stopId = +destinationId;

              console.log("stopId: ", stopId);

              stopPointX = paramsCF.facilities.features[stopId-1].geometry.x;

              stopPointY = paramsCF.facilities.features[stopId-1].geometry.y;

              stopPoint = new Point(stopPointX, stopPointY);

              console.log("stopPoint inside function: ", stopPoint);

               // start the directions widget

              startDirections();

            });

          });

0 Kudos