startEditing : function(template) { var drawingTool = template.template.drawingTool; switch(drawingTool) { case FeatureTemplate.TOOL_POINT: drawingTool = Draw.POINT; break; } on(this.drawingToolbar, "draw-end", lang.hitch(this, this.createFeature, template)); this.drawingToolbar.activate(drawingTool); }
createFeature : function(template, evt) { var featureLayer = template.featureLayer; template = template.template; var prototype = template.prototype; var geometry = evt.geometry; var graphic = new Graphic(prototype.toJson()); graphic.setGeometry(geometry); this.initAttributes(graphic, featureLayer).then(function() { var features = [graphic]; featureLayer.applyEdits(features).then(function(addResults) { var objectIds = array.map(addResults, function(addResult) { return addResult.objectId; }); var q = new Query(); q.objectIds = objectIds; featureLayer.selectFeatures(q).then(function(features) { main.openForm(features); }); }); }); }
Solved! Go to Solution.
on(this.drawingToolbar, "draw-end", lang.hitch(this, this.createFeature, template));
on(this.drawingToolbar, "draw-end", lang.hitch(this, this.createFeature, template));
Move below statement out of startEditing function. I don't know what will trigger to call startEditing. But every time it's invoked, onDrawEnd event handler will be defined one more time, which makes createFeature invoked one more time.
I would recommend to define the onDrawEnd event handler in the same function where drawingToolbar instance is created so to ensure it's been defined once only.on(this.drawingToolbar, "draw-end", lang.hitch(this, this.createFeature, template));