"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getImage = exports["default"] = void 0;
var _Marker = _interopRequireWildcard(require("../marker/Marker"));
var _Point = _interopRequireDefault(require("../point/Point"));
var _Polygon = _interopRequireDefault(require("../polygon/Polygon"));
var _Polyline = _interopRequireDefault(require("../polyline/Polyline"));
var _lodash = require("lodash");
var _mapIcon = _interopRequireDefault(require("@vtx/map-icon/lib/map-icon"));
var _excluded = ["type", "icon", "image", "color", "size", "text"];
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
var getImage = exports.getImage = function getImage(options) {
  var image;
  if (typeof options === 'string') {
    image = options;
  } else if ((0, _lodash.isObject)(options)) {
    var _options$type = options.type,
      type = _options$type === void 0 ? 'CommonIcon' : _options$type,
      icon = options.icon,
      _image = options.image,
      color = options.color,
      size = options.size,
      text = options.text,
      other = _objectWithoutProperties(options, _excluded);

    // 图标类型 CockpitIcon CockpitIcon2 CommonIcon CommonIcon2
    if (type === 'PointIcon') {
      image = (0, _Marker.getImgUrl)(type, _objectSpread({
        size: size,
        color: color
      }, other));
    } else if (_mapIcon["default"][type] && text) {
      image = (0, _Marker.getImgUrl)(type, _objectSpread({
        color: color,
        text: text,
        size: size
      }, other));
    } else if (_mapIcon["default"][type] && _mapIcon["default"].icon[icon]) {
      image = (0, _Marker.getImgUrl)(type, _objectSpread({
        canvasIcon: icon,
        color: color,
        size: size
      }, other));
    } else {
      image = _image;
    }
  }
  return image;
};
var TYPE = {
  Point: _Point["default"],
  Polyline: _Polyline["default"],
  Polygon: _Polygon["default"],
  Circle: _Point["default"],
  Marker: _Marker["default"]
};
var Renderer = function Renderer(type) {
  var style = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  if (!type) {
    new Error('缺少类型');
  }
  if (!TYPE[type]) {
    new Error('没有这个类型类型的样式');
  }
  return new TYPE[type](style);
};
var Simple = function Simple(_ref) {
  var type = _ref.type,
    style = _ref.style;
  return Renderer(type, style);
};
var UniqueValue = function UniqueValue(feature, _ref2) {
  var field = _ref2.field,
    _ref2$render = _ref2.render,
    render = _ref2$render === void 0 ? [] : _ref2$render;
  var value = feature.get(field);
  var renderer = render.find(function (v) {
    return String(v.value) === String(value);
  });
  if (renderer) {
    return Simple(renderer);
  }
};
var ClassBreaks = function ClassBreaks(feature, _ref3) {
  var field = _ref3.field,
    _ref3$render = _ref3.render,
    render = _ref3$render === void 0 ? [] : _ref3$render;
  var value = feature.get(field);
  var renderer = render.find(function (v) {
    return Number(value) >= Number(v.value[0]) && Number(value) <= Number(v.value[1]);
  });
  if (renderer) {
    return Simple(renderer);
  }
};
var setRenderer = function setRenderer(layer, renderer) {
  if (layer && renderer) {
    var mode = renderer.mode;
    if (mode === 'Simple') {
      layer.setStyle(Simple(renderer));
    }
    if (mode === 'UniqueValue') {
      layer.setStyle(function (feature) {
        return UniqueValue(feature, renderer);
      });
    }
    if (mode === 'ClassBreaks') {
      layer.setStyle(function (feature) {
        return ClassBreaks(feature, renderer);
      });
    }
  }
};
var _default = exports["default"] = {
  Point: _Point["default"],
  Polyline: _Polyline["default"],
  Marker: _Marker["default"],
  Simple: Simple,
  UniqueValue: UniqueValue,
  ClassBreaks: ClassBreaks,
  Renderer: Renderer,
  setRenderer: setRenderer,
  getImage: getImage
};
//# sourceMappingURL=index.js.map
