I'm writing a custom directions widget because the default one doesn't have the functionality I need.
Loading in the from point and the to point work fine.
But on Line 60 my call to routeTask.solve() doesn't do anything? It doesn't even make a network request, which I've monitored through Chrome dev tools. Any ideas on what's going wrong? I've used routeTask.solve() successfully before. The only difference between the successful times and this, that I can see, is that this on a different file and is imported through dojo require.
function CustomDirections(options){
var fromLoc = null;
var toLoc = null;
var view = options.view;
var routeLayer = options.routeLayer;
var routeTask = options.routeTask;
var routeParams = options.routeParams;
var routeSymbol = options.routeSymbol;
var search = options.search;
search.autoSelect = false;
var directionsNode = document.createElement("div");
directionsNode.className = "custom-directions";
var searchNode = document.createElement("div");
search.container = searchNode;
directionsNode.appendChild(searchNode);
var toLocation = document.createElement("p");
toLocation.innerHTML = "Test";
directionsNode.appendChild(toLocation);
var routeWrapper = document.createElement("div");
directionsNode.appendChild(routeWrapper);
search.on("search-complete", function(event){
setFromLocation(event);
event.stopPropagation();
});
search.on("select-result", function(event){
setFromLocation(event);
event.stopPropagation();
});
function setFromLocation(event){
console.log("setFromLocation => ", event.results[0].results[0].feature.geometry);
fromLoc = event.results[0].results[0].feature.geometry;
if(fromLoc !== null && toLoc !== null){
renderRoute();
}
}
function setToLocation(loc){
console.log("setToLocation => ", loc);
toLoc = loc;
toLocation.innerHTML = loc.x.toFixed(0) + ", " + loc.y.toFixed(0);
if(fromLoc !== null && toLoc !== null){
renderRoute();
}
}
function renderRoute(){
routeLayer.removeAll();
routeParams.stops.features = [];
routeParams.stops.features.push(fromLoc);
routeParams.stops.features.push(toLoc);
routeTask.solve(routeParams).then(function(data){
console.log(data);
});
}
return {
domNode: directionsNode,
setToLocation: setToLocation
};
}
Solved! Go to Solution.
Shakil,
Add an otherwise function to capture the error you are receiving or just look at your network traffic or browser web console to see whats going wrong.
Shakil,
Add an otherwise function to capture the error you are receiving or just look at your network traffic or browser web console to see whats going wrong.
Ah of course. Turns out I was adding geometrys to the routeparams instead of graphics.