[GIS] Programatically add feature to Feature Layer with ArcGIS JavaScript API

arcgis-javascript-apiarcgis-serverjavascript

I've so far been able to add a feature layer from an ArcGIS server, and I've also been able to add an editor widget which allows me to draw to feature with the mouse. The added features are being correctly committed to the server, and are visible from other viewers as well as in the SDE database. I have also been able to add the Editor toolbar and edit the existing polygon features.

However, I'm now looking for a way to add a feature without using the widget, just using JavaScript code. The closest thing I found was http://forums.esri.com/Thread.asp?c=206&f=2274&t=271592 but it discusses .NET and doesn't look similar to the way something like that would be achieved in Javascript. Where would the best starting point be for doing something like this?

Best Answer

I think what you're trying to do would use a combo of the Draw tool and the FeatureLayer applyEdits method. This sample kind of gets you started, but the workflow is use Draw tool, on draw-end event, add drawn graphic using applyEdits method of FeatureLayer. I don't have a solid example on hand, but here is a simple-edit-widget and sample code from my book.

If you wanted to do it all via non-esri JS code, you'll need to get familiar with the ArcGIS REST API, particularly the applyEdits endpoint of a Feature Service.

Hope that helps.