AnsweredAssumed Answered

Problems creating a feature layer from a feature collection

Question asked by stevel on Feb 12, 2013
Latest reply on Dec 15, 2015 by lkoumis
Is anyone able to explain why the attached code isn't working? Also available live here.

I'm trying to create a featureLayer from a featureCollection based on the results of a query.

I'm finding that the featureLayer is apparently created, and I can see that it contains graphics (map.getLayer("query layer").graphics.length shows there are 167 features in the new layer), but they are not visible on the map. There should be a polygon shown in the centre of the map.

The relevant code is:
queryTask.execute(query, selectShowResults, SQLerror);  function selectShowResults(results) {     //Create a feature layer from the results     var featureSet = new esri.tasks.FeatureSet({         features: results.features     });          var fields = [         {             "name": "NAME",             "type": "esriFieldTypeString",             "alias": "Name"         },         {             "name": "OBJECTID",             "type": "esriFieldTypeOID",             "alias": "OBJECTID"         }     ]          var layerDefinition = {       "geometryType": "esriGeometryPolygon",       "fields": fields,       "objectIdField": "OBJECTID",     }       var featureCollection = {       layerDefinition: layerDefinition,       featureSet: featureSet     };          var layer = new esri.layers.FeatureLayer(featureCollection, {         id: "query layer",         mode: esri.layers.FeatureLayer.MODE_SNAPSHOT     })          var renderer = new esri.renderer.SimpleRenderer(         new esri.symbol.SimpleFillSymbol("solid", null, new dojo.Color([255, 0, 255, 0.75])     ));          layer.setRenderer(renderer);     map.addLayer(layer);                 }