export class MapCustom {
  drawResolve = null;
  constructor(data) {
    this.map = new AMap.Map(data.dom, {
      version: "1.4.15",
      zoom: 13,
      center: [116.397428, 39.90923], //初始化地图中心点
      ...data,
    });
  }
  draw() {
    return new Promise((resolve) => {
      this.drawResolve = resolve;
      this.map.clearMap();
      let list = [];
      let mouseTool = new AMap.MouseTool(this.map);
      // mouseTool.rectangle();
      mouseTool.polygon({
        center: ["116.368074", "39.927925"],
        fillColor: "#00aeff57",
        strokeColor: "#00AEFF", //描边颜色
        strokeWeight: 2,
        strokeStyle: "solid",
      });

      mouseTool.on("draw", (event) => {
        event.obj.getPath().forEach((e, i) => {
          list.push({ lat: e.lat, lng: e.lng });
        });
        mouseTool.close(false);
        this.drawResolve(list);
      });
    });
  }
  clearMap() {
    this.map.clearMap();
  }
}
