Feature edit and existing graphics

3910
4
Jump to solution
02-10-2015 06:11 AM
IbrahimHussein
Occasional Contributor

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.

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

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);

View solution in original post

4 Replies
KenBuja
MVP Esteemed Contributor

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);

IbrahimHussein
Occasional Contributor

Thanks for your help; I tried the method you mentioned and I cant seem to get it to work.

applyedits.jpg

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.

0 Kudos
KenBuja
MVP Esteemed Contributor

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);

IbrahimHussein
Occasional Contributor

Yup that was it. thanks.

0 Kudos