'use strict';

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

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

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

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

var _createClass3 = _interopRequireDefault(_createClass2);

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

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _get2 = require('babel-runtime/helpers/get');

var _get3 = _interopRequireDefault(_get2);

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

var _inherits3 = _interopRequireDefault(_inherits2);

var _extends2 = require('babel-runtime/helpers/extends');

var _extends3 = _interopRequireDefault(_extends2);

var _basicLayer = require('./basicLayer');

var _basicLayer2 = _interopRequireDefault(_basicLayer);

var _deepmerge = require('deepmerge');

var _deepmerge2 = _interopRequireDefault(_deepmerge);

var _methodsUtil = require('../../../_util/methods-util');

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

var defaultLayerOptions = (0, _deepmerge2['default'])(_basicLayer.defaultVectorLayerOptions, {
  paint: {
    'icon-color': 'rgba(0, 0, 0, 1)',
    'icon-halo-blur': 0,
    'icon-halo-color': 'rgba(0, 0, 0, 0)',
    'icon-halo-width': 0,
    'icon-opacity': 1,
    'icon-translate': [0, 0],
    'text-color': 'rgba(0, 0, 0, 1)',
    'text-halo-blur': 0,
    'text-halo-color': 'rgba(0, 0, 0, 0)',
    'text-halo-width': 0,
    'text-opacity': 1,
    'text-translate': [0, 0]
  },
  layout: {
    'symbol-placement': 'point',
    'icon-allow-overlap': false,
    'icon-anchor': 'center',
    'icon-ignore-placement': false,
    'icon-keep-upright': false,
    'icon-offset': [0, 0],
    'icon-optional': false,
    'icon-padding': 0,
    'icon-rotate': 0,
    'icon-size': 1,
    'icon-text-fit': 'none',
    'text-allow-overlap': false,
    'text-anchor': 'center',
    'text-ignore-placement': false,
    'text-justify': 'center',
    'text-keep-upright': true,
    'text-line-height': 1.2,
    'text-max-angle': 45,
    'text-max-width': 50,
    'text-offset': [0, 0],
    'text-optional': false,
    'text-padding': 0,
    'text-radial-offset': 0,
    'text-rotate': 0,
    'text-size': 16,
    'text-transform': 'none'
  },
  metadata: {
    layerTypeName: 'SymbolLayer'
  }
}); /**
     * @文件说明: Layers.SymbolLayer 矢量符号图层
     * @创建人: pjtools@vip.qq.com
     * @创建时间: 2020-06-09 17:27:55
     */

var defaultOptions = (0, _extends3['default'])({}, _basicLayer.defaultVectorBasicOptions);

