AnsweredAssumed Answered

closestFacility question trouble with query tasks and graphics

Question asked by meyvn77 on Sep 20, 2012
Latest reply on Sep 20, 2012 by meyvn77
I have been using the API for a little bit but am really confused about results from query tasks and graphics layers...

What I am trying to do I thought would be simple but...I'm stuck. I am working with the closestFacility example for my application and from what I understand it can only use graphics... That said, the way I am doing it is this...

1) Add 50 or so facility graphics using a query task on a feature service. I already have a feature layer from this layer but I need graphics for the closestFacility task.
2) Get the XY of the feature the user clicked on and turn that into a graphic
3)well lets stop here because I do not have 1 or 2 working...

The main issue I am having is the facility graphics that I define in the initialization function comes up undefined when I try to use it.

var YardGraphicsLayer = new esri.layers.GraphicsLayer();     YardGraphicsLayer.id = 'YardGraphic';     map.addLayer(YardGraphicsLayer);      var Yardsymbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, 40,             new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,             new dojo.Color([255, 0, 0]), 4),             new dojo.Color([0, 255, 0, 0.25]));      queryYards = new esri.tasks.Query();     queryYards.returnGeometry = true;     queryYards.outFields = ["NAME_CITY", "REGION"];     queryYards.where = "1=1";     queryTaskYards = new esri.tasks.QueryTask("http://services.arcgis.com/s94UJcOoEa23NHUs/arcgis/rest/services/Rigs_by_Yards/FeatureServer/0");     queryTaskYards.execute(queryYards, function (results) {          var featureSet = results.features;         alert("Yards: " + featureSet.length);          for (var i = 0, il = featureSet.length; i < il; i++) {             var graphic = featureSet[i];             graphic.setSymbol(Yardsymbol);             YardGraphicsLayer.add(graphic);         }     }, errCallback);



If I try map.getLayer("YardGraphicsLayer");  when I want to use the layer I get an undefined..
To put it easy I would like to use my own feature layers in the closest Facility example...
Any help would be great,
Charles

Outcomes