2

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);
}
  • Can you paste the offending lines into your question. It's nice to have the link for context but for readability can you trim it down to the lines causing error. It's not a long script but some would be put off by having to read more than a page of code. – Michael Stimson Sep 20 '15 at 21:33
2

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!

  • I was aware of item #1 -- and noted it in my question. You are correct as far as #2 is concerned. I got some help on another forum, and that turned out to be the issue as well as each geometry object needing a spatial reference object. I was using JSON snippets returned by an ArcGIS rest end point. It seems that what it returns, isn't exactly what it requires in return. Thank you for your help. – GregK Sep 23 '15 at 12:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.