4

I am developing a web map application in the ArcGIS API for Javascript.

I two have ArcGISDynamicMapServiceLayer layers that I am trying to run a simple query task on. The code I am using works in other applications doing the same task with different data.

My problem is, when I load the app (tried both Firefox and Chrome) in a browser, the map itself won't load (indefinite load screen). Console in both browsers shows this error:

ReferenceError: esri is not defined.

Comment #13 on this Esri forum post alludes to the DOM issue, but I need help understanding how to handle the issue. Also, it's possible that the DOM thing is not the issue at all.

So, does anyone have experience with this error? How have you worked around it?

Thanks so much for your input.

UPDATE: This is the code that is actually throwing the error:

var scalebar = new esri.dijit.Scalebar({ map: map, attachTo:"bottom-left" });

Note that I have included the dojo require statement for that class:

dojo.require("esri.dijit.Scalebar");

And if I simply comment out that function, the same undefined error comes with the next esri object class referenced (which also has its appropriate dojo require statement in the doc).

9
  • 6
    Please post code to reproduce the issue. It is almost certainly that you're referencing something in the esri namespace before the API is loaded. Commented Mar 2, 2013 at 1:00
  • Did you require the map module? ``` require(esri/map); ``` or ``` dojo.require(esri.map); ``` Commented Mar 3, 2013 at 18:18
  • @Gautham Yes, the map module is included.
    – Badmagis
    Commented Mar 4, 2013 at 15:19
  • 1
    @Badmagis as shown in all the SDK samples, wrap your JS that uses esri.* classes in a function called by dojo.ready, for instance: help.arcgis.com/en/webapi/javascript/arcgis/jssamples/#sample/… Commented Mar 4, 2013 at 18:16
  • 3
    Not to discourage you, but if you are following any of the hundreds of examples on the arcgis js site re @Derek, you shouldn't need to ask this. Start with working examples -- modify them in small chunks -- revert back when you have problems.
    – awesomo
    Commented Mar 4, 2013 at 18:34

1 Answer 1

4

I've seen that happen if you don't put your JavaScript API code into something like an init function like so:

function (init) {
            map = new esri.Map("map", {
                basemap: "streets"
            });
...
}

dojo.ready(init);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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