Draw Toolbar, Dojo Error

Jump to solution
11-16-2015 08:52 AM
Occasional Contributor II

I noticed the question didn't make it through. I've used the sample here: https://developers.arcgis.com/javascript/jssamples/graphics_add.html. I modified it slightly for my app. I am now getting this error:

Error: scriptError
Stack trace:

src: dojoLoader 3.14:31:494
info: Array [ "http://js.arcgis.com/3.14/esri/tool…", error ] 3.14:31:494
. 3.14:32:11

I've made changes in the DIV and double-checked my require statement, without any luck. I also have combed through the code for the toolbar, but I don't see anything missing. Any ideas on what I may be missing? Thanks in advance for any help you can give!

Here's my require statement:

function (domConstruct, Map, Color, keys, has, SnappingManager, SimpleRenderer, esriConfig, Extent, webMercatorUtils, BasemapGallery, HomeButton, Search, Popup, Scalebar, Print, Measurement, InfoTemplate, ArcGISDynamicMapServiceLayer, FeatureLayer, GeometryService, SimpleFillSymbol, SimpleLineSymbol, SimpleMarkerSymbol, Draw, Graphic, TOC, aspect, dom, ready, on

And the code for the toolbar:

mapMain.on("load", initDrawTool);
function initDrawTool() {
var drawToolbar = new Draw({
 map: mapMain,
 drawTime: 25,
 tolerance: 4
drawToolbar.on("draw-end", addGraphic);
on(dom.byId("info"), "click", function (evt) {
if(evt.target.id === "info") {
var drawTool=evt.target.id.toLowerCase();
function addGraphic(evt) {
var symbol;
if ( evt.geometry.type === "point" || evt.geometry.type === "multipoint") {
            symbol = drawMarker;
          } else if ( evt.geometry.type === "line" || evt.geometry.type === "polyline") {
            symbol = drawLine;
          else {
            symbol = drawFill;
          mapMain.graphics.add(new Graphic(evt.geometry, symbol));


var drawMarker = new SimpleMarkerSymbol ();
 drawMarker.setColor(new Color("#FF0000"));
var drawLine = new SimpleLineSymbol ("solid", new Color("#FF0000"), 3);
var drawFill = new SimpleFillSymbol ("solid", new Color(["#FF0000", 1.25]));

And the DIV:

<body class="nihilo">
    <div id="mainWindow" data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="design:'headline'"
     style="width:100%; height:100%;">
      <div id="header" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'top'">
        <div id="PrintButton" style="position:absolute; right: 20px; top: 10px"></div>
  <div id="title">
  <a id ="logo" href="http://www.outdooralabama.com" target="_blank"><img src="images/OA_Header.png"></a>
      <div data-dojo-type="dijit/layout/ContentPane" id="leftPane" data-dojo-props="region:'left'">
        <div id="tocDiv"></div>
   <div id="info">
      <div>Select a shape then draw on map to add graphic</div>
      <button id="Point">Point</button>
      <button id="Multipoint">Multipoint</button>
      <button id="Line">Line</button>
      <button id="Polyline">Polyline</button>
      <button id="FreehandPolyline">Freehand Polyline</button>
      <button id="Triangle">Triangle</button>
      <button id="Extent">Rectangle</button>
      <button id="Circle">Circle</button>
      <button id="Ellipse">Ellipse</button>
      <button id="Polygon">Polygon</button>
      <button id="FreehandPolygon">Freehand Polygon</button>
      <div id="map" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'center'">
    <div style="position:absolute; right:20px; top:25px; z-Index:999;">
    <div data-dojo-type="dijit/TitlePane" data-dojo-props="title:'Switch Basemap', closable:false, open:false">
     <div data-dojo-type="dijit/layout/ContentPane" style="width:380px; height:280px; overflow:auto;">
      <div id="basemapGallery"></div>
    <div style="position:absolute; right:15px; bottom:50px; z-Index:999; width: 250px">
          <div id="TitlePane" data-dojo-type="dijit/TitlePane" data-dojo-props="title:'Measurement', closable:false, open:false">
          <div id ="measurementDiv"></div>
    <span id="latlong" style="position:absolute; right:20px; top:8px; font-size:80%; color:#FFFFFF; z-index:50;"></span>
    <div id="HomeButton"></div>
    <div id="search"></div>
0 Kudos
1 Solution

Accepted Solutions
Regular Contributor

Found the issue, in the require for draw toolbar you need you use "esri/toolbars/draw" and not "esri/toolbars/Draw"

the change is case is not getting the required js file which fails.

View solution in original post

10 Replies
Regular Contributor

the error is in the addGraphics function the drawToolbar is out of scope. the Scope of drawToolbar is within initDrawTool method only. Try to move the variable definition out of the function.

0 Kudos
Occasional Contributor II

I tried removing the variable definition, but that didn't resolve my problem.

0 Kudos
Regular Contributor

apart from drawToolbar.deactivate in addGraphics. there is another error

var drawToolbar = new Draw({  
     map: mapMain, 
     drawTime: 25,  

the correct syntax is

var drawToolbar = new Draw(mapMain, { 

     drawTime: 25,  

Hope this helps

Occasional Contributor II

I've made these changes, but still getting the error. I'm wondering if I have put the drawToolbar.deactivate in the wrong location. Where should it go? I've tried placing it within the initDrawTool method and after all of the Draw Toolbar code.

I apologize for all of the questions, but I'm still pretty new to this and the learning curve has been steep!

0 Kudos
Regular Contributor

The drawToolbar is a local variable in initToolbar function hence, you cannot use it in addGraphics method. hence, I had asked you to move that variable outside like befow

var drawToolbar;
function initToolbar(){
     drawToolbar = new Draw(mapMain, { ...

then, you can use that variable in addGraphics method.

Strange, that you are still getting the error. let me ask you a basic question. when do you get the error at the time of loading or after you draw a grometry?

Can you set up a jsBin or something?

0 Kudos
Occasional Contributor II

The error is at the time of loading. I believe this link will work for jsbin: JS Bin - Collaborative JavaScript Debugging

0 Kudos
Regular Contributor

Found the issue, in the require for draw toolbar you need you use "esri/toolbars/draw" and not "esri/toolbars/Draw"

the change is case is not getting the required js file which fails.

Occasional Contributor II


Thanks for your help! Between this and the other two errors you previously found, the error has been taken care of. While I'm now getting a different error (a symbol has not been defined), I am hoping I can take care of that one myself.

Thanks again!


0 Kudos
Regular Contributor

I created a draw toolbar widget you may be able to use.

WSDOT-GIS/arcgis-js-draw-ui · GitHub

0 Kudos