Select to view content in your preferred language

Find Route Location

572
0
07-29-2010 09:32 AM
PatrickAdesso
Emerging Contributor
Hello,

I have an interesting problem that I can't quite overcome.  I have a 300+ mile polyline that is also a route published as a map service in ArcGIS 10.

I need to replicate the functionality that is in ArcMap where a user can provide a route location and the application will zoom to that spot as described here.

I tried a workaround of querying the line to get it in my graphics layer then looping through the paths array, calculating distances and returning a point when the distance exceeded the input but the result wasn't accurate enough.

private function getRouteLocation(location:Number, paths:Array):MapPoint    
   {     
    tempDist = 0;     
    var locationPoint:MapPoint = new MapPoint(); 
    
    for(var i:int = 0; i < paths.length; i++)      
    {      
     for(var j:int = 0; j < paths.length; j++)       
     {         
      if(i < paths.length && j <= paths.length - 2)  // normal        
      {        
       tempDist =          
        tempDist + Math.sqrt( Math.pow( (paths[j + 1].x - paths.x), 2)           
         + Math.pow( (paths[j + 1].y - paths.y), 2) );           
      }        
      else if(i<=paths.length - 2 && j == paths.length) //end of an inner array        
      {        
       tempDist =          
        tempDist + Math.sqrt( Math.pow( (paths[i + 1][0].x - paths.x), 2)           
         + Math.pow( (paths[i + 1][0].y - paths.y), 2) );           
      }
      
      locationPoint = paths;
      
      if(tempDist >= location)        
      {            
       return locationPoint;        
      }       
     }           
    }          
    
    return locationPoint;     
   }


Any help is appreciated!

Patrick
Tags (2)
0 Kudos
0 Replies