There is such an incomprehensible thing: Here is the script:
function buildMap(lat,lon,level) { var map = new GMap2(document.getElementById("map")); map.addControl(new GLargeMapControl()); map.addControl(new GMapTypeControl()); map.setCenter(new GLatLng(lat, lon), level); map.addControl(new GSmallMapControl()); map.addControl(new GMapTypeControl()); }
Actually - the task is to make the object var map = new GMap2 (document.getElementById ("map")); that is, the map was global and could be called from any function in the script.
I tried to do this:
var map = new GMap2(document.getElementById("map")); function buildMap(lat,lon,level) { map.addControl(new GLargeMapControl()); map.addControl(new GMapTypeControl()); map.setCenter(new GLatLng(lat, lon), level); map.addControl(new GSmallMapControl()); map.addControl(new GMapTypeControl()); }
But then the problem arises that when you call the function "buildMap ()" this variable is not visible .... and even hurt yourself in the post with your head. Does not want to work and that's it.
After that, I decided to test my brain for the correctness of judgments. Made a simple script:
var test = "123"; function show_test(){ alert(test); }
As a result, I see in the Alert the value of the variable "test". Those. this proves that, in this case, the variable is not empty => "var map = ..." outside the limits of the function, also had to initialize normally into the function and work through it normally.
Question !!!!
What a joke :)