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.LineLayer 矢量线图层
 * @创建人: pjtools@vip.qq.com
 * @创建时间: 2020-05-25 10:05:46
 */

import BasicLayerClass, { defaultVectorLayerOptions, defaultVectorBasicOptions } from './basicLayer';
import deepmerge from 'deepmerge';
import { isEmpty } from '../../../_util/methods-util';

var defaultLayerOptions = deepmerge(defaultVectorLayerOptions, {
  paint: {
    'line-color': 'rgba(250, 84, 28, 0.8)',
    'line-opacity': 1,
    'line-width': 4,
    'line-blur': 0,
    'line-offset': 0,
    'line-gap-width': 0
  },
  layout: {
    'line-cap': 'round',
    'line-join': 'round'
  },
  metadata: {
    layerTypeName: 'LineLayer'
  }
});

var defaultOptions = _extends({}, defaultVectorBasicOptions);

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

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

    _classCallCheck(this, LineLayer);

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

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

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

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


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

    /**
     * 获取矢量线的颜色属性
     */

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

    /**
     * 设置矢量线的颜色属性
     * @param {String} color 待设定的颜色值
     */

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

    /**
     * 获取矢量线的宽度
     */

  }, {
    key: 'getLineWidth',
    value: function getLineWidth() {
      return this.getPaint('line-width');
    }

    /**
     * 设置矢量线的宽度
     * @param {Number} width 待设定的线宽度
     */

  }, {
    key: 'setLineWidth',
    value: function setLineWidth(width) {
      !isEmpty(width) && this.setPaint('line-width', width);
    }
  }]);

  return LineLayer;
}(BasicLayerClass);

export default LineLayer;