'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.bindPrototypeMethods = exports.BasicMapApiEvented = undefined;

var _typeof2 = require('babel-runtime/helpers/typeof');

var _typeof3 = _interopRequireDefault(_typeof2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

/**
 * @文件说明: 构建iMapApi地图实例的子级对象的基类
 * @创建人: pjtools@vip.qq.com
 * @创建时间: 2020-03-19 23:31:37
 */

var BasicMapApi = function () {
  var _iMapApi = Symbol('iMapApi');

  var BasicMapApi = function () {
    (0, _createClass3['default'])(BasicMapApi, [{
      key: 'iMapApi',
      get: function get() {
        return this[_iMapApi];
      }
    }]);

    function BasicMapApi(iMapApi) {
      (0, _classCallCheck3['default'])(this, BasicMapApi);

      this[_iMapApi] = iMapApi;
    }

    return BasicMapApi;
  }();

  return BasicMapApi;
}();

exports['default'] = BasicMapApi;

// 扩展带自定义事件的基类

var BasicMapApiEvented = exports.BasicMapApiEvented = function () {
  var _evented = Symbol('Evented');

  var BasicMapApiEvented = function (_BasicMapApi) {
    (0, _inherits3['default'])(BasicMapApiEvented, _BasicMapApi);

    function BasicMapApiEvented(iMapApi) {
      (0, _classCallCheck3['default'])(this, BasicMapApiEvented);

      var _this = (0, _possibleConstructorReturn3['default'])(this, (BasicMapApiEvented.__proto__ || Object.getPrototypeOf(BasicMapApiEvented)).call(this, iMapApi));

      var _ref = iMapApi && iMapApi.exports,
          mapboxgl = _ref.mapboxgl;

      _this[_evented] = new mapboxgl.Evented();
      return _this;
    }

    /**
     * 注册绑定事件
     * @param {String} type 事件类型名
     * @param {Function} listener 回调事件函数
     */


    (0, _createClass3['default'])(BasicMapApiEvented, [{
      key: 'on',
      value: function on(type, listener) {
        return this[_evented].on(type, listener);
      }

      /**
       * 解除绑定事件
       * @param {String} type 事件类型名
       * @param {Function} listener 回调事件函数
       */

    }, {
      key: 'off',
      value: function off(type, listener) {
        return this[_evented].off(type, listener);
      }

      /**
       * 注册绑定仅只执行一次事件
       * @param {String} type 事件类型名
       * @param {Function} listener 回调事件函数
       */

    }, {
      key: 'once',
      value: function once(type, listener) {
        return this[_evented].once(type, listener);
      }

      /**
       * 驱动执行绑定的事件
       * @param {Event} event 事件类型名
       * @param {Object} properties 回调事件函数接收的数据
       */

    }, {
      key: 'fire',
      value: function fire(event, properties) {
        return this[_evented].fire(event, properties);
      }

      /**
       * 判断事件监听是否已注册
       * @param {String} type 事件类型名
       */

    }, {
      key: 'listens',
      value: function listens(type) {
        return this[_evented].listens(type);
      }
    }]);
    return BasicMapApiEvented;
  }(BasicMapApi);

  return BasicMapApiEvented;
}();

/**
 * 动态扩展Class类的Prototype属性挂接函数方法
 * @param {Object} methods 待动态添加的函数对象
 * @param {Class} prototype 待动态挂接的Class类Prototype属性
 */
var bindPrototypeMethods = exports.bindPrototypeMethods = function bindPrototypeMethods(methods, prototype) {
  if ((typeof methods === 'undefined' ? 'undefined' : (0, _typeof3['default'])(methods)) === 'object') {
    Object.keys(methods).map(function (key) {
      prototype[key] = methods[key];
    });
  }
};