"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _react = _interopRequireWildcard(require("react"));
require("./style");
var _useProps2 = _interopRequireDefault(require("../use-props"));
var _ScaleDenominator = _interopRequireDefault(require("./ScaleDenominator"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } // Test.jsx
// 获取地图容器的像素尺寸
function getMapSizeInPx(map) {
  var viewport = map.getViewport();
  var rect = viewport.getBoundingClientRect();
  return {
    width: rect.width,
    height: rect.height
  };
}

// 示例：在控制台输出当前地图尺寸
var Test = function Test() {
  var _useProps = (0, _useProps2["default"])(),
    map = _useProps.map;
  var _useState = (0, _react.useState)('none'),
    _useState2 = _slicedToArray(_useState, 2),
    dispaly = _useState2[0],
    setDispaly = _useState2[1];
  var _useState3 = (0, _react.useState)(0),
    _useState4 = _slicedToArray(_useState3, 2),
    clickCount = _useState4[0],
    setClickCount = _useState4[1];
  var _useState5 = (0, _react.useState)(false),
    _useState6 = _slicedToArray(_useState5, 2),
    isDragging = _useState6[0],
    setIsDragging = _useState6[1];
  var _useState7 = (0, _react.useState)({
      x: 0,
      y: 0
    }),
    _useState8 = _slicedToArray(_useState7, 2),
    dragStart = _useState8[0],
    setDragStart = _useState8[1];
  var _useState9 = (0, _react.useState)({
      x: 100,
      y: 100
    }),
    _useState10 = _slicedToArray(_useState9, 2),
    boxPosition = _useState10[0],
    setBoxPosition = _useState10[1];
  var boxRef = (0, _react.useRef)(null);
  var lastClickTime = (0, _react.useRef)(0);
  (0, _react.useEffect)(function () {
    if (!map) return;
    setBoxPosition({
      x: getMapSizeInPx(map).width / 2 - 100,
      y: getMapSizeInPx(map).height / 2 - 75
    });
    var handleClick = function handleClick() {
      var currentTime = Date.now();
      // 检查两次点击间隔是否小于1秒(1000毫秒)
      if (currentTime - lastClickTime.current < 1000) {
        var newCount = clickCount + 1;
        setClickCount(newCount);
        if (newCount >= 10) {
          setDispaly('block');
        }
      }
      // 更新上次点击时间
      lastClickTime.current = currentTime;
    };
    map.on('click', handleClick);
    return function () {
      map.un('click', handleClick);
    };
  }, [map, clickCount]);
  // 处理拖动开始
  var handleDragStart = function handleDragStart(e) {
    setIsDragging(true);
    setDragStart({
      x: e.clientX - boxPosition.x,
      y: e.clientY - boxPosition.y
    });
    e.preventDefault();
  };

  // 处理拖动过程
  var handleDrag = function handleDrag(e) {
    if (isDragging) {
      setBoxPosition({
        x: e.clientX - dragStart.x,
        y: e.clientY - dragStart.y
      });
    }
  };

  // 处理拖动结束
  var handleDragEnd = function handleDragEnd() {
    setIsDragging(false);
  };

  // 在useEffect中添加鼠标事件监听
  (0, _react.useEffect)(function () {
    if (isDragging) {
      document.addEventListener('mousemove', handleDrag);
      document.addEventListener('mouseup', handleDragEnd);
    } else {
      document.removeEventListener('mousemove', handleDrag);
      document.removeEventListener('mouseup', handleDragEnd);
    }
    return function () {
      document.removeEventListener('mousemove', handleDrag);
      document.removeEventListener('mouseup', handleDragEnd);
    };
  }, [isDragging, dragStart]);
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, dispaly === 'block' && /*#__PURE__*/_react["default"].createElement("div", {
    ref: boxRef,
    style: {
      position: 'absolute',
      top: "".concat(boxPosition.y, "px"),
      left: "".concat(boxPosition.x, "px"),
      width: '200px',
      height: '150px',
      border: '2px solid #333',
      backgroundColor: 'rgba(255, 255, 255, 0.8)',
      cursor: 'move',
      resize: 'both',
      overflow: 'auto',
      zIndex: 1000
    },
    onMouseDown: handleDragStart
  }, /*#__PURE__*/_react["default"].createElement(_ScaleDenominator["default"], null)));
};
var _default = Test;
exports["default"] = _default;
//# sourceMappingURL=Test.js.map
