Keith,
So your issue is one that trips up many JS developers at first, it is a scope issue.
You are trying to use "this" in a function for the draw end and inside that function "this" is different than what "this" is outside of that function. In Dojo you use lang.hitch to get around this issue.
define([
'dojo/_base/declare',
'jimu/BaseWidget',
'esri/symbols/SimpleMarkerSymbol',
'esri/graphic',
'esri/toolbars/draw',
'esri/Color',
'esri/symbols/SimpleLineSymbol',
'dojo/_base/lang'],
function (declare, BaseWidget, SimpleMarkerSymbol, Graphic, Draw, Color, SimpleLineSymbol, lang) {
var myDraw, symbol, graphic;
//To create a widget, you need to derive from BaseWidget.
return declare([BaseWidget], {
// Custom widget code goes here
baseClass: 'my-first-widget',
// this property is set by the framework when widget is loaded.
// name: 'MyFirstWidget',
// add additional properties here
//methods to communication with app container:
postCreate: function () {
this.inherited(arguments);
//console.log('MyFirstWidget::postCreate');
//console.log(this.map.id);
},
starting: function () {
myDraw.activate(Draw.POINT);
//myDraw.activate(Draw.POINT);
//console.log('MyFirstWidget::startup');
},
startup: function () {
this.inherited(arguments);
myDraw = new Draw(this.map);
myDraw.on("draw-end", lang.hitch(this, function (evt) {
//symbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_DIAMOND, 10, null, new Color("#ff6666") );
symbol = new SimpleMarkerSymbol(this.config.symbols.smsymbol);
graphic = new Graphic(evt.geometry, symbol);
this.map.graphics.add(graphic);
myDraw.finishDrawing();
myDraw.deactivate();
}));
},
// onOpen: function(){
// console.log('MyFirstWidget::onOpen');
// },
onClose: function () {
myDraw.deactivate();
// console.log('MyFirstWidget::onClose');
}
});
});