problem get infomation directions router

3087
5
07-10-2015 03:07 AM
lasinh
by
New Contributor III

not get information points of router,   returns Locattion 1, loacation2 ....

i use firebug get messages atribute of routeResults

"Input field [field] was not mapped to a field in the network analysis class "Stops"."

below image firebug

router.png

information direction:

ro2.png

my code:

$("#tuyen1").click(function () {

                  var routeTask, routeParams;

                  routeTask = new esri.tasks.RouteTask("http://localhost/arcgis/rest/services/NetworkanalystGT/NetworkanalystGT/NAServer/Route");

                  routeParams = new esri.tasks.RouteParameters();

                  routeParams.stops = new esri.tasks.FeatureSet();

                  routeParams.returnDirections = true;

                  routeParams.returnRoutes = true;

                  routeParams.routeName = true;

                  routeTask.on("solve-complete", showRoute);

                  routeTask.on("error", errorHandler);

                  var queryTaskstuyenDL = new esri.tasks.QueryTask(stringservice + "Bandochuyende/DULICH_03052015/MapServer/35");

                  var querytuyenDL = new esri.tasks.Query();

                  querytuyenDL.returnGeometry = true;

                  querytuyenDL.where = "upper(PHANLOAI_LUU) like 'ĐÌNH, CHÙA'";

                  querytuyenDL.outSpatialReference = myMap.spatialReference;

                  querytuyenDL.spatialRelationship = esri.tasks.Query.SPATIAL_REL_INTERSECTS;

                  queryTaskstuyenDL.execute(querytuyenDL, function (featureSet) {

                      myMap.graphics.clear();

                      var resultFeatures = featureSet.features;

                      if (resultFeatures.length > 0) {

                          for (var i = 0, il = resultFeatures.length; i < il; i++) {

                          

                              var graphic = resultFeatures;                        

                              routeParams.stops.features.push(resultFeatures);

                              graphic.setSymbol(symbolmochc);                         

                              myMap.infoWindow.setFeatures([resultFeatures]);                          

                              myMap.graphics.add(graphic);                             

                          }

                          routeTask.solve(routeParams);

                      }

                  });

              });                     

              function showRoute(evt) {

                  var segmentGraphic;

                  var directions = evt.result.routeResults[0].directions;

                  var directionFeatures = directions.features;

                  var routeSymbol = new esri.symbol.SimpleLineSymbol().setColor(new dojo.Color([0, 120, 255, 0.5])).setWidth(4);

                  myMap.graphics.add(evt.result.routeResults[0].route.setSymbol(routeSymbol));

                  myMap.setExtent(directions.extent, true);

                  var directionsInfo = evt.result.routeResults[0].directions.features;

                  var totalDistance = dojo.number.format(directions.totalLength);

                  var totalLength = dojo.number.format(directions.totalTime);

                  data = dojo.map(directionsInfo, function (feature, index) {

                      return {

                          "detail": feature.attributes.text,

                          "distance": dojo.number.format(feature.attributes.length, { places: 2 }),

                          "index": index

                      }

                  });

                  var griddirection = new dgrid.Grid({

                      renderRow: renderList,

                      showHeader: true

                  }, "griddirection");

                  griddirection.renderArray(data);

                  griddirection.on(".dgrid-row:click", function (evt) {

                      var index = griddirection.row(evt).id;

                      var segment = directionFeatures[index];

                      var segmentSymbol = new esri.symbol.SimpleLineSymbol().setColor(new dojo.Color([255, 0, 00, 0.5])).setWidth(10);

                      myMap.setExtent(segment.geometry.getExtent(), true);

                      if (!segmentGraphic) {

                          segmentGraphic = myMap.graphics.add(new esri.Graphic(segment.geometry, segmentSymbol));

                      } else {

                          segmentGraphic.setGeometry(segment.geometry);

                      }

                  });

                  $('#griddirection').show();

                  $('#griddirection').draggable();

              }

              function errorHandler(err) {

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

              }

0 Kudos
5 Replies
TomSellsted
MVP Regular Contributor

Ia,

Some things to check. 

Did your query return a result?  If no results are returned, then no stops will be created.  Or there may be too many stops for a route to be solved.

Are the stops using the same spatial reference as the route network used?  If they are not, the stops won't be close enough to the route's street network to be considered a stop point.

Regards,

Tom

lasinh
by
New Contributor III

Thanks Tom!

My query return a few points

yes, i use router netwword, i was showed points and router, i not show points address in results direction

i displayed direction of the router,  but instead of displaying the specific points address, Then  the results returned is the location1, locattion2 in the directions

r11.png

0 Kudos
TomSellsted
MVP Regular Contributor

Ia,

To get the stop name to appear you must assign it as you add the stop.  It would be ideal if when you added a stop that it would find a "Name" field and use it for your stop location name.  To solve this problem, I created an stop object to use for each feature and explicitly added a stop name.

  // add the selected stops
  arrayUtil.forEach(selectedGraphicsLayer.graphics, function(feature, i) {
       var a = feature.attributes;
       // make a stop so we have name and XY
       var stop = {
            name: a.Name, 
            feature: {
                 geometry: {
                      x: feature.geometry.x, 
                      y: feature.geometry.y
                 }, 
                 attributes: a
       }
  };
  directions.addStop(stop);
  });
  directions.getDirections();

This example was from a craft beverage tour where the app user can select which locations they would like to visit and create driving directions.  You can view this example at:  Craft Beverage Tour  Please view source to see how I manage the stops for this app.

I hope this helps!

Regards,

Tom

lasinh
by
New Contributor III

Thank you! my code worked

0 Kudos
TimWitt2
MVP Alum

La,

don't forget to mark the right answer.

Tim

0 Kudos