<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Directions widget - load route with waypoints in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/directions-widget-load-route-with-waypoints/m-p/381512#M35421</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So I've got a solution that allows me to load a route that has waypoints. &amp;nbsp;A couple of notes. &amp;nbsp;&lt;/P&gt;&lt;P&gt;1) I had to add the stops as points and allow the directions widget to make a call to reverse geocode each point.&lt;/P&gt;&lt;P&gt;2) I had to add my actual stops (not waypoints) first then call getDirections() without the waypoints. &amp;nbsp;In my case, routes will have a start and end point with (potentially) waypoints in between to force a route to take certain roads.&lt;/P&gt;&lt;P&gt;3) after getDirections() returns, then add the waypoints as stops.&lt;/P&gt;&lt;P&gt;4) I had to track the index for each waypoint, then coerce the waypoints in my event handler for the directions-start event and set the isWaypoint bool flag to true.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With these caveats, it seemed to work...most of the time. &amp;nbsp;I haven't identified exactly why, but I believe the incremental solving of the route (meaning it solves the route for each stop, then moves on to the next stop), that sometime there existed a race condition between solving the route and updating the stops in the UI for the directions widget. &amp;nbsp;My current workaround, though not great, was to center and zoom to the route's extent prior to loading all the stops. &amp;nbsp;This seems to take just enough time to make it all work. &amp;nbsp;Here's some code (that is still experimental and in development):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;loadStops&lt;/STRONG&gt;: function (routeData) {&lt;BR /&gt; if (routeData != null &amp;amp;&amp;amp;&lt;BR /&gt; routeData.Stops != null &amp;amp;&amp;amp;&lt;BR /&gt; routeData.Stops.length &amp;gt; 0) {&lt;BR /&gt;var stops = JSON.parse(routeData.StopsJson);&lt;BR /&gt;if (stops == null) {&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;return;&lt;BR /&gt; }&lt;BR /&gt; var numStops = stops.length;&lt;BR /&gt;var numWaypoints = 0;&lt;BR /&gt;&lt;STRONG&gt;this.map.directions.stopsAsWaypoints = [];&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;var waypoints = [];&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;// zoom to avoid race condition? between rest api solve and directions widget&lt;/EM&gt;&lt;BR /&gt; var geo = JSON.parse(routeData.Geometry);&lt;BR /&gt; var route = {&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;geometry: geo,&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;"symbol": { "color": [0, 0, 0, 255], "width": 5, "type": "esriSLS", "style": "esriSLSSolid" }&lt;BR /&gt; };&lt;BR /&gt; var routeGraphic = new Graphic(route);&lt;BR /&gt; var graphics = [];&lt;BR /&gt; graphics[0] = routeGraphic;&lt;BR /&gt; var graphicextent = esri.graphicsExtent(graphics);&lt;BR /&gt; this.map.setExtent(graphicextent, true);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// Add stops (not waypoints), one at a time.&lt;/P&gt;&lt;P&gt;// Keep waypoints in array to add when directions have finished&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;for (var index = 0; index &amp;lt; numStops; index++) {&lt;/STRONG&gt;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;var stop = stops[index];&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;var point = new Point(stop.feature.geometry);&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;points[index] = point;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;if (stop.feature.attributes.isWaypoint) {&lt;/STRONG&gt;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;this.map.directions.stopsAsWaypoints[numWaypoints] = index;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;waypoints[numWaypoints] = point;&lt;/STRONG&gt;//stop;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;numWaypoints++;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&lt;STRONG&gt;&amp;nbsp;else&lt;/STRONG&gt;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;&amp;nbsp;this.map.directions.addStop(point, index);&lt;/STRONG&gt;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;this.map.directions.getDirections().then&lt;/STRONG&gt;(lang.hitch(this, function () {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;// NOTE: There appears to be a race condition here where directions are recalculated&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;// if place a breakpoint in directionsstart it works&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;this.map.directions.addStops(waypoints, this.map.directions.stopsAsWaypoints[0]);&lt;/STRONG&gt;&lt;BR /&gt;}));&lt;BR /&gt; }&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's part of the directions-start event handler:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;directionsStartHandler&lt;/STRONG&gt;: function (event) {&lt;BR /&gt;console.log("Starting directions...");&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if (this.embeddedDirections.stops &amp;amp;&amp;amp; this.embeddedDirections.stops.length &amp;gt; 2 &amp;amp;&amp;amp;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.embeddedDirections.stopsAsWaypoints) {&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;for (var ctr = 0; ctr &amp;lt; this.embeddedDirections.stops.length; ctr++)&lt;/STRONG&gt; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// use jQuery $.inArray to see if this stop is in the waypoint list&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if ($.inArray(ctr, this.embeddedDirections.stopsAsWaypoints) != -1) {&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;this.embeddedDirections.stops[ctr].feature.attributes.isWaypoint = true;&lt;/STRONG&gt;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;console.log("Waypoint: " + JSON.stringify(this.embeddedDirections.stops[ctr]));&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR /&gt; }&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 15 Sep 2016 12:40:10 GMT</pubDate>
    <dc:creator>AndyWhitaker1</dc:creator>
    <dc:date>2016-09-15T12:40:10Z</dc:date>
    <item>
      <title>Directions widget - load route with waypoints</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/directions-widget-load-route-with-waypoints/m-p/381511#M35420</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In the JS API 3.17, I am using the Directions widget for routing. &amp;nbsp;After getting directions, I am saving the stops to a SQL Server database in JSON format as returned in the directions. &amp;nbsp;I can load the first two stops to the directions widget by calling updateStop(...). &amp;nbsp;If I've got more than 2 stops, then calling addStop(...) will add another stop in the widget. &amp;nbsp;What I cannot figure out is how to load a start and end point (two stops in the directions widget) AND a waypoint, then allow the directions widget to recalculate directions via a call to getDirections(). &amp;nbsp;The waypoint is not a stop-over point. &amp;nbsp;It's just the location to pass through. &amp;nbsp;I found that the feature property in each stop has an attribute for "isWaypoint". &amp;nbsp;I have tried checking each stop and if isWaypoint==true, then do not add the stop to the directions widget. &amp;nbsp;However, the call to network analyst Route/solve should still have the waypoint(s) so the route is calculated through those points. &amp;nbsp;I'm really just trying to replicate a route with waypoints programmatically. &amp;nbsp;Below is some code I've been playing with to load the stops from the database. &amp;nbsp;routeData is my own&amp;nbsp;Object with properties that I fill from the database. &amp;nbsp;The StopsJson property has the JSON for each exactly as found in the directions widget. &amp;nbsp;Anyone done this or have any advice? &amp;nbsp;If I have not been clear, please comment below and I can elaborate.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loadStops: function (routeData) {&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;if (routeData != null &amp;amp;&amp;amp;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;routeData.Stops != null &amp;amp;&amp;amp;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;routeData.Stops.length &amp;gt; 0) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;var stops = JSON.parse(routeData.StopsJson);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (stops == null) {&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;var numStops = stops.length;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;var comments = routeData.Comments.join(". ");&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;var numWaypoints = 0;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;var insertionIndex = 0;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;// NOTE: do we call Route?solve directly?&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;//this.map.directions.stops = stops;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;for (var index = 0; index &amp;lt; numStops; index++) {&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var stop = stops[index];&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var point = new Point(stop.feature.geometry);&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (stop.feature.attributes.isWaypoint) { //(stop.name != "DWWP") {&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// This is a waypoint&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//insertionIndex = index;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; numWaypoints++;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// The following line adds the stop (as waypoint) but&amp;nbsp;&amp;nbsp;DOESN'T WORK with directions widget&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//this.map.directions.stops.splice(insertionIndex, 0, stop);&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else {&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;insertionIndex = index - numWaypoints;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (insertionIndex &amp;lt; 2) {&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.map.directions.updateStop(point, insertionIndex);&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else {&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.map.directions.addStop(point, insertionIndex);&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; }&lt;BR /&gt; },&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Sep 2016 20:11:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/directions-widget-load-route-with-waypoints/m-p/381511#M35420</guid>
      <dc:creator>AndyWhitaker1</dc:creator>
      <dc:date>2016-09-13T20:11:47Z</dc:date>
    </item>
    <item>
      <title>Re: Directions widget - load route with waypoints</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/directions-widget-load-route-with-waypoints/m-p/381512#M35421</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So I've got a solution that allows me to load a route that has waypoints. &amp;nbsp;A couple of notes. &amp;nbsp;&lt;/P&gt;&lt;P&gt;1) I had to add the stops as points and allow the directions widget to make a call to reverse geocode each point.&lt;/P&gt;&lt;P&gt;2) I had to add my actual stops (not waypoints) first then call getDirections() without the waypoints. &amp;nbsp;In my case, routes will have a start and end point with (potentially) waypoints in between to force a route to take certain roads.&lt;/P&gt;&lt;P&gt;3) after getDirections() returns, then add the waypoints as stops.&lt;/P&gt;&lt;P&gt;4) I had to track the index for each waypoint, then coerce the waypoints in my event handler for the directions-start event and set the isWaypoint bool flag to true.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With these caveats, it seemed to work...most of the time. &amp;nbsp;I haven't identified exactly why, but I believe the incremental solving of the route (meaning it solves the route for each stop, then moves on to the next stop), that sometime there existed a race condition between solving the route and updating the stops in the UI for the directions widget. &amp;nbsp;My current workaround, though not great, was to center and zoom to the route's extent prior to loading all the stops. &amp;nbsp;This seems to take just enough time to make it all work. &amp;nbsp;Here's some code (that is still experimental and in development):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;loadStops&lt;/STRONG&gt;: function (routeData) {&lt;BR /&gt; if (routeData != null &amp;amp;&amp;amp;&lt;BR /&gt; routeData.Stops != null &amp;amp;&amp;amp;&lt;BR /&gt; routeData.Stops.length &amp;gt; 0) {&lt;BR /&gt;var stops = JSON.parse(routeData.StopsJson);&lt;BR /&gt;if (stops == null) {&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;return;&lt;BR /&gt; }&lt;BR /&gt; var numStops = stops.length;&lt;BR /&gt;var numWaypoints = 0;&lt;BR /&gt;&lt;STRONG&gt;this.map.directions.stopsAsWaypoints = [];&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;var waypoints = [];&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;// zoom to avoid race condition? between rest api solve and directions widget&lt;/EM&gt;&lt;BR /&gt; var geo = JSON.parse(routeData.Geometry);&lt;BR /&gt; var route = {&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;geometry: geo,&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;"symbol": { "color": [0, 0, 0, 255], "width": 5, "type": "esriSLS", "style": "esriSLSSolid" }&lt;BR /&gt; };&lt;BR /&gt; var routeGraphic = new Graphic(route);&lt;BR /&gt; var graphics = [];&lt;BR /&gt; graphics[0] = routeGraphic;&lt;BR /&gt; var graphicextent = esri.graphicsExtent(graphics);&lt;BR /&gt; this.map.setExtent(graphicextent, true);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// Add stops (not waypoints), one at a time.&lt;/P&gt;&lt;P&gt;// Keep waypoints in array to add when directions have finished&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;for (var index = 0; index &amp;lt; numStops; index++) {&lt;/STRONG&gt;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;var stop = stops[index];&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;var point = new Point(stop.feature.geometry);&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;points[index] = point;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;if (stop.feature.attributes.isWaypoint) {&lt;/STRONG&gt;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;this.map.directions.stopsAsWaypoints[numWaypoints] = index;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;waypoints[numWaypoints] = point;&lt;/STRONG&gt;//stop;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;numWaypoints++;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&lt;STRONG&gt;&amp;nbsp;else&lt;/STRONG&gt;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;&amp;nbsp;this.map.directions.addStop(point, index);&lt;/STRONG&gt;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;this.map.directions.getDirections().then&lt;/STRONG&gt;(lang.hitch(this, function () {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;// NOTE: There appears to be a race condition here where directions are recalculated&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;// if place a breakpoint in directionsstart it works&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;this.map.directions.addStops(waypoints, this.map.directions.stopsAsWaypoints[0]);&lt;/STRONG&gt;&lt;BR /&gt;}));&lt;BR /&gt; }&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's part of the directions-start event handler:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;directionsStartHandler&lt;/STRONG&gt;: function (event) {&lt;BR /&gt;console.log("Starting directions...");&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if (this.embeddedDirections.stops &amp;amp;&amp;amp; this.embeddedDirections.stops.length &amp;gt; 2 &amp;amp;&amp;amp;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.embeddedDirections.stopsAsWaypoints) {&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;for (var ctr = 0; ctr &amp;lt; this.embeddedDirections.stops.length; ctr++)&lt;/STRONG&gt; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// use jQuery $.inArray to see if this stop is in the waypoint list&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if ($.inArray(ctr, this.embeddedDirections.stopsAsWaypoints) != -1) {&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;this.embeddedDirections.stops[ctr].feature.attributes.isWaypoint = true;&lt;/STRONG&gt;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;console.log("Waypoint: " + JSON.stringify(this.embeddedDirections.stops[ctr]));&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR /&gt; }&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Sep 2016 12:40:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/directions-widget-load-route-with-waypoints/m-p/381512#M35421</guid>
      <dc:creator>AndyWhitaker1</dc:creator>
      <dc:date>2016-09-15T12:40:10Z</dc:date>
    </item>
    <item>
      <title>Re: Directions widget - load route with waypoints</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/directions-widget-load-route-with-waypoints/m-p/1113977#M75160</link>
      <description>&lt;P&gt;Hi, I know it is an old question!&lt;/P&gt;&lt;P&gt;Could you please share with me your code or more details about the issue.&lt;/P&gt;&lt;P&gt;I am working with directions widget argis api 3.38, and I have to save the data route details on a sqlserver and try to load it again on the map.&lt;/P&gt;&lt;P&gt;So could you please share with me the details please ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Nov 2021 09:18:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/directions-widget-load-route-with-waypoints/m-p/1113977#M75160</guid>
      <dc:creator>benchikh</dc:creator>
      <dc:date>2021-11-04T09:18:14Z</dc:date>
    </item>
  </channel>
</rss>

