
// 加载百度地图js
const map = {
  init: function () {
    const AK = '7aLLv8GDWaDFLiBlCrctGnq3vTFsHEWf'
    const BMapURL = 'http://api.map.baidu.com/api?v=2.0' + AK + '&s=1&callback=onBMapCallback'
    return new Promise((resolve) => {
      // 如果已加载直接返回
      if (typeof BMap !== 'undefined') {
        resolve(BMap)
        return true
      }
      // 百度地图异步加载回调处理
      window.onBMapCallback = function () {
        // console.log('百度地图脚本初始化成功...')
        resolve(BMap)
      };
      // 插入script脚本
      let scriptNode = document.createElement('script')
      scriptNode.setAttribute('type', 'text/javascript')
      scriptNode.setAttribute('src', BMapURL)
      document.body.appendChild(scriptNode)
    })
  }
}
export default map
