2011-02-04 67 views
4

我試圖在Lazy Loading中使用Bing Maps 7.0 API,因爲這似乎是通過onScriptLoad參數來支持的。我用這個最小的測試案例:Bing地圖7 AJAX控件爲什麼不是延遲加載?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <title>Bing Maps Test</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
</head> 
<body> 
    <div id='mapDiv' style="position:absolute; width:600px; height:400px;"></div> 
    <script type="text/javascript"> 

     function initMap() { 
      console.log('Callback called'); 
      var map = new Microsoft.Maps.Map(document.getElementById("mapDiv"), {credentials:"<API KEY>"}); 
     } 

     function loadMapControl() 
     { 
      var script = document.createElement("script"); 
      script.setAttribute("src", "http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0&onScriptLoad=initMap"); 
      script.setAttribute("type", "text/javascript"); 
      document.documentElement.firstChild.appendChild(script); 
      console.log('Tag appened'); 
     } 
     setTimeout(loadMapControl, 1000); 

    </script> 
</body> 
</html> 

如預期回調被調用,但螢火蟲拋出我的Microsoft.Maps.Map is not a constructor錯誤。即使我在通過setTimeout調用回調後10秒鐘將地圖創建延遲了。

在Bing文檔的簡單的例子,但是,可以正常使用:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <title>Bing Maps Test</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
    <script charset="UTF-8" type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script> 
</head> 
<body> 
    <div id='mapDiv' style="position:absolute; width:600px; height:400px;"></div> 
    <script type="text/javascript"> 
     var map = new Microsoft.Maps.Map(document.getElementById("mapDiv"), {credentials:",API KEY>"}); 
    </script> 
</body> 
</html> 

有沒有人成功地讓API 7.0懶加載工作?

謝謝。

回答

0

僅供參考,此問題最終在Maps API的最新版本中得到修復。 一切工作如預期與這個新版本。

+0

好:)現在,如果他們可以添加其他功能回來,我也可以在客戶項目中擺脫6.3 – wildpeaks 2011-03-07 11:04:42