Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

So I am currently writing an application using the ArcGIS JavaScript API, and I want to access the map object that is held inside of my div from a js module I have. I was thinking it would be a simple JQuery call but it doesn't seem to be the case, as when I try to use map.centerAndZoom(), it states that it is not a member of the object that returned by that call.

Is there anyway to be able to reference the map object that was created in my main index.html elsewhere?

share|improve this question

2 Answers 2

I'm not an expert on this, so this may not be best-practise - I'll defer to more expert programmers to come up with a better approach.

But what I usually do is create a single global JSON object and hitch everything off this. eg:

var myObject = {};
myObject.map = new Map("map", {.....});
myObject.layers = {.....};

You can access this object using window.myObject:

window.myObject.map.centerAndZoom(...);
share|improve this answer
    
I ended up just using map = new Map() instead of var map = new Map(). Making it global seemed to do the trick. –  Logan Lehman Jun 10 at 3:48
up vote 0 down vote accepted

After further research, I don't believe it is possible. Instead, I created a global variable to access the map that way.

map = new Map()

instead of

var map = new Map()

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.