"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = FeatureDraw;
var _react = require("react");
var _useProps2 = _interopRequireDefault(require("../use-props"));
var _FeatureDraw = _interopRequireDefault(require("./FeatureDraw"));
var _propTypes = _interopRequireDefault(require("prop-types"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
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); }
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 FeatureDraw(props) {
  var _useProps = (0, _useProps2["default"])(),
    map = _useProps.map,
    TextEnum = _useProps.TextEnum;
  var drawRef = (0, _react.useRef)();
  var _props$drawType = props.drawType,
    drawType = _props$drawType === void 0 ? '' : _props$drawType,
    _props$onDrawEnd = props.onDrawEnd,
    onDrawEnd = _props$onDrawEnd === void 0 ? function () {} : _props$onDrawEnd,
    _props$feature = props.feature,
    feature = _props$feature === void 0 ? null : _props$feature,
    _props$style = props.style,
    style = _props$style === void 0 ? null : _props$style,
    _props$markerStyle = props.markerStyle,
    markerStyle = _props$markerStyle === void 0 ? {
      icon: 'YWZ',
      color: '#119FFB'
    } : _props$markerStyle;
  (0, _react.useEffect)(function () {
    drawRef.current = new _FeatureDraw["default"](_objectSpread(_objectSpread({}, props), {}, {
      map: map,
      TextEnum: TextEnum,
      style: style
    }), function (feature, distance) {
      onDrawEnd(feature, distance);
    });
    return function () {
      drawRef.current.destroy();
    };
  }, []);
  (0, _react.useEffect)(function () {
    if (drawRef.current) {
      var _drawRef$current, _drawRef$current2;
      (_drawRef$current = drawRef.current) === null || _drawRef$current === void 0 || _drawRef$current.clearFeatures();
      (_drawRef$current2 = drawRef.current) === null || _drawRef$current2 === void 0 || _drawRef$current2.removeDrawTool();
      // 如果有features的话 加载features
      if (feature) {
        var _drawRef$current3;
        (_drawRef$current3 = drawRef.current) === null || _drawRef$current3 === void 0 || _drawRef$current3.loadFeatures(feature);
      } else {
        var _drawRef$current4;
        (_drawRef$current4 = drawRef.current) === null || _drawRef$current4 === void 0 || _drawRef$current4.init(drawType, function (feature, distance) {
          onDrawEnd(feature, distance);
        }, markerStyle);
      }
      drawRef.current.drawType = drawType;
    }
  }, [drawType, feature]);
  return null;
}
FeatureDraw.propTypes = {
  drawType: _propTypes["default"].string,
  onDrawEnd: _propTypes["default"].func,
  feature: _propTypes["default"].object,
  style: _propTypes["default"].object,
  markerStyle: _propTypes["default"].object
};
//# sourceMappingURL=index.js.map
