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; graphic.setSymbol(Yardsymbol); YardGraphicsLayer.add(graphic); } }, errCallback);
Solved! Go to Solution.
var YardGraphicsLayer = new esri.layers.GraphicsLayer(); YardGraphicsLayer.id = 'YardGraphic';
var YardGraphicsLayer = new esri.layers.GraphicsLayer({ "id": "YardGraphic" });
dojo.connect(graphicsLayer, "onClick", function(evt) { console.log("clicked graphic: ", evt.graphic); });
function ClosestYard() { var facilities = new esri.tasks.FeatureSet(); facilities.features = map.getLayer("featureLayerYard").graphics; /// This is wrong way to put featurelayer into params.facilities = facilities; params.outSpatialReference = map.spatialReference; closestFacilityTask = new esri.tasks.ClosestFacilityTask("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Network/USA/NAServer/Closest Facility"); ........
dojo.forEach(featureSet.features,function(feature){ var graphic = feature; graphic.setSymbol(symbol); //Set the infoTemplate. graphic.setInfoTemplate(infoTemplate); //Add graphic to the map graphics layer. map.graphics.add(graphic); });
dojo.forEach(featureSet.features,function(feature){ //var graphic = feature; feature.setSymbol(symbol); //Set the infoTemplate. feature.setInfoTemplate(infoTemplate); //Add graphic to the map graphics layer. map.graphics.add(feature); });