cadrin

esri is not defined inside JavaScript class

Discussion created by cadrin on Mar 11, 2013
Hi guys,

i'm trying to build my web map with an javascript class, but it seems that the dojo.require("esri.map"); can't be called inside a class.

here is my javascript code:

dojo.require("dojo.fx");

dojo.require("esri.map");


/*
 * Objet Mapper
 */
var Mapper = function()
{
 // public variables
 this.map;
 
 // private variables
 
 
 // public functions
 this.init = init;
 this.initMap = initMap;
 this.buildDivs = buildDivs;
 
 function init()
 {
  console.log("init");
  
        buildDivs();
     
     dojo.ready(initMap());
 }
 
 function initMap()
 {
  this.map = new esri.Map("map",{
            basemap:"topo",
            center:[-122.45,37.75], //long, lat
            zoom:13,
            sliderStyle:"small"
         });
 }
 
 function buildDivs()
 {
  div_main = $('#main');
  div_map = $('<div id="map"></div>');
  div_main.append(div_map);
 } 
 
}


and inside my index.html I am calling the class when the document is ready:
<html>
 <head>
  <!-- TITRE -->
  <title>Cartographie 2.0</title>
 
  <!-- FORMATAGE -->
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  
  <!-- DOCTYPE -->
  <!DOCTYPE html>
 
  <!-- XHTML -->
  <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
 
  <!-- CSS -->
  <link rel="stylesheet" href="css/interface.css" type="text/css">
 
  <!-- JAVASCRIPT -->
  
  <script type="text/javascript" src="js/jquery-1.9.1.min.js" ></script>
  <script type="text/javascript" src="js/jquery-ui-1.10.1.custom.min.js" ></script>
  <script type="text/javascript" src="js/mapper.js" ></script>
  <script src="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3/"></script>
  <script type="text/javascript">
   var oMapper = new Mapper();
  
      $(document).ready(function()
      {
       oMapper.init();
       console.dir(initMap());
   });
   
  </script>
 
 </head>
 <body>
  <div id="main" class="container">
  </div>
 </body>
</html>



The error I get from FireBug is: ReferenceError: esri is not defined ( var tmp = new esri.Map("map",{ ...)

Outcomes