import AMapLoader from '@amap/amap-jsapi-loader';

export function amapInit() {
  return new Promise((resolve, reject) => {

    window._AMapSecurityConfig = {
      securityJsCode: AMAP_SEC_CODE,  // 来源 public/config.js
    };
    AMapLoader.load({
      "key": AMAP_KEY,  // 来源 public/config.js
      "version": "2.0",
      "plugins": [],
    }).then((AMap)=>{
      window.AMap = AMap;
      resolve(AMap);
    }).catch((e)=>{
      console.error(e);  //加载错误提示
      reject(e);
    });
  })
}

export function newMarker(options = {}) {
  return new AMap.Marker({
    content: '<div class="cust-map-marker"></div>',  // 自定义点标记覆盖物内容
    offset: new AMap.Pixel(-30, -10), // 相对于基点的偏移位置
    ...options
  });
}
