Problems with Draw Toolbar

920
5
Jump to solution
10-15-2012 11:11 AM
JessicaKnight1
Occasional Contributor
I am attempting to get the draw toolbar to work in my application so I can use it as part of a geoprocessing task. I am just using it for a point feature. I had looked at the samples online and thought I had it sorted out, but apparently I haven't. I have attached my code here.

I keep getting an error saying that my toolbar variable is undefined, but I have it defined earlier in the code. I figure another set of eyes on it may help me see where I have an error. A simple misspelling or something simple is hopefully all that is wrong. I haven't begun really working on the GP task itself yet as I wanted to get this working first.

If I could get any help that would be great. Being a JS coding novice can be frustrating at times...


Thanks!
0 Kudos
1 Solution

Accepted Solutions
DavideLimosani
Frequent Contributor
Hi,

try this:

1) put
function createToolbar(themap){     toolbar = new esri.toolbars.Draw(map);     dojo.connect(toolbar,"onDrawEnd", addToMap); }  function addToMap(geometry){     toolbar.deactivate();     var symbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE, 10, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0]), 1), new dojo.Color([0, 255, 0, 0.25]));     var graphic = new esri.Graphic(geometry,symbol);     map.graphics.add(graphic); }


outside the executeIdentifyTask function.
Just before the dojo.connect(map, 'onLoad', createToolbar) inside init() is good.

2)
uncomment the  dojo.connect(map, 'onLoad', createToolbar);

The problem is that the function createToolbar is not called by your code because it is written inside the executeIdentifyTask that is called only when you click on the map.

Regards,
Davide

View solution in original post

0 Kudos
5 Replies
DavideLimosani
Frequent Contributor
Hi,

try this:

1) put
function createToolbar(themap){     toolbar = new esri.toolbars.Draw(map);     dojo.connect(toolbar,"onDrawEnd", addToMap); }  function addToMap(geometry){     toolbar.deactivate();     var symbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE, 10, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0]), 1), new dojo.Color([0, 255, 0, 0.25]));     var graphic = new esri.Graphic(geometry,symbol);     map.graphics.add(graphic); }


outside the executeIdentifyTask function.
Just before the dojo.connect(map, 'onLoad', createToolbar) inside init() is good.

2)
uncomment the  dojo.connect(map, 'onLoad', createToolbar);

The problem is that the function createToolbar is not called by your code because it is written inside the executeIdentifyTask that is called only when you click on the map.

Regards,
Davide
0 Kudos
JessicaKnight1
Occasional Contributor
Thanks. But unfortunately that's not solving my problem. I still get a "toolbar is undefined" error. Any other thoughts?
0 Kudos
JessicaKnight1
Occasional Contributor
Bumping this up. I need a hand!
0 Kudos
KellyHutchins
Esri Notable Contributor
Jessica you were close but the line that called the function that initialized the draw toolbar was commented out. There were also a few formatting issues that may have been contributing to the problem. I modified your code to call the draw toolbar right after you create the nav toolbar. See a working version of your code here:


http://jsfiddle.net/KqmwX/
0 Kudos
JessicaKnight1
Occasional Contributor
Thanks so much! Hopefully I can get my GP task up and running soon now...trying to teach this to myself has been a challenge for sure!
0 Kudos