Select to view content in your preferred language

Custom dojo and dojox/gfx/createSurface.xd.js not found

2305
11
11-04-2011 05:04 AM
RafaelCoutinho
New Contributor
For some reason i get this error when opening the map using custom dojo (ersiDojo):

"NetworkError: 404 Not Found - http://serverapi.arcgisonline.com/jsapi/arcgis/2.5/js/dojo/dojox/gfx/createSurface.xd.js"
create...e.xd.js
uncaught exception: Could not load cross-domain resources: dojox.gfx.createSurface

Not sure why but there's something related with my dojo version... Does any had anything like that
0 Kudos
11 Replies
RyanMuller
Occasional Contributor
I get this error as well. and I'm using the djconfig object to configure custom namespaces so that my custom version of dojo 1.7 is loaded first and then the esri api is loaded in the custom namespace.

<script type="text/javascript" src="js/libs/dojo/dojo/dojo.js"></script> <!--version 1.7.1 of the dojo framework is loaded first -->
<script type="text/javascript">
<!--then I remap the dojo namespace so that when the arcgis library is loaded it's functions can be called using esridojo instead of dojo -->
  djConfig = {
    scopeMap: [
      [ "dojo", "esridojo" ],
      [ "dijit", "esridijit" ],
      [ "dojox", "esridojox" ]
    ]
  };
</script>
<script type="text/javascript" src="http://tiney-pie/cma/staging/prototype/js/libs/arcgis_js_api/2.6/"></script>


I think that this type of remapping the dojo namespace is not really supported. I'll likely just revert to using the dojo library that's bundled with the JSAPI.

Does anyone have a workaround for this? I should mention that I only get this error about 20% of the time.
0 Kudos
MattMoyles
Occasional Contributor
The renaming of the dojo namespace is not really supported. I have not been successfull with it. scopeMap is deprecated in dojo 2.0 anyway.
0 Kudos
RyanMuller
Occasional Contributor
Thanks Matt. This is unfortunate as dojo 1.7 has a lot of functionality and bug fixes that I would like to use. It's good to know that it's not just me that's having problems though.
0 Kudos
derekswingley1
Deactivated User
This is supported, and we publish a sample to show how to do it:  http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples/mapconfig_customdojo.html

That being said, I haven't tried this with 1.7. Since 1.7 introduces a new loader, there might be issues. I'll try to take a look and see if I can get it to work.

Edit:  This simple example works with version 2.7 of our API (uses dojo 1.6.1) and dojo 1.7.1 from the Google CDN:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9" />
    <!--The viewport meta tag is used to improve the presentation and behavior of the samples 
      on iOS devices-->
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
    <title>Custom Dojo Namespace</title>
    <!-- Load Dojo 1.7.1 from Google CDN -->
    <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.7.1/dojo/dojo.js"></script>
    <!-- local version also works... -->
    <!-- <script type="text/javascript" src="/~dswingley/dojosrc/1.7.1/dojo/dojo.js" ></script>  -->
    <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.7/js/dojo/dijit/themes/claro/claro.css">
    <script type="text/javascript">
     djConfig = {
        scopeMap: [
          [ "dojo", "esriDojo" ],
          [ "dijit", "esriDijit" ],
          [ "dojox", "esriDojox" ]
        ]
      };
    </script>
    <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.7"></script>

    <script type="text/javascript">
     // Dojo library from Google CDN is built in such a way that
      // it depends on the djConfig global object when loading modules. 
      // But we override it later when loading the JSAPI.
      // Reset it here so that modules from Google CDN are loaded
      // properly. 
      // For example: after the page loads, try loading the following
      // module:
      // dojo.require("dijit.layout.ContentPane");
      // and observe firebug net tab. You should see bunch of modules
      // loaded from Google CDN. Without the reset below, the first module
      // loaded will be from Google CDN and its dependencies loaded from 
      // the dojo instance embedded within JSAPI.
      djConfig = dojo.config;
      esriDojo.require("esri.map");
      dojo.require("dijit.layout.ContentPane");

      function init() {        
       var extent = new esri.geometry.Extent(-122.93,47.02,-122.86,47.07, new esri.SpatialReference({wkid:4326}));
        var map = new esri.Map("map", {extent:esri.geometry.geographicToWebMercator(extent)});
        var tiledMapServiceLayer = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer");
        map.addLayer(tiledMapServiceLayer);
        
        esriDojo.connect(map,"onLoad",function(map){
          var esriVersion = "<b>ArcGIS API for JavaScript version:</b>" + esri.version;
          var esriDojoVersion = "<b>ArcGIS API for JavaScript Dojo version:</b>" + esriDojo.version;
          esriDojo.byId('esriInfo').innerHTML= esriVersion + "<br />" + esriDojoVersion;
        });
      }
      function initDojo(){
        dojo.byId('dojoInfo').innerHTML="<b>Google CDN Dojo Version:</b>" + dojo.version;
      }
      dojo.addOnLoad(initDojo);
      esriDojo.addOnLoad(init);
    </script>

  </head>

  <body class="claro">
  The following libraries are loaded in this application:<br />
    <div id="map" style="margin:2px 2px 2px 2px; border:solid thin #999967;width:500px;height:500px;"> </div>
    <span id="esriInfo"></span><br />
    <span id="dojoInfo"></span>
    </div>
  </body>
