bokeefe

(How To) Reference the MAP Object post-creation

Discussion created by bokeefe on Apr 2, 2014
Latest reply on Apr 2, 2014 by JUihlein-esristaff
I'm trying to figure out how to modularize the mapping process. I would prefer to break my code out into multiple pieces for ease of maintenance and upgrades. So I want to put the 'Map Initialization / Creation' process in it's own file. I think it would be great to avoid Global variables as well.

So, rather than create a global variable ('map') and pass it around, since I know that I assign the MAP object to a div with the id of 'mapDIV' is there any way to just reference the map object through the DOM?

Here is my map creating file...

<!DOCTYPE html>
<html>
 <head>
  <title>Create a Map</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
  <link rel="stylesheet" href="http://js.arcgis.com/3.8/js/dojo/dijit/themes/claro/claro.css">
  <link rel="stylesheet" href="http://js.arcgis.com/3.8/js/esri/css/esri.css">
  <style>
   html, body, #mapDiv
   {
    padding: 0;
    margin: 0;
    height: 100%;
   }
  </style>
  <script src="http://js.arcgis.com/3.8/"></script>
  <script>
   require
   (
    ["esri/map", "dojo/domReady!"],
    function(Map)
    {
     new Map
     (
      "mapDiv",
      {
       center: [-95.989658, 36.155520],
       zoom: 13,
       basemap: "gray",
       sliderStyle: "small"
      }
     );
    }
   );
  </script>
 </head>
 <body class="claro">
  <div id="mapDiv"></div>
 </body>
</html>


You can see that I don't even utilize a map variable at all.

Outcomes