[GIS] Loading custom dojo and Esri

arcgis-javascript-apiarcgis-serverdojo

We have to develop an application which will have lot of rich ui along with a map. For the map, I am using the arcgis javascript api which includes dojo. For UI components other than the map, I want to use a copy of dojo which I will host locally. How can I load both of these?
I read this blog esri dojo, but this works with api 1.6, and I am using 3.6.

Best Answer

To load your custom UI tools along with ESRI's version of Dojo, you'll need to add the name and location of your custom package to the dojoConfig object in the script. Just before you load ESRI's JavaScript API in the head of document, set your dojoConfig similar to the following

<script type="text/javascript">
  dojoConfig = {
    async: true,
    packages: [
      {
        name: "customUI",
        location: "/js/customUI" // or wherever you keep your custom code
      }
    ]
  };
</script>
<script src="http://js.arcgis.com/3.6/"></script>

Then, later, you can call it in a require or define statement.

require(["customUI/DrawingTool", "esri/map", "dojo/ready"],
  function (DrawingTool, Map, ready) {
    ready(function () {
       var map = new Map("mapdiv", {});
       var myDrawingTool = new DrawingTool({ map: map});
       // do whatever with it.
    });
  }
);

Here's some reading to help you set it up properly:

  1. Defining Modules in Dojo (1.8)
  2. Loading custom modules while using Dojo CDN (via StackOverflow)
  3. How does package location work in Dojo (via StackOverflow)