AnsweredAssumed Answered

Not Able To Display Query Task Result on Graphic Layer

Question asked by behClevest on Sep 27, 2017
Latest reply on Sep 27, 2017 by kenbuja

Using ArcGIS API 3.21 and following code I am trying to populate the result of a Query Task on map by populating the result featureSet on GraphicLayer but I am not getting any thing in result. and No error on Console. Can you please let me know what I am doing wrong?

 

 

var map;
require([
"esri/map",
"esri/layers/FeatureLayer",
"esri/layers/GraphicsLayer",
"esri/tasks/query",
'esri/tasks/QueryTask',
'dojo/_base/array',
"esri/graphic",
"esri/symbols/SimpleMarkerSymbol",
"esri/Color",
"dojo/dom",
"dojo/domReady!"
], function(
Map, FeatureLayer, GraphicsLayer, Query, QueryTask, array, Graphic, SimpleMarkerSymbol, Color, dom
) {
map = new Map("mapDiv", {
basemap: "streets",
center: [-88.155000, 41.784042],
zoom: 14,
slider: false
});

var graphicsLayer = new GraphicsLayer();

var markerSymbol = new SimpleMarkerSymbol(
SimpleMarkerSymbol.STYLE_SQUARE, 10, null, new Color([50,50,255])
);

  var queryTask = new QueryTask("https://server.domain.com/arcgis/rest/services/ElectricData/FeatureServer/3");
  
  var query = new Query();
   query.where = "1=1";
   query.returnGeometry = true;
   query.outFields = [ "CreationUser"];
   queryTask.execute(query).then(onQuerySuccess, onError);

  function onQuerySuccess(featureSet) {
    array.forEach(featureSet.features, function(feature) {
    feature.setSymbol(markerSymbol);
    graphicsLayer.add(feature);
   });
   map.addLayer(graphicsLayer);
  }

  function onError(error) {
    console.error('An error ocurred in the query: ', error);
}

});

Outcomes