[GIS] ArcGIS Feature Layer from Feature Collection using ArcGIS API for JavaScript

arcgis-javascript-apifeature-layer

I am trying to create a polygon feature layer from a feature collection using the ArcGIS API for Javascript. I have modified Esri's Flickr sample to use polygon geometries, rather than point geometries. The features are not getting added to the layer properly. I have put together a JSFiddle here that illustrates the problem. I have commented out the method where I add the features (line 137).

http://jsfiddle.net/gregKnight66/mmhqqan6/

There isn't an error per se, I am just not getting results (the features are not added to the layer).

var featureLayer = new FeatureLayer(featureCollection, {
    id: 'buildingFeatures'
});

map.on("layers-add-result", function (results) {
    addBuildingFeatures();
});

map.addLayers([featureLayer]);

function addBuildingFeatures() {
    var features = buildingFeatures;
    featureLayer.applyEdits(features, null, null);
}

Best Answer

I see two issues in your jsfiddle example:

  1. the functiton addBuildingFeatures is not actually being called. Add line addBuildingFeatures(); right below the function definition to call it.
  2. After you do #1, you are still getting an error - the issue is that you are calling applyEdits and passing your buildingFeatures array of object(s) to the first parameter, but the documentation says that you must pass an array of Graphics. So you must have new Graphic(...); somewhere in your code and pass an array of those.

Hope this helps!