为什么Bing Maps 7 AJAX控件没有惰性加载?

4
我正在尝试使用支持onScriptLoad参数的Lazy Loading的Bing Maps 7.0 API。我使用了这个最小化测试用例:
<!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>

回调函数按预期被调用,但是Firebug会抛出一个“Microsoft.Maps.Map不是构造函数”的错误。即使我使用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与延迟加载结合使用了吗?
谢谢。
1个回答

0

请注意,这个问题已经在最新版本的地图API中得到了修复。 使用这个新版本,一切都按照预期工作。


太好了 :) 现在,如果他们能把其他功能也加回来,我就终于可以在客户项目中摆脱6.3。 - wildpeaks

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接