简体   繁体   中英

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:

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

Using the callback function is really simply an only adds 1 extra line of code to your application which consists of "});".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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