Trouble with routing

Discussion created by jjmiller1980 on Nov 22, 2010
Latest reply on Nov 24, 2010 by ciava.at
I�??m new to the ESRI map system and I�??m having a problem.  We�??re using an ESRI map in our JSF application.  The application will bring up some information and multiple buttons to create different routes (generally 3 different routes).  I�??m having kind of a strange problem.  Here�??s the scenario:

  • I go to the page and do a look-up

  • When it comes up, click icon for the first route, and it routes fine.  The stops show up on the map almost instantly, and the line to connect the dots shows up after a short delay (5 seconds or so).

  • After that one routes, I try to route any other icon and they all come up with �??Error�?�.

  • I close my browser and open a new browser, go back to the page and perform the same look-up.

  • When it comes up, I click on cycle icon for the BOTTOM icon and I get the error.  Now, no matter what icon I click, I get errors on all of them (including the one that worked before). 

  • If I close and reopen the browser again, and do the same look-up again, it works the same way.  If I click the top one, it works, but nothing else does.  If I click anything else, nothing works.

No matter what, all the stops do show up on the map.  And I have a pop up to show me what's being sent, and can verify that all of the stops I'm sending ARE valid points on the layer that I'm telling it to route to.  So I'm not sure what's going on. 

My code, which I�??ll post below, closely matches the sample shown here (http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples_start.htm#jssamples/routetask_find_route.html), with some small adjustments such as the map & layer locations.  The first line of the errorHandler is:

alert("An error occured\n" + err.message + "\n" + err.details.join("\n"));

I changed that to just


Because I wasn�??t getting an error message with it the other way, just nothing would happen.

I appreciate any help you can provide.

var map, routeTask, routeParams;
var stopSymbol, routeSymbol, lastStop;
var resizeTimer;
function init() {
 dojo.style(dojo.byId("map"), { width: "100%", height: "640px" });

 map = new esri.Map("map", {logo:false});

 var baselayer = new esri.layers.ArcGISTiledMapServiceLayer("...");
 //var streetslayer = new esri.layers.ArcGISTiledMapServiceLayer("...");
 var raillayer = new esri.layers.ArcGISTiledMapServiceLayer("...");
 var labelslayer = new esri.layers.ArcGISDynamicMapServiceLayer("...");
 var nbclayer = new esri.layers.ArcGISDynamicMapServiceLayer("...");
 routeTask = new esri.tasks.RouteTask("...");
    routeParams = new esri.tasks.RouteParameters();
    routeParams.stops = new esri.tasks.FeatureSet();
    routeParams.returnStops = true;

    dojo.connect(routeTask, "onSolveComplete", showRoute);
    dojo.connect(routeTask, "onError", errorHandler);
    stopSymbol = new esri.symbol.SimpleMarkerSymbol().setStyle(esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE).setSize(6);

    routeSymbol = new esri.symbol.SimpleLineSymbol().setColor(new dojo.Color([112,219,147])).setWidth(3);
 dojo.connect(map, "onLoad", function() {

function findRoute(list){
 alert("List: " + list);
 var queryTask  = new esri.tasks.QueryTask("...");
    var query = new esri.tasks.Query();
    query.returnGeometry = true;
    query.where = "POST_I IN (" + list+ ")";
    queryTask.execute(query, addStops, errorHandler);

function addStops(results) {
 var symbol = new esri.symbol.SimpleMarkerSymbol().setStyle(esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE).setSize(10).setColor(new dojo.Color([112,219,147]));
 for (var i = 0; i < results.features.length; i++) {
  var graphic = results.features[i];
   var stop = map.graphics.add(graphic);
 if (routeParams.stops.features.length >= 2) {
      lastStop = routeParams.stops.features.splice(0, 1)[0];

//Adds the solved route to the map as a graphic
function showRoute(solveResult) {
 dojo.forEach(solveResult.routeResults, function(routeResult, i) {

//Displays any error returned by the Route Task
function errorHandler(err) {
 //alert("An error occured\n" + err.message + "\n" + err.details.join("\n"));
 routeParams.stops.features.splice(0, 0, lastStop);
 map.graphics.remove(routeParams.stops.features.splice(1, 1)[0]);

function reactToResize(){
 // Resizes the map to fill the container it's in.
 resizeTimer = setTimeout( function() {
 var mapDiv = dojo.byId(this.map.id); 
 }, 500);

function clearGraphics() {
 // Clears all routes/points from map.