2.8 to 3.1 breaks my site?

1330
7
Jump to solution
08-07-2012 11:00 AM
StevenGriffith
New Contributor III
Just switched from the v2.8 api to v3.1 and I'm now getting lots of "Uncaught Reference Error: esri is not defined" errors. What happened to the esri object?

Steve G
County of SLO
0 Kudos
1 Solution

Accepted Solutions
derekswingley1
Frequent Contributor
Basically, do not reference anything in the esri namespace until all modules are loaded. Which means waiting dojo.addOnLoad or dojo.ready to fire.

View solution in original post

0 Kudos
7 Replies
JohnGravois
Frequent Contributor
Because of some changes in Dojo 1.7, (used in our Javascript API version 3.x) it is now possible that code outside an initialization function which instantiate classes can fire before the supporting modules are available.

You can still use global variables, but if you are instantiating classes immediately, try moving the code inside init (or similar)

var queryTask;

      function init() {
        //build query
        queryTask = new esri.tasks.QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5");
        //dojo.connect(queryTask, "onComplete", showResults);

instead of
var queryTask;
queryTask = new esri.tasks.QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5");
      function init() {
        //build query
        dojo.connect(queryTask, "onComplete", showResults);
0 Kudos
derekswingley1
Frequent Contributor
Basically, do not reference anything in the esri namespace until all modules are loaded. Which means waiting dojo.addOnLoad or dojo.ready to fire.
0 Kudos
StephenLead
Regular Contributor III
Basically, do not reference anything in the esri namespace until all modules are loaded. Which means waiting dojo.addOnLoad or dojo.ready to fire.


Hi Derek,

How would we handle this in the case of a custom module which internally references the esri namespace?

An example is on the Public Information Map, which includes the heatlayer module in the index.html page:

<script type="text/javascript" src="js/heatlayer.js"></script>


This contains a reference to the esri namespace:

dojo.declare("HeatmapLayer", [esri.layers.DynamicMapServiceLayer], {


What's the best way to migrate an application like this to 3.1?

Thanks,
Steve
0 Kudos
AndyStewart1
New Contributor III
Over at http://help.arcgis.com/en/webapi/javascript/arcgis/help/jshelp/inside_dojoversion.html, it explains that from 3.0 onward, the option to rename the namespace is no longer available. 

So what are my options if I need 3.0 or later of the ArcGIS API, but have a conflict between 1.7 and another version of Dojo that is used on the application where my GIS app is embedded?  Do I have any options?
0 Kudos
ReneRubalcava
Frequent Contributor
It looks like scopemap won't work anymore, but according to Dojo docs you should be able to load custom namespaces for different dojo libraries to work with packages you define. Granted, I have not tried this, but could be worth investigating if you need to maintain some legacy compatibility.
http://dojotoolkit.org/reference-guide/1.7/loader/amd.html#relocating-module-namespaces
0 Kudos
derekswingley1
Frequent Contributor

How would we handle this in the case of a custom module which internally references the esri namespace?


I didn't see this when it was initially posted... The way to handle this is to not include Dojo modules via a script tage and instead use dojoConfig to tell the loader where to find the module. The point clustering sample shows how to use dojoConfig.packages to point to the location of a custom module.
0 Kudos
AndyStewart1
New Contributor III
It looks like scopemap won't work anymore, but according to Dojo docs you should be able to load custom namespaces for different dojo libraries to work with packages you define. Granted, I have not tried this, but could be worth investigating if you need to maintain some legacy compatibility.
http://dojotoolkit.org/reference-guide/1.7/loader/amd.html#relocating-module-namespaces


We tried this approach but were unsuccessful on first attempt.  Will have to try again. 

Our issue is we have an GIS solution that is a third party app embedded in a customer's J2EE application. The customer's app runs a version of Dojo earlier than 1.7. But we need the ESRI Javascript API 3.0, but that version of Dojo conflicts with our customer's app in some specific ways.

Is there no version of the ArcGIS JavaScript API that we could download that doesn't include Dojo?
0 Kudos