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– Michael Stimson2015年09月20日 21:33:43 +00:00Commented Sep 20, 2015 at 21:33
1 Answer 1
I see two issues in your jsfiddle example:
- the functiton
addBuildingFeatures
is not actually being called. Add lineaddBuildingFeatures();
right below the function definition to call it. - After you do #1, you are still getting an error - the issue is that you are calling
applyEdits
and passing yourbuildingFeatures
array of object(s) to the first parameter, but the documentation says that you must pass an array of Graphics. So you must havenew 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– GregK2015年09月23日 12:55:42 +00:00Commented Sep 23, 2015 at 12:55
Explore related questions
See similar questions with these tags.