Select to view content in your preferred language

Getting a reference to a map object with dojo.byId

1180
2
11-29-2012 07:41 AM
JosephCox
Occasional Contributor
I was wondering if there is a method to get a reference to the map object without having to have a global variable for the map. If you do: var x = dojo.byId("map") x is a reference to the DIV that contains the map but I don't know how to pull the map out of that, or if I should even be trying to reference the map in this way.
0 Kudos
2 Replies
MattO_Hara
Emerging Contributor
I'm by no means a dojo expert but I don't believe it is possible to get the JavaScript object from the HTML element. The JavaScript map object contains a link to the HTML element that the map is in but the reverse is not true.

I've always just used a global variable called map in order to access it.
0 Kudos
derekswingley1
Deactivated User
We don't keep a reference to the map as a global variable anywhere. If you want to interact with your map at runtime via your browser's dev tools, make your map variable global. This is why we make the map a global var in most of our samples.

As you found out, dojo.byId returns references to dom nodes. Dijit.byId returns references to dijits but esri.Map is not a dijit.