(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>
  <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="">
  <link rel="stylesheet" href="">
   html, body, #mapDiv
    padding: 0;
    margin: 0;
    height: 100%;
  <script src=""></script>
    ["esri/map", "dojo/domReady!"],
     new Map
       center: [-95.989658, 36.155520],
       zoom: 13,
       basemap: "gray",
       sliderStyle: "small"
 <body class="claro">
  <div id="mapDiv"></div>

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