Preloading message for VE JavaScript

This Page is locked
Modified: 2007/09/06 22:44 by ViaVE Visitor
The Virtual Earth JavaScript is big (XXKB). Microsoft have done the following to reduce the size and speed it up:
  • JavaScript optimisation
  • TODO: add more

If you want to load your page, display a loading message and then start downloading the file:

  • Don’t include the JavaScript link in your header!


<html>
   <head>
      <title></title>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <script>
         var map = null;
         var le = 0;
         function GetMap()
         {
   		var head = document.getElementsByTagName("head")[0];
   		var s = document.createElement('script');
   		s.id = 'VEScript';
   		s.type = 'text/javascript';
   		s.src = "http://local.live.com/veapi.asjx";
   		head.appendChild(s);
   		DelayGetMap();
         }   
         function DelayGetMap()
         {
                try {
                        map = new VEMap('myMap');
                        document.getElementById("myLoading").style.display = "none";
                        document.getElementById("myMap").style.display = "block";
                        map.LoadMap(new VELatLong(47.6, -122.33), 10 ,'h' ,false);
                }catch(err)
                {
                        if (le < 30)
                        {
                                le++;
                                setTimeout("DelayGetMap()",1000);
                        }else
                        {
                                alert("Site is busy.");
                        }
                }   
         }   

</script> </head> <body onload="GetMap();"> <div id='myMap' style="position:relative; width:400px; height:400px;display:none;"></div> <div id='myLoading' style="position:relative; width:400px; height:400px;">Loading...</div> </body> </html>


NOTE:
"http://local.live.com/veapi.asjx" will fetch the latest version. It maybe more appropriate to reference the specific version you have built against:
V3 - http://maps.live.com/veapi.ashx?v=1.3.0908172755.52
V4 - http://maps.live.com/veapi.ashx?v=1.3.1115150037.31