简体   繁体   English

是否可以同步加载Bing Maps模块?

[英]Is it possible to load Bing Maps modules synchronously?

I have the following code in my page that loads the BingMap followed by a BingMap module asynchronously: 我的页面中有以下代码,该代码异步加载BingMap和BingMap模块:

var MM = window.Microsoft.Maps;
var _map = new MM.Map(
MM.registerModule('HtmlPushpinLayerModule', '/include/js/mapsearch/HtmlPushpinLayerModule.js');
MM.loadModule('HtmlPushpinLayerModule', function loadHtmlPushpinLayer() {
    // do all sorts of things on the map.       
});

Is there anyway to load the module synchronously? 无论如何有同步加载模块吗?

There is nothing that can be done until the module is loaded anyway, so it doesn't make sense for it to be async. 在加载模块之前,什么也做不了,所以异步是没有意义的。 And there are so many indirections in the code already, I don't want to add anymore. 而且代码中已经有很多间接,我不想再添加了。

No, modules have to load asynchronously, they are downloaded via AJAX, thus it is asynchronous. 不,模块必须异步加载,它们是通过AJAX下载的,因此是异步的。 The ajax call could be forced to be synchronous, but that would mean all UI would be frozen until the module is loaded which would be a poor user experience. Ajax调用可能被强制同步,但这将意味着将冻结所有UI,直到加载模块为止,这将带来糟糕的用户体验。

Using the callback function is really simply an only adds 1 extra line of code to your application which consists of "});". 使用回调函数实际上只是一个简单的操作,仅向您的应用程序增加了1行代码,其中包括“});”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM