import { MapOverLayer } from './MapOverLayer'
import { MapCoordTrans } from '../export/MapCoordTrans'
/**
 * 百度图层类，存放于maplayers数据中
 * @private
 */
export class BDMapOverLayer extends MapOverLayer {
  //this.element =>[BMapGL.Marker],[BMapGL.Polyline],[ BMapGL.Polygon]
  constructor(name, element, visible, type) {
    super(name, element, visible, type)
    this.coordTrans = new MapCoordTrans()
  }
  /**
   * 注册事件
   * @param {string} eventType 事件类型
   * @param {function} callback 回调函数
   */
  on(eventType, callback) {
    var that = this
    for (var i = 0; i < this.element.length; i++) {
      this.element[i].addEventListener(eventType, function (e) {
        // callback(e)
        var pt84 = that.coordTrans.baiduToWGS84([[e.latLng.lng, e.latLng.lat]])
        callback({
          attr: e.target.attributes,
          lonlat: pt84[0],
          object: e.target,
          mapsEvent: e
        })
      })
    }
  }
  /**
   * 根据事件类型移除事件
   * @param {string} eventType 事件类性
   */
  off(eventType) {
    for (var i = 0; i < this.element.length; i++) {
      this.element[i].removeEventListener(eventType)
    }
  }
}
