健康同学微信公众号h5项目

123456789101112131415161718192021222324252627282930313233343536373839
  1. export default function MapLoader(isSyncLoad = false, pluginsArr = []) {
  2. // plugin: 字符串数组[ 'AMap.Geocoder', ... ]
  3. return new Promise((resolve, reject) => {
  4. try {
  5. if (window.AMap && (pluginsArr === null || pluginsArr === undefined || pluginsArr.length === 0)) {
  6. resolve(window.AMap);
  7. } else {
  8. var script = document.createElement('script');
  9. script.type = 'text/javascript';
  10. script.async = !isSyncLoad;
  11. script.src =
  12. 'https://webapi.amap.com/maps?v=1.4.15&callback=initAMap&key=' +
  13. '6e4a6c39ea6d18b8dd3151baa3a7c0d5' +
  14. '&plugin=AMap.BezierCurveEditor' +
  15. (pluginsArr ? ',' + pluginsArr.join(',') : '');
  16. script.onerror = reject;
  17. document.head.appendChild(script);
  18. var script1 = document.createElement('script');
  19. script1.type = 'text/javascript';
  20. script1.async = false;
  21. script1.src = 'https://webapi.amap.com/ui/1.0/main.js?v=1.0.11';
  22. script1.onerror = reject;
  23. if (isSyncLoad) {
  24. document.head.appendChild(script1);
  25. }
  26. }
  27. window.initAMap = () => {
  28. resolve(window.AMap);
  29. };
  30. // JSAPI key搭配静态安全密钥以明文设置, 详情见: https://lbs.amap.com/api/jsapi-v2/guide/abc/load
  31. window._AMapSecurityConfig = {
  32. securityJsCode: '6a421e1233cd12dd4899e373e11bb641'
  33. };
  34. } catch (e) {
  35. console.log(e);
  36. }
  37. });
  38. }