var SymbolLayer = function (_BasicLayerClass) {
  (0, _inherits3['default'])(SymbolLayer, _BasicLayerClass);

  function SymbolLayer(iMapApi, id) {
    var layerOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
    var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
    (0, _classCallCheck3['default'])(this, SymbolLayer);

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

    // 绑定图层实例对象
    var _this = (0, _possibleConstructorReturn3['default'])(this, (SymbolLayer.__proto__ || Object.getPrototypeOf(SymbolLayer)).call(this, iMapApi, id, layer, opts));

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

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


  (0, _createClass3['default'])(SymbolLayer, [{
    key: 'setOpacity',
    value: function setOpacity(opacity) {
      (0, _get3['default'])(SymbolLayer.prototype.__proto__ || Object.getPrototypeOf(SymbolLayer.prototype), 'setOpacity', this).call(this, opacity, ['icon-opacity', 'text-opacity']);
    }
  }]);
  return SymbolLayer;
}(_basicLayer2['default']);

exports['default'] = SymbolLayer;

/**
 * 扩展文本矢量图层
 */

var TextSymbolLayer = exports.TextSymbolLayer = function (_SymbolLayer) {
  (0, _inherits3['default'])(TextSymbolLayer, _SymbolLayer);

  function TextSymbolLayer(iMapApi, id) {
    var layerOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
    var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
    (0, _classCallCheck3['default'])(this, TextSymbolLayer);

    !layerOptions && (layerOptions = {});
    // 设置文本内容
    if (options && options.text) {
      !layerOptions.layout && (layerOptions.layout = {});
      layerOptions.layout['text-field'] = options.text;
    }
    // 设置文本大小
    if (options && !(0, _methodsUtil.isEmpty)(options.size)) {
      !layerOptions.layout && (layerOptions.layout = {});
      layerOptions.layout['text-size'] = options.size;
    }
    // 设置矢量符号碰撞显示
    if (options && (0, _methodsUtil.isBooleanTrue)(options.overlap)) {
      !layerOptions.layout && (layerOptions.layout = {});
      layerOptions.layout['text-allow-overlap'] = options.overlap;
      layerOptions.layout['text-ignore-placement'] = options.overlap;
    }
    // 继承矢量符号基类
    return (0, _possibleConstructorReturn3['default'])(this, (TextSymbolLayer.__proto__ || Object.getPrototypeOf(TextSymbolLayer)).call(this, iMapApi, id, layerOptions, options));
  }

  /**
   * 获取矢量文本的颜色属性
   */


  (0, _createClass3['default'])(TextSymbolLayer, [{
    key: 'getColor',
    value: function getColor() {
      return this.getPaint('text-color');
    }

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

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

    /**
     * 获取矢量文本的字体大小
     */

  }, {
    key: 'getSize',
    value: function getSize() {
      return this.getLayout('text-size');
    }

    /**
     * 设置矢量文本的字体大小
     * @param {Number} size 待设定的字体大小
     */

  }, {
    key: 'setSize',
    value: function setSize(size) {
      !(0, _methodsUtil.isEmpty)(size) && this.setLayout('text-size', size);
    }

    /**
     * 获取矢量文本的外描边
     */

  }, {
    key: 'getHalo',
    value: function getHalo() {
      return {
        width: this.getPaint('text-halo-width'),
        color: this.getPaint('text-halo-color'),
        blur: this.getPaint('text-halo-blur')
      };
    }

    /**
     * 设置矢量文本的外描边样式
     * @param {Object} options 外描边的参数选项，包括：[ width | color | blur ]
     */

  }, {
    key: 'setHalo',
    value: function setHalo() {
      var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

      !options && (options = {});
      !(0, _methodsUtil.isEmpty)(options.width) && this.setPaint('text-halo-width', options.width);
      !(0, _methodsUtil.isEmpty)(options.color) && this.setPaint('text-halo-color', options.color);
      !(0, _methodsUtil.isEmpty)(options.blur) && this.setPaint('text-halo-blur', options.blur);
    }

    /**
     * 设置矢量文本是否碰撞显示
     * @param {Boolean} overlap 是否允许碰撞强制显示
     */

  }, {
    key: 'setOverlap',
    value: function setOverlap() {
      var overlap = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;

      overlap = !!(0, _methodsUtil.isBooleanTrue)(overlap);
      this.setLayout('text-allow-overlap', overlap);
      this.setLayout('text-ignore-placement', overlap);
    }

    /**
     * 设置矢量文本的显示文本
     * @param {String} text 待设置的矢量文本
     */

  }, {
    key: 'setText',
    value: function setText(text) {
      !(0, _methodsUtil.isEmpty)(text) && this.setLayout('text-field', text);
    }
  }]);
  return TextSymbolLayer;
}(SymbolLayer);

/**
 * 扩展图标矢量图层
 */


var IconSymbolLayer = exports.IconSymbolLayer = function (_SymbolLayer2) {
  (0, _inherits3['default'])(IconSymbolLayer, _SymbolLayer2);

  function IconSymbolLayer(iMapApi, id) {
    var layerOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
    var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
    (0, _classCallCheck3['default'])(this, IconSymbolLayer);

    !layerOptions && (layerOptions = {});
    // 设置图标
    if (options && options.icon) {
      !layerOptions.layout && (layerOptions.layout = {});
      layerOptions.layout['icon-image'] = options.icon;
    }
    // 设置图标的大小
    if (options && !(0, _methodsUtil.isEmpty)(options.size)) {
      !layerOptions.layout && (layerOptions.layout = {});
      layerOptions.layout['icon-size'] = options.size;
    }
    // 设置矢量符号碰撞显示
    if (options && (0, _methodsUtil.isBooleanTrue)(options.overlap)) {
      !layerOptions.layout && (layerOptions.layout = {});
      layerOptions.layout['icon-allow-overlap'] = options.overlap;
      layerOptions.layout['icon-ignore-placement'] = options.overlap;
    }
    // 继承矢量符号基类
    return (0, _possibleConstructorReturn3['default'])(this, (IconSymbolLayer.__proto__ || Object.getPrototypeOf(IconSymbolLayer)).call(this, iMapApi, id, layerOptions, options));
  }

  /**
   * 获取矢量图标的尺寸大小
   */


  (0, _createClass3['default'])(IconSymbolLayer, [{
    key: 'getSize',
    value: function getSize() {
      return this.getLayout('icon-size');
    }

    /**
     * 设置矢量图标的尺寸大小
     * @param {Number} size 待设定的尺寸大小
     */

  }, {
    key: 'setSize',
    value: function setSize(size) {
      !(0, _methodsUtil.isEmpty)(size) && this.setLayout('icon-size', size);
    }

    /**
     * 设置矢量图标是否碰撞显示
     * @param {Boolean} overlap 是否允许碰撞强制显示
     */

  }, {
    key: 'setOverlap',
    value: function setOverlap() {
      var overlap = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;

      overlap = !!(0, _methodsUtil.isBooleanTrue)(overlap);
      this.setLayout('icon-allow-overlap', overlap);
      this.setLayout('icon-ignore-placement', overlap);
    }

    /**
     * 设置矢量图标
     * @param {String} icon 待设置的矢量图标
     */

  }, {
    key: 'setIcon',
    value: function setIcon(icon) {
      icon && this.setLayout('icon-image', icon);
    }
  }]);
  return IconSymbolLayer;
}(SymbolLayer);