How To: Limit the number of edits on a web map configured using ArcGIS API for JavaScript


The ability to disable editing a web map is possible using JavaScript by implementing the drawToolbar.deactivate() and editToolbar.deactivate() functions in a script.

To set a certain number of allowable edits in a web map configured using ArcGIS API for JavaScript before editing is disabled, the script requires a counter with a preset number that triggers the deactivate function when the counter reaches the specified number.


The following instructions demonstrate how to limit the number of edits performed using ArcGIS API for JavaScript. The script sample below sets the count to less than or equals to 3: 

  1. Set up a counter parameter for added graphic.
//Set up the counter for graphic added
count = count + 1; 
console.log("Graphic Count", count);
  1. Set an if...else statement to a activate the drawToobar.deactivate() and editToolbar.deactivate() function with specified number of edits.
//Editing is enabled for 3 or less edit points
if(count <= 3) {
appliedEdits = selectedTemplate.featureLayer.applyEdits([newGraphic], null, null);
alert(" You have successfully completed 3 edits!"); 
return count; 
Edit the code segment, "if(count <= 3)" with the desired number of edits allowed.

Related Information