</html>
0 Kudos
derekswingley1
Deactivated User
This is unfortunate as dojo 1.7 has a lot of functionality and bug fixes that I would like to use. It's good to know that it's not just me that's having problems though.


Can you post more of your code? Do you see the error you mentioned even when you don't load dojo 1.7.1 but still rename the dojo namespace?
0 Kudos
MattMoyles
Occasional Contributor
This is supported, and we publish a sample to show how to do it:  http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples/mapconfig_customdojo.html

That being said, I haven't tried this with 1.7. Since 1.7 introduces a new loaded, there might be issues. I'll try to take a look and see if I can get it to work.


Even if you can manage to hack it together and get it to work I don't think it's a good idea.  You'll be loading many libraries twice. Esri Dojo 1.6.1 stuff to support their widgets and then whatever 1.7 stuff you load yourself. So you might be loading 2 dijit.form.Textbox or whatever else. If it's a smaller app then it's prob not a problem. If you are doing a larger app the double loading will kill your browser twice as fast, and you will see the dreaded 'script is too large' in your Firebug console.
0 Kudos
derekswingley1
Deactivated User
Even if you can manage to hack it together and get it to work I don't think it's a good idea.  You'll be loading many libraries twice. Esri Dojo 1.6.1 stuff to support their widgets and then whatever 1.7 stuff you load yourself. So you might be loading 2 dijit.form.Textbox or whatever else. If it's a smaller app then it's prob not a problem. If you are doing a larger app the double loading will kill your browser twice as fast, and you will see the dreaded 'script is too large' in your Firebug console.


You might end up loading modules from dojo's base twice, but unless you dojo.require("dijit.something") and esridojo.require("dijit.something"), you shouldn't be loading additional modules twice. Taking it one step further, and this might be more trouble than it's worth, if you use dojo 1.7's AMD loader, you have to explicitly load everything so you could avoid duplicating modules in dojo base. You would only explicitly require() what you need and duplication would be minimal.
0 Kudos
RyanMuller
Occasional Contributor
Can you post more of your code? Do you see the error you mentioned even when you don't load dojo 1.7.1 but still rename the dojo namespace?


I was using JSAPI 2.6 and dojo 1.7.1 both hosted locally. One thing I did not do was to reset the djconfig like you did in your example.

I will upgrade to 2.7 and reset djconfig and report back.
0 Kudos
MattMoyles
Occasional Contributor
You might end up loading modules from dojo's base twice, but unless you dojo.require("dijit.something") and esridojo.require("dijit.something"), you shouldn't be loading additional modules twice. Taking it one step further, and this might be more trouble than it's worth, if you use dojo 1.7's AMD loader, you have to explicitly load everything so you could avoid duplicating modules in dojo base. You would only explicitly require() what you need and duplication would be minimal.


I don't know about that. Sounds like a good way for a programmer to go bald. And I think it would be a nightmare to maintain.
0 Kudos