Does the direction widget support way points when initialized in JS API 3.x?

643
5
03-12-2018 07:15 PM
LeoDeng
Occasional Contributor II

Hi all,

  I'm using the direction widget with esri javascript API  version 3.x.

  I want to add some waypoint and get the directions.

  How to implement this by the existing api?

  I've tried to call the function of addStops and  addStop, it will add all of the stops into the directions widget and displayed as a stop.

Thanks,

Leo

0 Kudos
5 Replies
RichardReinicke
Occasional Contributor II

Hi Leo,

can you please describe a little bit more detailled what you need? Your description of Direction-Widgets behaviour is quiet as expected. In my understanding the stops are the waypoints.

Following the sample at Directions | ArcGIS API for JavaScript 3.23 you can add stops to your route and as they are now part of your route, directions become recalculated to include them.

With the addStops(stop, index?) Method you have a second parameter that allows you to define where to insert the waypoint into the existing route.

If you already know all of your stops then you can also just pass them to the constructor as follows:

var directions = new Directions({

    stops: [ new Point(x1, y1, someSpatialReference), new Point(x2, y2, someSpatialReference)]

}, 'myDirectionNodeId');


0 Kudos
LeoDeng
Occasional Contributor II

Hi Richard,

    In order to solve the problem of Map Matching with esri products, I'm trying to use the direction widget.

    There is a dataset includes 500 GPS points. First and last points are stops and others are waypoints. My target is to get the route through all of the gps points and draw the result on the map. And ONLY the stops should be displayed in the directions.

    In the direction wedgit, the stops added in the direction widget will be shown as stops by default. But waypoints do not appear in driving directions.

    Do you have any suggestions?

Thanks,

Leo

0 Kudos
RichardReinicke
Occasional Contributor II

Hi Leo,

if you just want wo hide the intermediate waypoimt marker you can first replace their symbol with a PictureMarkerSymbol with 0 size:

        var symbol =  new PictureMarkerSymbol({
          "url":"anyPicture.png",
          "height":0,
          "width":0,
          "type":"esriPMS"
        });
        var directions = new Directions({
          map: map,
          stopSymbol: symbol
        },"dir");

But there are remaining labels. Esri API seems to add them as SVG elements. I wasn`t able to remove them yet. Maybe svg.js or d3.js are helpful here.

Is this what you are looking for?

0 Kudos
LeoDeng
Occasional Contributor II

Hi Richard,

    Thanks for your advice. Unfortunately, besides the symbols shown on the map, there also have direction details on the widget. This couldn't removed by your solution.

    At the same time, the direction turns are calculated by the stops, which is not as expect either.

Leo

0 Kudos
RichardReinicke
Occasional Contributor II

Hi Leo,

what you describe can not be fulfilled with that widget while its designed exactly for that usecase. Also further hooking into existing Esri widgets is by my experience not a good idea.

 

For your intentions I only see the solution to get your data directly from the REST-service (RouteTask()) and build a nice little widget or module around it. We do this for most of our special needs that can`t be reached with out of the box esri widgets.

Richard

0 Kudos