2

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?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jun 5, 2014 at 22:56

3 Answers 3

2

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()

answered Jun 5, 2014 at 23:11
1

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(...);
answered Jun 5, 2014 at 23:33
1
  • I ended up just using map = new Map() instead of var map = new Map(). Making it global seemed to do the trick. Commented Jun 10, 2014 at 3:48
0

On Web Appbuilder created apps a global variable window._viewerMap is created by MapManager.js -> _publishMapEvent

I have not tested this on other JSAPI applications.

answered Feb 25, 2016 at 12:23

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.