Can I draw simple geometries and save them as features on my feature layer in JS API 4.x?

03-16-2018 01:11 AM
New Contributor II

I found this sample for JS API 3.x Edit without editor widget | ArcGIS API for JavaScript 3.23  and I want to do something similar in JS 4.x, I only found this sample for now, but here it's just adding point data. Is there something similar like the sample in v3 available in v4 where I can draw, edit and delete a polygon and have it saved as a feature layer? If yes, it would be helpful if someone could point me to some documentation or samples.


0 Kudos
5 Replies
MVP Esteemed Contributor


   In the current release 4.6 there is no sample or editing tools. But you can combine the SketchViewModel and the editing sample you provided above to do what you want.

SketchViewModel | API Reference | ArcGIS API for JavaScript 4.6 

Sketch temporary geometries | ArcGIS API for JavaScript 4.6 

New Contributor II


Thanks a lot, will try it out.

0 Kudos
Occasional Contributor

Deepanjana, Did you ever get this working? If so, can you share your code, please?

0 Kudos
New Contributor II

Simon, I did get it to work, I used Update FeatureLayer using applyEdits() | ArcGIS API for JavaScript 4.9.  I used sketchviewmodel to draw the features and then do applyEdits()

something like this

var sketchViewModel = new SketchViewModel({
    view: view,
    layer: featureLayer,
    polygonSymbol: polygonSymbol

    // ************************************************************
    // Get the completed graphic from the event and add it to view.
    // This event fires when user presses
    //  * "C" key to finish sketching point, polygon or polyline.
    //  * Double-clicks to finish sketching polyline or polygon.
    //  * Clicks to finish sketching a point geometry.
    // ***********************************************************
    sketchViewModel.on("draw-complete", addGraphic);
    sketchViewModel.on("update-complete", modifyGraphic);
    //sketchViewModel.on("update-cancel", modifyGraphic);
    //sketchViewModel.on("update-start", modifyGraphic);

    function addGraphic(evt) {
      var geometry = evt.geometry;
      newIncident = new Graphic({
        geometry: geometry,
        symbol: polygonSymbol,
        attributes: {}

      var edits = {
        addFeatures: [newIncident]


0 Kudos
Occasional Contributor


Thank you. That’s great.

For anyone finding this in the future, Deepanjana and Robert Scheitlins replies are combined in to a working 1 page solution here: View the full discussion<>


0 Kudos