I'm putting together an ArcGIS (v10.1) JS API (v3.2) application and I've hit a snag in drawing / editing functionality.

Users can draw a new geometry or edit an existing one. I'm using the draw and edit toolbars to achieve this, but attempting to activate the edit toolbar is producing some strange errors and I don't know where to start debugging.

This function works fine for moving a Graphic around on the map:

editGraphic: function(graphic) {

        {allowAddVertices: true, allowDeleteVertices: true} // used for EDIT_VERTICES action

However, if I change the action to esri.toolbars.Edit.EDIT_VERTICES, esri.toolbars.Edit.ROTATE, or any combination I get

Uncaught TypeError: Cannot call method 'add' of null _VertexMover.js:19

I've managed to do some digging (it's not easy as ESRI has everything uglified and Chrome's developer tools crash when I try to pretty print the API to support tracing the error. It seems the null object in question is a property called _scratchGL, which I assume should be the Graphics Layer, but is null (note it's not undefined).

The edit toolbar is defined as

this.editToolbar = new esri.toolbars.Edit(this.map)

and obviously the map is what it should be.

I discovered while debugging other errors that the Graphic should be passed to my edit function via a Graphics Layer event, so the graphic variable passed to my function is sourced in this way (I think this is necessary to ensure key properties are set on Graphic, such as the Graphics Layer it belongs to).

Unfortunately due to the size and many files in my application it's just not possible to show a useful sub-section of the code and I can't provide the whole lot.

The fact that I can use the MOVE action tells me that I'm doing things correctly, so why can I not edit vertices or rotate?

Fundamentally I'm not doing anything different to this example, which uses the same version of the API. However it is perhaps significant that if I add the following line of code it does not respond to clicks, even when all other map click handlers are disabled

dojo.connect(this.map.graphics, "onClick", function(evt){

Has anyone had a similar experience? I've Googled this quite a bit but to no useful outcome. I don't even know where to start on the problem. Any thoughts very much appreciated.

  • I've submitted a bug report for this to ESRI, I'll update my question when I get a response
    – tomfumb
    Oct 29, 2012 at 17:01
  • solution added below
    – tomfumb
    Oct 30, 2012 at 19:53

2 Answers 2


Honestly, you're into a corner the API that not a lot of people are using so I'm not surprised there weren't many results from Google on this. Editing in a web app isn't yet an operation that a lot of people are using.

The issue is probably in the "tool" argument you're passing to editToolbar.activate. That argument isn't an array of constants but rather uses a bitmask. While clever, it is not intuitive or readable.

When you want to specify multiple operations, combine them with the | operator. This is documented in the activate method section of the edit toolbar docs. It's also shown in the edit toolbar sample. If that doesn't work, please post all of the code you're using to call editToolbar.activate.

Edit: here's a simplified version of the edit toolbar sample showing edit vertices + add vertices as well as rotate: http://jsfiddle.net/GKuhX/

  • Thanks Derek but that is how I'm combining the actions. I get the same problem if I only use EDIT_VERTICES or ROTATE on their own. Perhaps anything that requires the dotted lines and vertices shown on the Graphics Layer?
    – tomfumb
    Oct 24, 2012 at 21:29
  • The sample you linked to is the one I referenced in my question. I'm really not doing anything fundamentally different - using the argument from a graphics event, with an action and some basic options in the activate method. However something is still not working, so I assume it's related to how my map is configured. Unfortunately the error doesn't provide any idea where to start investigating
    – tomfumb
    Oct 24, 2012 at 21:31
  • @tomfumb I've added a link to a simplified version of the sample that shows adding and editing vertices only. It's hard to say where the issue is without seeing more of your code. The easiest way forward will be to look at a simplified version of your code that still reproduces the issue. Can you provide that? Oct 25, 2012 at 4:10
  • Yes I was thinking Idd have to put together a stripped-down example that just shows this problem, I'll work on it. Hopefully this slim version will work great and highlight my problem, but if it still causes problems I'll let you know
    – tomfumb
    Oct 25, 2012 at 16:15
  • I now have a small test application that replicates the error. The application is in the AMD vein (perhaps this is part of the problem) so I can't dump the whole thing on a JS Fiddle. There are only three files (around 5k unzipped). If you are still interested in seeing this is there anywhere conveinent I can pass it to you?
    – tomfumb
    Oct 25, 2012 at 22:29

Following direction from @DerekSwingley (for which I am very grateful) this problem has now been solved.

The primary issue is that the Edit toolbar is created before the map has completely loaded. Although the toolbar's API documentation does not explicitly identify this as a requirement the samples do follow the same practice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.