map.navigationManager missing with optimized build of API

5506
1
Jump to solution
01-15-2015 05:19 PM
BryanBaker
Occasional Contributor

We're using a custom build of the JS API generated with the Web Optimizer (jso.arcgis.com). It's been working OK (though I had to add some missing modules manually that the dependencies didn't pick up - could see those in the browser debugger when it tried to retrieve missing module files).

Now I'm adding in a drawing toolbar. The toolbar initializes, but when I call the toolbar.activate method, I get an error:

Cannot read property 'setImmediateClick' of undefined

If I step into the custom dojo.js code, I see the error is occurring in this statement of the draw tool:

c.navigationManager.setImmediateClick(!1);

Here the "c" is a reference to the map object.

I looked at the sample at Add graphics to a map | ArcGIS API for JavaScript‌, which uses the draw toolbar but the standard JS API source, and stepped into the .activate method, and can see that the map.navigationManager.setImmediateClick() goes into a esri/MapNavigationManager class. That is obviously missing from my application. However, I don't see that module available in the web optimizer. I also ensured that the modules mentioned in the sample are included in my build. Any ideas on how to add that module to my map with the web-optimizer build?

EDIT: I created a custom build for the above-mentioned graphics sample. I started from the option to manually specify modules, and chose the compact build as the starting point. I added the modules listed in the sample. I set up the sample to use this custom build. On a side note, when I first ran with this custom build, I got errors. I had to add two more modules to get it to run at all: dojo/gfx/svg and esri/dijit/Attribution.

With this updated custom build, the graphics sample ran fine, and I could draw graphics. I stepped into the code and can see that the map.navigationManager is populated and works. I compared it to my application's custom build, and added a couple of modules so that my app used all the ones in the sample's build. However, that custom build still fails - no map.navigationManager. More mystifying than before.

1 Solution

Accepted Solutions
BryanBaker
Occasional Contributor

Turns out this was user (developer) error, sort of. I had used code from elsewhere and had just done something like this:

var tb = new Draw(map);

But my map object isn't stored in the "map" variable, it's in a separate custom object. So I should have done something like new Draw(myobj.map). Since there wasn't a variable named map, the javascript engine 'helpfully' instead used the DOM (html) div "map". Obviously not the same thing.

It would have been helpful if the API had complained right away when constructing the Draw object that the thing being passed in wasn't a proper map object. It's also not helpful that all the ESRI samples use "map" for both the div ID and the map variable name, which can lead to this kind of confusion when we follow their pattern!

View solution in original post

1 Reply
BryanBaker
Occasional Contributor

Turns out this was user (developer) error, sort of. I had used code from elsewhere and had just done something like this:

var tb = new Draw(map);

But my map object isn't stored in the "map" variable, it's in a separate custom object. So I should have done something like new Draw(myobj.map). Since there wasn't a variable named map, the javascript engine 'helpfully' instead used the DOM (html) div "map". Obviously not the same thing.

It would have been helpful if the API had complained right away when constructing the Draw object that the thing being passed in wasn't a proper map object. It's also not helpful that all the ESRI samples use "map" for both the div ID and the map variable name, which can lead to this kind of confusion when we follow their pattern!