Not Able To Display Query Task Result on Graphic Layer

1727
12
Jump to solution
09-27-2017 10:07 AM
BehrouzHosseini
Occasional Contributor

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);
 }
 
 });‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
12 Replies
RobertScheitlin__GISP
MVP Emeritus

Interesting. So you need to manually define the query out spatial reference then

query.outSpatialReference = {wkid:102100};
0 Kudos
KenBuja
MVP Esteemed Contributor

If you want to use map.spatialReference, you'll have to wait until the map's spatial reference has been set in the load event (which fires when the first or base layer has been successfully added to the map)

BehrouzHosseini
Occasional Contributor

Thanks a lots, it is working now!

0 Kudos