import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
import _createClass from 'babel-runtime/helpers/createClass';
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
import _get from 'babel-runtime/helpers/get';
import _inherits from 'babel-runtime/helpers/inherits';
import _extends from 'babel-runtime/helpers/extends';
/**
 * @文件说明: Layers.BackgroundLayer 背景色矢量图层
 * @创建人: pjtools@vip.qq.com
 * @创建时间: 2020-05-22 15:01:49
 */

import BasicLayerClass, { defaultVectorLayerOptions, defaultVectorBasicOptions } from './basicLayer';
import deepmerge from 'deepmerge';

var defaultLayerOptions = deepmerge(defaultVectorLayerOptions, {
  paint: {
    'background-color': 'rgba(0, 0, 0, 1)',
    'background-opacity': 1
  },
  metadata: {
    layerTypeName: 'BackgroundLayer'
  }
});

var defaultOptions = _extends({}, defaultVectorBasicOptions);

var BackgroundLayer = function (_BasicLayerClass) {
  _inherits(BackgroundLayer, _BasicLayerClass);

  function BackgroundLayer(iMapApi, id) {
    var layerOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
    var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};

    _classCallCheck(this, BackgroundLayer);

    var opts = deepmerge.all([{}, defaultOptions, options || {}]);
    opts.opacityPaints = ['background-opacity'];
    // 合并原生Layer图层属性
    var layer = deepmerge.all([{}, defaultLayerOptions, layerOptions || {}]);
    layer.type = 'background';
    // 继承矢量图层基类

    // 绑定图层实例对象
    var _this = _possibleConstructorReturn(this, (BackgroundLayer.__proto__ || Object.getPrototypeOf(BackgroundLayer)).call(this, iMapApi, id, layer, opts));

    _this.mapLayer && (_this.mapLayer._instance = _this);
    return _this;
  }

  /**
   * 设置图层的整体透明度
   * @param {Number} opacity 待设定的透明度
   */


  _createClass(BackgroundLayer, [{
    key: 'setOpacity',
    value: function setOpacity(opacity) {
      _get(BackgroundLayer.prototype.__proto__ || Object.getPrototypeOf(BackgroundLayer.prototype), 'setOpacity', this).call(this, opacity, ['background-opacity']);
    }

    /**
     * 获取图层的背景色
     */

  }, {
    key: 'getColor',
    value: function getColor() {
      return this.getPaint('background-color');
    }

    /**
     * 设置图层的背景色
     * @param {String} color 待设定的背景色
     */

  }, {
    key: 'setColor',
    value: function setColor(color) {
      color && this.setPaint('background-color', color);
    }
  }]);

  return BackgroundLayer;
}(BasicLayerClass);

export default BackgroundLayer;