Hello everyone. I am working on a new application that has a template picker that works really well. I am looking to limit the user where they can only add three points to the map and that is it. Currently, I have it set up where you click on the template picker, you are in constant draw/editing mode.
Looking to set up a loop on clicks and when you hit 3, you will get an alert that says, "you have added 3 points". Is there a way I can trap the mouse clicks or the number of edits applied?
I am a bit stuck on this...any assistance would greatly be appreciated. Below is my code block:
// *************************************************
// * Editing Code Block *
// *************************************************
function initEditing(evt) {
var layers = arrayUtils.map(evt.layers, function(result) {
return result.layer;
});
// Editor Toolbar
var editToolbar = new Edit(map);
// Draw Toolbar used to Draw Graphic during Editing
var drawToolbar = new Draw(map);
// Template Picker Widget
var templatePicker = new TemplatePicker({
featureLayers: layers,
rows: "auto",
columns: 1,
grouping: false
}, "templatePickerDiv");
templatePicker.startup();
// Template Picker Widget - Selection Only Add Point
var selectedTemplate;
templatePicker.on("selection-change", function() {
if( templatePicker.getSelected() ) {
selectedTemplate = templatePicker.getSelected();
console.log("Name", selectedTemplate);
drawToolbar.activate(Draw.POINT);
}
});
drawToolbar.on("draw-end", function(evt) {
// Loop Variables
//var count = 0;
//var i = 0;
//drawToolbar.deactivate();
//editToolbar.deactivate();
var newAttributes = lang.mixin({}, selectedTemplate.template.prototype.attributes);
console.log("Attributes", newAttributes);
var newGraphic = new Graphic(evt.geometry, null, newAttributes);
selectedTemplate.featureLayer.applyEdits([newGraphic], null, null);
/* -- Code Not working ---- Commented Out --------------------------------------------------------
for(i=0; i<4; i++) {
var newGraphic = new Graphic(evt.geometry, null, newAttributes);
count = count + 1;
console.log("Ian Count", count);
}
if(count < 4) {
selectedTemplate.featureLayer.applyEdits([newGraphic], null, null);
}
else
{
//drawToolbar.deactivate();
//editToolbar.deactivate();
alert(" You have successfully completed 3 edits!");
}
*/ -- Code Not working ---- Commented Out --------------------------------------------------------
});
}