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 https://developers.arcgis.com/javascript/latest/sample-code/editing-applyedits/index.html, 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.
Thanks!
Deepanjana,
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
Robert,
Thanks a lot, will try it out.
Deepanjana, Did you ever get this working? If so, can you share your code, please?
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
<SPAN class="keyword token">var</SPAN> sketchViewModel <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">SketchViewModel</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">{</SPAN> view<SPAN class="punctuation token">:</SPAN> view<SPAN class="punctuation token">,</SPAN> layer<SPAN class="punctuation token">:</SPAN> featureLayer<SPAN class="punctuation token">,</SPAN> polygonSymbol<SPAN class="punctuation token">:</SPAN> polygonSymbol <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// ************************************************************</SPAN> <SPAN class="comment token">// Get the completed graphic from the event and add it to view.</SPAN> <SPAN class="comment token">// This event fires when user presses</SPAN> <SPAN class="comment token">// * "C" key to finish sketching point, polygon or polyline.</SPAN> <SPAN class="comment token">// * Double-clicks to finish sketching polyline or polygon.</SPAN> <SPAN class="comment token">// * Clicks to finish sketching a point geometry.</SPAN> <SPAN class="comment token">// ***********************************************************</SPAN> sketchViewModel<SPAN class="punctuation token">.</SPAN><SPAN class="token function">on</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"draw-complete"</SPAN><SPAN class="punctuation token">,</SPAN> addGraphic<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> sketchViewModel<SPAN class="punctuation token">.</SPAN><SPAN class="token function">on</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"update-complete"</SPAN><SPAN class="punctuation token">,</SPAN> modifyGraphic<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//sketchViewModel.on("update-cancel", modifyGraphic);</SPAN> <SPAN class="comment token">//sketchViewModel.on("update-start", modifyGraphic);</SPAN> <SPAN class="keyword token">function</SPAN> <SPAN class="token function">addGraphic</SPAN><SPAN class="punctuation token">(</SPAN>evt<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">var</SPAN> geometry <SPAN class="operator token">=</SPAN> evt<SPAN class="punctuation token">.</SPAN>geometry<SPAN class="punctuation token">;</SPAN> newIncident <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Graphic</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">{</SPAN> geometry<SPAN class="punctuation token">:</SPAN> geometry<SPAN class="punctuation token">,</SPAN> symbol<SPAN class="punctuation token">:</SPAN> polygonSymbol<SPAN class="punctuation token">,</SPAN> attributes<SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> edits <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN> addFeatures<SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">[</SPAN>newIncident<SPAN class="punctuation token">]</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="token function">applyEdits</SPAN><SPAN class="punctuation token">(</SPAN>edits<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.