"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.Toolbox = void 0;
exports["default"] = Tool;
exports.options = void 0;
var _react = _interopRequireWildcard(require("react"));
var _ItemWrap = _interopRequireDefault(require("../components/ItemWrap"));
var _ToolItem = _interopRequireDefault(require("../components/ToolItem"));
var _Icon = _interopRequireDefault(require("../components/Icon"));
var _Distance = _interopRequireDefault(require("./Measure/Distance"));
var _Area = _interopRequireDefault(require("./Measure/Area"));
var _MapPrint = _interopRequireDefault(require("./MapPrint"));
var _MapDownload = _interopRequireDefault(require("./MapDownload"));
var _EagleEye = _interopRequireDefault(require("./EagleEye"));
var _ScaleLine = _interopRequireDefault(require("./ScaleLine"));
var _MapBookmark = _interopRequireDefault(require("./MapBookmark"));
var _useProps2 = _interopRequireDefault(require("../../use-props"));
var _BoxSelect = _interopRequireDefault(require("./BoxSelect"));
var _CircleSelect = _interopRequireDefault(require("./CircleSelect"));
var _PolygonSelect = _interopRequireDefault(require("./PolygonSelect"));
var _SpaceQuery = _interopRequireDefault(require("./SpaceQuery"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
var P = {
  measureDistance: _Distance["default"],
  measureArea: _Area["default"],
  mapPrint: _MapPrint["default"],
  mapDownload: _MapDownload["default"],
  mapBookmark: _MapBookmark["default"],
  boxSelect: _BoxSelect["default"],
  circleSelect: _CircleSelect["default"],
  polygonSelect: _PolygonSelect["default"],
  spaceQuery: _SpaceQuery["default"]
};
var Toolbox = exports.Toolbox = function Toolbox(props) {
  var type = props.type;
  var Page = P[type];
  return /*#__PURE__*/_react["default"].createElement(Page, props);
};
var options = exports.options = [{
  label: '测距',
  icon: 'icon-ceju',
  key: 'measureDistance'
}, {
  label: '测面',
  icon: 'icon-mianji',
  key: 'measureArea'
}, {
  label: '地图书签',
  icon: 'icon-shuqian',
  key: 'mapBookmark'
}, {
  label: '地图下载',
  icon: 'icon-dituxiazai',
  key: 'mapDownload'
}, {
  label: '地图打印',
  icon: 'icon-ditudayin',
  key: 'mapPrint'
}];
function Tool(props) {
  var onScaleLineClick = props.onScaleLineClick,
    onEagleEyeClick = props.onEagleEyeClick,
    active = props.active,
    setActive = props.setActive;
  var _useProps = (0, _useProps2["default"])(),
    map = _useProps.map;
  var itemWrapRef = (0, _react.useRef)();
  (0, _react.useEffect)(function () {
    // 挂载关闭工具方法
    map.closeToolbox = function () {
      setActive('');
    };
    return function () {
      // 移除关闭工具方法
      delete map.closeToolbox;
    };
  }, []);
  var onChange = function onChange(v) {
    if (!v.key || v.key === 'pointSelect') {
      return;
    }

    // 关闭气泡
    itemWrapRef.current.setVisible(false);
    var value = active && v.key === active ? '' : v.key;

    // 执行关闭分析
    map.closeAnalysis && map.closeAnalysis();

    // 增加当前激活的工具属性
    map.toolboxActive = value;
    setActive(value);
  };
  return /*#__PURE__*/_react["default"].createElement(_ItemWrap["default"], {
    ref: itemWrapRef,
    content: /*#__PURE__*/_react["default"].createElement(_Icon["default"], {
      type: "icon-gongju"
    })
  }, options && options.length > 0 && options.map(function (v) {
    var params = props[v.key];
    if (params !== null && params !== void 0 && params.show) {
      return /*#__PURE__*/_react["default"].createElement(_ToolItem["default"], {
        key: v.label,
        onClick: function onClick() {
          return onChange(v);
        },
        label: v.label,
        icon: v.icon,
        active: active === v.key || v.active
      });
    } else {
      return null;
    }
  }), /*#__PURE__*/_react["default"].createElement(_ScaleLine["default"], {
    onClick: function onClick(val) {
      itemWrapRef.current.setVisible(false);
      onScaleLineClick === null || onScaleLineClick === void 0 || onScaleLineClick(val);
    }
  }), /*#__PURE__*/_react["default"].createElement(_EagleEye["default"], {
    onClick: function onClick(val) {
      itemWrapRef.current.setVisible(false);
      onEagleEyeClick === null || onEagleEyeClick === void 0 || onEagleEyeClick(val);
    }
  }));
}
Tool.defaultProps = {
  measureDistance: {
    show: true
  },
  measureArea: {
    show: true
  },
  pointSelect: {
    show: true
  },
  boxSelect: {
    show: true
  },
  circleSelect: {
    show: true
  },
  polygonSelect: {
    show: true
  },
  mapBookmark: {
    show: true
  },
  mapDownload: {
    show: true
  },
  mapPrint: {
    show: true
  },
  eagleEye: {
    show: true
  },
  scaleLine: {
    show: true
  },
  spaceQuery: {
    show: true
  }
};
//# sourceMappingURL=index.js.map
