directions = new Directions({ map: map, stops: ["Knoxville ", "Chattanouga"], },"directionsDiv"); directions.startup(); directions.getDirections();
Solved! Go to Solution.
var directions = new Directions({ map: map }, "dir"); directions.on("load", function(){ directions._updateStops(["Knoxville ", "Chattanouga"]).then(function(stops){ console.log("stops object: ", stops); directions.getDirections(); }); });
Hi and welcome to the forums!
Are you waiting for both the DOM and the map to load before calling getDirections()?
on(map, "load", function(){ // the map has been loaded, do the following directions.getDirections(); });
map.on("load", function(){ // the map has been loaded, do the following directions.getDirections(); });
You can use DOJO's AMD style event listener, on, and listen for the 'load' event that the map emits.
http://dojotoolkit.org/reference-guide/1.9/dojo/on.html#dojo-on
Blog:
http://dojotoolkit.org/documentation/tutorials/1.9/events/on(map, "load", function(){ // the map has been loaded, do the following directions.getDirections(); });
edit*
This should also work (same thing written differently).map.on("load", function(){ // the map has been loaded, do the following directions.getDirections(); });
console.log(map.loaded); directions.getDirections();
var directions = new Directions({ map: map }, "dir"); directions.on("load", function(){ directions._updateStops(["Knoxville ", "Chattanouga"]).then(function(stops){ console.log("stops object: ", stops); directions.getDirections(); }); });
Hey James,
It looks like this is an unintended bug. It will be fixed in the next version.
In the meantime, here is a work-around using one of the internal ("private") functions.var directions = new Directions({ map: map }, "dir"); directions.on("load", function(){ directions._updateStops(["Knoxville ", "Chattanouga"]).then(function(stops){ console.log("stops object: ", stops); directions.getDirections(); }); });
Note: For this work-around, don't set the 'stops' parameter in the Direction widget constructor.
We are using the deferred returned by _updateStops() to confirm that the stops have been properly loaded.