const { ZenMap, GeoJSON, zenmap } = window;
const map = zenmap;

export const drawByGeometry = ({ geometry, id, opt, callBack, needMove = true, layers }) => {
  // map.clearOverlays();//删除所有覆盖物
  var overLayer = GeoJSON.read(geometry);
  opt && overLayer.setStyle(opt);
  overLayer.currentId = id;
  // this.arrowline.load([overLayer]);
  needMove === true && map.zoomToExtent(overLayer.getExtent(), null, { speed: 10 });
  layers ? layers.addOverlay(overLayer) : map.addLayer(overLayer);
  callBack && callBack(overLayer);
};

export const drawPolygonByPoint = ({ map, pointList, opt, isEnableEdit = false, callback, setZoom = false, layer, isRender = true }) => {
  let polygonOpt = opt
    ? opt
    : {
        color: '#A541FF', //颜色
        fillColor: '#ABB7FF', //填充颜色
        weight: 2, //宽度，以像素为单位
        opacity: 0.46, //透明度，取值范围0 - 1
        fillOpacity: 0.46, //填充的透明度，取值范围0 - 1
        lineStyle: 'LINE_TYPE_DASH ',
        // text: "胡写一个" //填充文案
      };
  var polygon = new ZenMap.Geometry.Polygon(pointList, polygonOpt);
  polygon.isEnableEdit = isEnableEdit;
  if (isRender) {
    layer ? layer.addOverlay(polygon) : map.addOverlay(polygon);
  }
  try {
    setZoom && map.zoomToExtent(polygon.getExtent(), null, { speed: 15, linear: false, duration: 1000 });
  } catch (err) {
    console.log(err);
  }

  callback && callback(polygon);
};
