async loadBMap() {
if (!window.Bmap) {
let urls = [
'http://api.map.baidu.com/api?v=3.0&ak=key&callback=onBMapCallback',
'http://api.map.baidu.com/library/LuShu/1.2/src/LuShu_min.js',
'http://api.map.baidu.com/library/AreaRestriction/1.2/src/AreaRestriction_min.js'
];
for (let i = 0; i < urls.length; i++) {
await new Promise((res, rej) => {
let script = document.createElement('script');
script.src = urls[i];
if (i === 1) {
window.onBMapCallback = () => {
res();
};
} else {
script.onload = () => {
res();
};
}
script.onerror = rej;
document.head.appendChild(script);
});
}
}
}
网友评论