Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ArcGis 3.5 issue with Requirejs

I am using ArcGIS 3.5 Javascript API and RequireJS

I implemented it using this code:

<script>
  var map;
  require(["esri/map", "dojo/domReady!"], function(Map) {
     map = new Map("mapDiv", {
      center: [-96.571541, 39.155622],
      zoom: 3,
      basemap: "streets"
     });
   });
  });
</script>

with this RequireJS Configuration :

requirejs.config({
    baseUrl: "js/",
    paths: {
        underscore: 'libs/underscore',
        tpl: 'tpl',
        backbone: 'libs/backbone',
        text: 'libs/text',
        domReady: 'libs/domReady'
    },
    packages: [
               {
                   name: 'dojo',
                   location: "http://serverapi.arcgisonline.com/jsapi/arcgis/3.5compact/js/dojo/dojo/"
               },
               {
                   name: 'dojox',
                   location: "http://serverapi.arcgisonline.com/jsapi/arcgis/3.5compact/js/dojo/dojox"
               },
               {
                   name: 'dijit',
                   location: "http://serverapi.arcgisonline.com/jsapi/arcgis/3.5compact/js/dojo/dijit"
               },
               {
                   name: 'esri',
                   location: "http://serverapi.arcgisonline.com/jsapi/arcgis/3.5compact/js/esri"
               }
           ],
    shim: {
        'backbone': {
            //These script dependencies should be loaded before loading backbone.js
            deps: ['underscore'],
            //Once loaded, use the global 'Backbone' as the module value.
            exports: 'Backbone'
        },
        'underscore': {
            exports: '_'
        }
    }
});

And It displays the following error:

I have this error

**Uncaught TypeError: Object function (){} has no method 'add' has.js:8

Uncaught Error: Load timeout for modules: dojo/domReady!_unnormalized2,dojo/has!dom-addeventlistener?:./aspect_unnormalized3,dojo/i18n!dojo/cldr/nls/number_unnormalized4,dojo/i18n!dojo/cldr/nls/gregorian_unnormalized5,dojo/i18n!esri/nls/jsapi_unnormalized6,dojox/gfx/renderer!_unnormalized7,dojo/selector/_loader!default_unnormalized8,dojo/has!host-browser?dom-addeventlistener?:../on:_unnormalized9**

Does any one have an explanation, or an idea about how to solve it?

like image 728
Slim Tekaya Avatar asked Oct 10 '13 08:10

Slim Tekaya


1 Answers

The ArcGIS Javascript API automatically loads the Dojo framework which defines it's own AMD loader. Here, it's attempting to use RequireJs's loader as it doesn't replace the functions if they already exist. However, the Dojo implementation has a few non-standard methods attached to some of its functions (such as 'has' in this example, I think 'add' might be another someone's posted), which dojo's modules use internally. This means that for dojo to function, you are currently required to use Dojo's loader. As a side effect of this, ArcGIS JS API is incompatible with RequireJs currently.

http://requirejs.org/docs/dojo.html has a bit of information from RequireJs (although the linked ticket is misleading as it being 'fixed' refers to that specific code block, and not the framework-wide problem).

Using requirejs with dojo 1.9.1 is a similar problem. They seem to have solved it by using the Source/SDK version of Dojo, but I think this is impossible when working with ArcGIS Javascript API.

This should resolve itself with future dojo/ArcGIS JS releases.

like image 196
Matt Bright Avatar answered Sep 28 '22 01:09

Matt Bright