Select to view content in your preferred language

RouteTask Help

836
1
08-16-2010 08:47 AM
CaseyBentz
Frequent Contributor
Hello All,

I am attempting to solve a route between two points and display a tool tip indicating the estimated time a GPS transmitting vehicle has left to reach its destination.  This was working just fine, until I made some changes.  Now, I get what appears to be the start time instead of the Total_Time for the route.  I will attempt to condese my code so you can see what I am doing. 

In my controller I create 4 global variables for the route.
private var route:RouteTask = new RouteTask();
private var routeParams:RouteParameters = new RouteParameters();
private var stops:Array = new Array;
private var fs:FeatureSet;

When the user double clicks a vehicle I push the currentTarget to the stops array
stops = new Array;
stops.push(e.currentTarget as Graphic);

I then send an httpService request to a web service that queries our orders database to get a collection of orders...
I loop through the results to find if an order has an enroute status, if it does, I add that order as a graphic to the stops array
        
route.concurrency = "last";
route.requestTimeout = 30;
route.addEventListener(RouteEvent.SOLVE_COMPLETE, onRouteResult);
route.addEventListener(FaultEvent.FAULT, onRouteFault);
route.url= "http://tasks.arcgisonline.com/ArcGIS/rest/services/NetworkAnalysis/ESRI_Route_NA/NAServer/Route";
stops.push(orderGra);
Model.instance.activeOrder = orderGra;
fs = new FeatureSet(stops);
routeParams.stops = fs;
routeParams.outSpatialReference = Model.instance.map.spatialReference;
if (stops.length > 1)
    route.solve(routeParams)
}

When the RouteTask is complete I run this function and the routeResult.route.attributes.Total_Time is equal to what looks to be the start time rather than Total_Time.
private function onRouteResult(e:RouteEvent):void{
var routeResult:RouteResult = e.routeSolveResult.routeResults[0];
Model.instance.routeLayer.clear();
var gra:Graphic = routeResult.route;
if( routeResult.route.attributes.Total_Time){
   gra.toolTip = "Expected arrival in " + Math.round(Number(routeResult.route.attributes.Total_Time)) + " minutes";
   gra.symbol = new SimpleLineSymbol("solid", 0x0000FF, .5, 5);
   Model.instance.routeLayer.add(gra);
   vehicleGroupAC.addItem(gra);
   var extent:Extent = GraphicUtil.getGraphicsExtent(vehicleGroupAC.toArray());
   if(extent){
      Model.instance.map.extent = extent;
      if(!Model.instance.map.extent.containsExtent(extent)){
         Model.instance.map.level--;
      }
   }  
}
}


Casey
Tags (2)
0 Kudos
1 Reply
CaseyBentz
Frequent Contributor
I figured it out.  When I was creating the attributes for my vehicles, I had a Time field.  This time as being added to the route time.  So if I subtracted the Total_Time attribute from the Time field of the vehicle, I would get the actual route time.  I changed my field name to StatusTime and it now works as expected. 

Casey
0 Kudos