define([ "dojo/on", "dojo/dom", "dojo/_base/event", "dojo/_base/declare", "dijit/_WidgetBase", "dijit/_TemplatedMixin", "dojo/text!./templates/DrawingToolsWidget.html", "esri/toolbars/draw", "esri/toolbars/edit", "esri/graphic", "esri/symbols/SimpleMarkerSymbol", "esri/symbols/SimpleLineSymbol", "esri/symbols/SimpleFillSymbol", "esri/geometry/Point", "esri/geometry/Polygon", "esri/geometry/jsonUtils", "esri/undoManager", "dojo/_base/Color", "dojo/domReady!" ], function( on, dom, Event, declare, _WidgetBase, _TemplatedMixin, template, Draw, Edit, Graphic, SimpleMarkerSymbol, SimpleLineSymbol, SimpleFillSymbol, Point, Polygon, geometryJsonUtils, UndoManager, Color) { return declare("DrawingToolsWidget",[_WidgetBase, _TemplatedMixin], { templateString: template, map:{}, toolbar:{}, symbol:{}, editToolbar:{}, selected:{}, currentLocation:{}, undoManager:{}, constructor: function(map) { this.map = map; this.undoManager = new UndoManager(); }, postCreate: function() { console.log(this.undoManager); this.createToolbar(); }, chooseTool: function(e) { Event.stop(e); var tool = e.target.id; console.log(tool); this.activateTool(tool); }, activateTool: function(tool) { // tool = tool.toUpperCase().replace(/ /g, "_"); this.toolbar.activate(Draw[tool]); this.map.hideZoomSlider(); }, chooseMoveTool: function(e) { Event.stop(e); var self = this; this.toolbar.deactivate(); self.editToolbar = new Edit(this.map); // this.editToolbar.deactivate(); this.map.graphics.on("click", function(evt) { self.selected = evt.graphic; // console.log(self.selected); self.editToolbar.activate(Edit.MOVE, evt.graphic); }); }, chooseDeleteTool: function(e) { Event.stop(e); var self = this; this.toolbar.deactivate(); this.map.graphics.on("click", function(evt) { map.graphics.remove(evt.graphic); }); }, createToolbar: function() { this.toolbar = new Draw(this.map); this.toolbar.on("draw-end", this.addToMap); }, undo: function(e) { Event.stop(e); this.undoManager.undo(); }, redo: function(e) { Event.stop(e); this.undoManager.redo(); }, addToMap: function(evt) { var symbol; console.log(this.undoManager); // this.toolbar.deactivate(); this.map.showZoomSlider(); switch (evt.geometry.type) { case "point": case "multipoint": symbol = new SimpleMarkerSymbol(); break; case "polyline": symbol = new SimpleLineSymbol(); break; default: symbol = new SimpleFillSymbol(); break; } var graphic = new Graphic(evt.geometry, symbol); var operation = this.map.graphics.add(graphic); this.undoManager.add(operation); //<-- this returns undefined, but the reference to this.map above it is fine. }, deactivateToolbar: function(e) { Event.stop(e); this.toolbar.deactivate(); } }); } );
Solved! Go to Solution.
this.toolbar.on("draw-end", this.addToMap);
this.toolbar.on("draw-end", lang.hitch(this, "addToMap"));
this.toolbar.on("draw-end", this.addToMap);
this.toolbar.on("draw-end", lang.hitch(this, "addToMap"));