// 异步加载高德地图API
// https://webapi.aMap.com/maps?v=1.4.15&key=908147cba89a3a4f1bc9e3627699ed25&callback=onLoad
export function loadMP() {
    const mp = new Promise(function(resolve, reject) {
        const hasLoaded1 = document.getElementById('amap')
        if (hasLoaded1) { // 只加载一次
            return
        }
        window.init = function() {
            resolve(AMap)
        }
        const script = document.createElement('script')
        script.type = 'text/javascript'
        script.src = '//webapi.amap.com/maps?v=1.4.6&key=908147cba89a3a4f1bc9e3627699ed25&callback=init'
        script.id = 'amap'
        script.onerror = reject
        document.head.appendChild(script)
    })
    const mpUI = new Promise(function(resolve, reject) {
        const hasLoaded2 = document.getElementById('amapUI')
        if (hasLoaded2) { // 只加载一次
            return
        }
        const script2 = document.createElement('script')
        script2.type = 'text/javascript'
        script2.src = '//webapi.amap.com/ui/1.0/main.js'
        script2.id = 'amapUI'
        script2.onerror = reject
        script2.onload = function(su) {
            resolve(AMapUI)
        }
        document.head.appendChild(script2)
    })
    return Promise.all([mp, mpUI])
        .then(function(result) {
            return result
        }).catch(e => {
            console.log(e)
        })
}
