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

发布于 2024-10-16 06:20:50 字数 2271 浏览 8 评论 0原文

我正在尝试将 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 调用回调后将地图创建延迟 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 使用延迟加载吗?

谢谢。

I'm trying to use Bing Maps 7.0 API with Lazy Loading, as this seem to be supported with the onScriptLoad parameter. I used this minimal test case:

<!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>

The callback is called as expected, but Firebug throws me an Microsoft.Maps.Map is not a constructor error. This even if I delay the map creation by 10 seconds after the callback is called via setTimeout.

The simple example in Bing docs, however, is working perfectly:

<!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>

Has anybody succeeded in getting the API 7.0 to work with lazy loading?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

删除→记忆 2024-10-23 06:20:50

仅供参考,这个问题终于在最新版本的 Maps API 中得到了解决。
在这个新版本中,一切都按预期进行。

FYI, this issue has finally been fixed in the newest release of the Maps API.
Everything is working as expected with this new version.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文