Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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) {

    this.editToolbar.activate(
        esri.toolbars.Edit.MOVE,
        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){
    debugger;
});

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.

share|improve this question
    
I've submitted a bug report for this to ESRI, I'll update my question when I get a response –  tomfumb Oct 29 '12 at 17:01
    
solution added below –  tomfumb Oct 30 '12 at 19:53
    
You just saved me a million hours. Thank you! –  Andrew Feb 12 '13 at 22:05
add comment

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/

share|improve this answer
    
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 '12 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 '12 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? –  Derek Swingley Oct 25 '12 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 '12 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 '12 at 22:29
show 1 more comment
up vote 2 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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