1

I'm maintaining some code that involves the mapquest map API. There's a javascript init() function which has this line:

map = new MQA.TileMap(document.getElementById('map'),6,{lat:34, lng:-118},'hyb'); 

which sets up the map in a down the page with the id of 'map', as per the API.

My problem is that I want to be able to access this map from outside this function, but I can't seem to find anything in the mapquest API about getting the map object from the div it's contained in. Trying to call map-related methods on the result of document.getElementById("map") just doesn't work.

Tneuktippa
  • 1,645
  • 3
  • 15
  • 25

1 Answers1

0

Sounds like you would use the global variable map to reference it.

var map;
function setUp(){
    map = new MQA.TileMap(document.getElementById('map'),6,{lat:34, lng:-118},'hyb');
}

function doSomething(){
    if(!map) return;
    map.XXX();  //where XXX is the method you want to call
}
epascarello
  • 204,599
  • 20
  • 195
  • 236
  • Bah, I really should know by now how scope in javascript works. Of course that makes sense. Thanks. – Tneuktippa Jun 24 '11 at 18:24
  • I actually created a global var with window.map. But whenever I try to getShapeCollection() it's empty. Even though there are POIs on the map. can you help me with that? I also can't wipe the old POIs on a new query with map.removeShapeCollection(); – keinabel Nov 14 '13 at 16:54