Select to view content in your preferred language

Directions Component Stops Provider

2793
21
Jump to solution
01-14-2014 01:38 AM
raffia
by
Deactivated User
Hello;

I am trying to provide a "Directions from here" and ..to here functionality, so I want to use the stopProvider property in the Directions Component. I tried passing an XY from the map point, but to no success. Any sample one line of code showing how to pass the stopProver please?

Raffi
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus
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).

View solution in original post

0 Kudos
21 Replies
RobertScheitlin__GISP
MVP Emeritus
Raffi,

   I don't have a sample for this but the documentation says that the stopProvider is an object (ArrayCollection) of DirectionsStop objects. So just create some DirectionStop objects and add them to an array collection and pass that to the Directions component.
0 Kudos
raffia
by
Deactivated User
Thank you Robert for the reply. I will give that a shot and update this post.
0 Kudos
KomanDiabate
Deactivated User
Hi Robert and Raffi,
That will be so so cool. This is exactly what I am trying to do right now -- what a coincidence. I will definitely post an update if I come accross anything exciting or interesting.
Thanks.
0 Kudos
raffia
by
Deactivated User
Hello Koman;

Thanks for the post. Am planning to dive into this myself in two or three days, and will update here for sure as well.

Regards;
Raffi
0 Kudos
KomanDiabate
Deactivated User
Hi Raffi,
I started researching a bit this weekend, I came across these two ESRI docs, you may have seen these also. Maybe interesting...
They are passing xy values somehow manually to a graphic stops / featureset. I am assuming you could do the following:
If you have your xy in an arraCollection, you could loop the arrayCollection and add them directly to the graphic named stops

var stops:Graphic = new Graphic(new MapPoint(arraCollection.X, arrayCoolection.Y);
var stopsFS:FeatureSet = new FeatureSet([stops]);

// See first link

Routing task:
https://developers.arcgis.com/en/flex/guide/routing-tasks.htm

https://developers.arcgis.com/en/flex/api-reference/com/esri/ags/tasks/supportClasses/RouteParameter...

Thanks
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Guys,

   Here is a sample seting the stops searchTerm to be geocoded.

<?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"
               pageTitle="Directions component sample">
    
    <fx:Script>
        <![CDATA[
            import com.esri.ags.SpatialReference;
            import com.esri.ags.components.supportClasses.DirectionsStop;
            
            import mx.events.FlexEvent;
            
            protected function dir_creationCompleteHandler(event:FlexEvent):void
            {
                var stop:DirectionsStop = dir.stopProvider[0];
                stop.editable = false;
                stop.searchTerm = '1123 Island Ave, San Diego, California, 92102';
                
                var stop2:DirectionsStop = dir.stopProvider[1];
                stop2.editable = false;
                stop2.searchTerm = '924 S 16th St, San Diego, California, 92102';
                
                var stop3:DirectionsStop = new DirectionsStop();
                stop3.searchTerm = '2025 L St, San Diego, California, 92102'
                dir.stopProvider.addItem(stop3);
            }
            
        ]]>
    </fx:Script>
    
    <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>
0 Kudos
KomanDiabate
Deactivated User
Hi Robert,
This is just brilliant. Thanks a bunch.
In my particular case, I have a list of addresses that I have to pass to the stopProvider.
I think I will have to loop the arrayCollection list and while looping add them to thestopProvider.
But I see you have explicitly name the stops(stop1, stop2 etc.) not sure if they need to be named as such in my implementation ?
I am not in front of a computer right now, but do think the logic below will work?
While looping the arrayCollection:

PseudoCde
For(var i:int=0; i<arrayCollection.length; i++)
{
      var stop:DirectionStop=new DirectionStop();
      stop.searchterm=arrayCollection.Address,
      Dir.stopProvider.aadItem(stop);
}

Not sure if I need to explicitly declare the stops such as stop1, stop2 etc:
Var stop:DirectionStop=dir.stopProvider[1];
Hope you can enlighten me on that portion.
Just love the way you put your code together, brilliant.

Thanks in bunch.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Koman,

   The directions component always begins with two stops in the dataprovider so that is why I create explicit vars for those stops so that I can just manipulate them. One you have those two set then you can just add more the way I did for my third stop.
0 Kudos
KomanDiabate
Deactivated User
Excellent,
Now I understand why you declare the first two stops and just instantiate the third one. I will experiment with this on Tuesday at the office and see  if I can make it work using a collection of address. I appreciate your help on this.
Thanks a bunch.
0 Kudos