export default function MapLoader(isSyncLoad = false, pluginsArr = []) {
  // plugin: 字符串数组[ 'AMap.Geocoder', ... ]
  return new Promise((resolve, reject) => {
    try {
      if (window.AMap && (pluginsArr === null || pluginsArr === undefined || pluginsArr.length === 0)) {
        resolve(window.AMap);
      } else {
        var script = document.createElement('script');
        script.type = 'text/javascript';
        script.async = !isSyncLoad;
        script.src =
          'https://webapi.amap.com/maps?v=1.4.15&callback=initAMap&key=' +
          '6e4a6c39ea6d18b8dd3151baa3a7c0d5' +
          '&plugin=AMap.BezierCurveEditor' +
          (pluginsArr ? ',' + pluginsArr.join(',') : '');
        script.onerror = reject;
        document.head.appendChild(script);

        var script1 = document.createElement('script');
        script1.type = 'text/javascript';
        script1.async = false;
        script1.src = 'https://webapi.amap.com/ui/1.0/main.js?v=1.0.11';
        script1.onerror = reject;
        if (isSyncLoad) {
          document.head.appendChild(script1);
        }
      }
      window.initAMap = () => {
        resolve(window.AMap);
      };
      // JSAPI key搭配静态安全密钥以明文设置, 详情见: https://lbs.amap.com/api/jsapi-v2/guide/abc/load
      window._AMapSecurityConfig = {
        securityJsCode: '6a421e1233cd12dd4899e373e11bb641'
      };
    } catch (e) {
      console.log(e);
    }
  });
}
