javascript - 为什么 Bing Maps 7 AJAX 控件不是延迟加载?

标签 javascript ajax lazy-loading bing-maps bing

我正在尝试将 Bing Maps 7.0 API 与延迟加载结合使用,因为 onScriptLoad 参数似乎支持这一点。我使用了这个最小的测试用例:

<!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 is not a constructor 错误。即使我在通过 setTimeout 调用回调后将 map 创建延迟 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 与延迟加载一起工作?

谢谢。

最佳答案

仅供引用,这个问题终于在最新版本的 Maps API 中得到解决。 这个新版本的一切都按预期工作。

关于javascript - 为什么 Bing Maps 7 AJAX 控件不是延迟加载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4897642/

相关文章:

javascript - 对克隆表单执行操作

javascript - 如何在不重新加载 JSON 更新页面的情况下更新 div 的类和内容

php - GET over POST 对生产有什么好处吗?

c++ - 如何换出内存块?

c# - Entity Framework - 一对多关系的问题

javascript - NodeJS 和 Javascript (requirejs) 依赖注入(inject)

javascript - Jquery 正在添加 prevObject : to array

javascript - 使用 jQuery 获取 DOM 加载后添加的元素的值

jquery - 如何在 Controller 的 “params”对象中识别我的Ajax键/值?

.net - 使用 Ninject 延迟加载