QueryTask Result to a Feature Layer

294
2
Jump to solution
10-15-2018 10:02 AM
DavidKucharski
New Contributor II

I am trying to use the FeatureSet results, from a QueryTask, as the Source of a Feature Layer. No matter how I am doing it, I cannot seem to get the Feature Layer loaded. Please see my logic below and let me know what I am doing wrong. 

1. var qTask = new QueryTask({
url: zipCodeUrl
});

2. var params = new Query({
returnGeometry: true,
outFields: ["*"]
});

3. params.where = "ID_ IN (" + blue.value + ")";
qTask.execute(params)
.then(getBlueResults)
.catch(promiseRejected);

4. 

function getBlueResults(response) {

layer = new FeatureLayer({
 source: response.features, // autocast as an array of esri/Graphic
// // create an instance of esri/layers/support/Field for each field object
 fields: bluefields, // This is required when creating a layer from Graphics
 objectIdField: "ObjectID"
});

map.add(layer);
}

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Esteemed Contributor

David,

   You are missing the required geometryType property (when using source). Do you see any errors in the browsers web console?

View solution in original post

0 Kudos
2 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

David,

   You are missing the required geometryType property (when using source). Do you see any errors in the browsers web console?

0 Kudos
DavidKucharski
New Contributor II

That did it.

layer = new FeatureLayer({
spatialReference: { wkid: 4326 },
source: response.features, // autocast as an array of esri/Graphic
fields: bluefields, 
renderer: blueRenderer,
geometryType: "polygon",
objectIdField: "ObjectID"
});

map.add(layer)

0 Kudos