Hey everyone,
Not sure if this is possible on the API, but im wondering if there is a way to add an existing graphic to a feature layer.
Editor widget with simple toolbar | ArcGIS API for JavaScript this sample allows you to draw a graphic (polygon) and it would add it to a feature layer. What Im trying to do is have a user look up an address (Identify with Popup - as seen here, the user can click an address and it would highlight that polygon) and that address polygon would go into a feature layer upon click.
Solved! Go to Solution.
You can use the FeatureLayer's applyEdits method to save a graphic. Once you have the graphic's geometry and attributes, use the first optional parameter to save it to the featurelayer.
myFeatureLayer.applyEdits([myGraphic],null,null);
You can use the FeatureLayer's applyEdits method to save a graphic. Once you have the graphic's geometry and attributes, use the first optional parameter to save it to the featurelayer.
myFeatureLayer.applyEdits([myGraphic],null,null);
Thanks for your help; I tried the method you mentioned and I cant seem to get it to work.
map.graphics.on("click", function(evt) {
console.log("before edit");
ALFLayer.applyEdits(evt.graphic,null,null,null,errCallback);
console.log("after edit");
console.log(evt.graphic);
});
I put some console.logs to see whats happening. the console.log(evt.graphic) shows a geometry and attribute. But when I do apply edits, nothing seems to happen in the data table. Im wondering if its because a field that cant be null is becoming null? one thing I noticed is when the applyedits code runs, that progress bar below the edit bar never goes away, so it must be stuck on something; even though nothing shows in the console.
The applyEdits parameter is expecting an array of features, meaning your graphic has to be enclosed in brackets. Have you tried
ALFLayer.applyEdits([evt.graphic],null,null,null,errCallback);
Yup that was it. thanks.