AnsweredAssumed Answered

Issue on Generating FeatureLayer From FeatureCollection With ArcGIS JS API

Question asked by behClevest on Dec 12, 2016
Latest reply on Dec 13, 2016 by behClevest

Can you please take a look at This Demo and let me if this is doable to create a FeatureLayer from featureCollection without using URL

Here is the code I am trying to use:

var schoolData = {"schools":[
{ "latitude":49.2752, "longitude":-123.0719, "name":"King George" },
{ "latitude":49.2627, "longitude":-123.1636, "name":"Britannia" },
{ "latitude":49.2253, "longitude":-123.0442, "name":"Killarney" }
]};

var featureCollection = {
"layerDefinition": null,
"featureSet": {
"features": [],
"geometryType": "esriGeometryPoint"
}
};
featureCollection.layerDefinition = {
"geometryType": "esriGeometryPoint",
"objectIdField": "ObjectID",
"drawingInfo": {
"renderer": {
"type": "simple",
"symbol": {
"type": "esriPMS",
"width": 15,
"height": 15
}
}
},
"fields": [{
"name": "ObjectID",
"alias": "ObjectID",
"type": "esriFieldTypeOID"
}, {
"name": "latitude",
"alias": "Description",
"type": "esriFieldTypeGeometry"
}, {
"name": "longitude",
"alias": "Title",
"type": "esriFieldTypeGeometry"
},{
"name": "name",
"alias": "Description",
"type": "esriFieldTypeString"
}]
};

var featureLayer = new FeatureLayer(featureCollection, { id: 'schoolsLayer' });
  map.addLayers(featureLayer);
  });

Outcomes