Solved! Go to Solution.
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:esri="http://www.esri.com/2008/ags"
xmlns:mx="library://ns.adobe.com/flex/mx"
pageTitle="Directions component sample">
<fx:Script>
<![CDATA[
import com.esri.ags.SpatialReference;
import com.esri.ags.components.supportClasses.DirectionsStop;
import mx.events.FlexEvent;
[Bindable]
private var stop0:int=0;
[Bindable]
private var stop0Address:String="401 B Street, San Diego, California, 92101";
protected function dir_creationCompleteHandler(event:FlexEvent):void
{
var stop:DirectionsStop = dir.stopProvider[stop0];
stop.editable = false;
stop.searchTerm = stop0Address;
var i:int;
var value:Object;
var value2:Object;
var stopCount:int=1;
for (i=0; i<theAddress.length; i++)
{
value=theAddress.getItemAt(i);
if(value.count==1)
{
var stop1:DirectionsStop = dir.stopProvider[1];
//set editable
stop1.editable = true;
stop1.searchTerm = value.addr;
trace("Hello"+ value.addr);
}
if(value.count>1)
{
stopCount+=stopCount+1;
//trace(value.addr);
var st:DirectionsStop = new DirectionsStop();
st.stopId=stopCount;
st.searchTerm = value.addr;
dir.stopProvider.addItem(st);
}
}
}
]]>
</fx:Script>
<fx:Declarations>
<mx:ArrayCollection id="theAddress">
<fx:Object addr="1702 India St, San Diego, CA 92101" count="1" />
<fx:Object addr="1123 Island Ave, San Diego, California, 92102" count="2" />
<fx:Object addr="924 S 16th St, San Diego, California, 92102" count="3" />
<fx:Object addr="2025 L St, San Diego, California, 92102" count="4" />
</mx:ArrayCollection>
</fx:Declarations>
<s:layout>
<s:HorizontalLayout paddingLeft="2"/>
</s:layout>
<esri:Directions width="320" height="100%"
map="{map}"
id="dir"
creationComplete="dir_creationCompleteHandler(event)"
url="http://sampleserver6.arcgisonline.com/arcgis/rest/services/NetworkAnalysis/SanDiego/NAServer/Route"/>
<esri:Map id="map">
<esri:extent>
<esri:WebMercatorExtent xmin="-13055785" ymin="3848161" xmax="-13025898" ymax="3866239"
spatialReference="{new SpatialReference(102100)}"/>
</esri:extent>
<esri:ArcGISTiledMapServiceLayer/>
</esri:Map>
</s:Application>
private function launchLandmarkDirections():void{
var landmarkStopProvider = new DirectionsStop();
landmarkStopProvider.location = landmarkMapPoint;
var stop2:DirectionsStop = new DirectionsStop();
trace(landmarkStopProvider.location);
landmarkDirectionComponent = new Directions;
landmarkDirectionComponent.url = "http://tela.roktech.net/arcgis/rest/services/DigitalEgypt/EGIPA_NetworkStreet/NAServer/Route";
landmarkDirectionComponent.addEventListener(DirectionsEvent.DIRECTIONS_COMPLETE, landmarkDirectionsCompleteHandler);
landmarkDirectionComponent.map = myMap;
landmarkDirectionComponent.stopProvider[0] = landmarkStopProvider;
}var stop:DirectionsStop = dir.stopProvider[0]; stop.editable = false; stop.searchTerm = '31.41189186200006,30.01863021300005';
Wow, Great App Raffi.
Its good to know that you can just send the XY to the stop provider. One of my requirement in the future will be to capture the mobile device location and use that as a stop -- stop[0]. This is going to come handy for me also in the near future.
Raffi,
Don't create a new directionsStop just set the search term on the first one in the directions component.var stop:DirectionsStop = dir.stopProvider[0]; stop.editable = false; stop.searchTerm = '31.41189186200006,30.01863021300005';
private function launchLandmarkDirections():void
{
landmarkDirectionComponent = new Directions;
landmarkDirectionComponent.url = "http://tela.roktech.net/arcgis/rest/services/DigitalEgypt/EGIPA_NetworkStreet/NAServer/Route";
landmarkDirectionComponent.addEventListener(DirectionsEvent.DIRECTIONS_COMPLETE, landmarkDirectionsCompleteHandler);
landmarkDirectionComponent.map = myMap;
var stop:DirectionsStop = landmarkDirectionComponent.stopProvider[0];
stop.editable = false;
stop.searchTerm = '31.41189186200006,30.01863021300005';
}Raffi,
Is there a reason you are creating the Direction component programatically and not in the MXML markup? It is likely that the Directions component is not finished creating before you attempt to access it's stopprovider (timing issue).
private function launchLandmarkDirections():void
{
landmarkDirectionComponent = new Directions;
landmarkDirectionComponent.url = "http://tela.roktech.net/arcgis/rest/services/DigitalEgypt/EGIPA_NetworkStreet/NAServer/Route";
landmarkDirectionComponent.addEventListener(DirectionsEvent.DIRECTIONS_COMPLETE, landmarkDirectionsCompleteHandler);
landmarkDirectionComponent.map = myMap;
landmarkDirectionComponent.addEventListener(FlexEvent.CREATION_COMPLETE, setUpDirections)
}
private function setUpDirections(event:FlexEvent):void
{
var stop:DirectionsStop = landmarkDirectionComponent.stopProvider[0];
var driveString:String = new String;
driveString = landmarkMapPoint.x + "," + landmarkMapPoint.y;
trace(driveString);
stop.searchTerm = driveString;
}