"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["default"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _useDrawHandler = _interopRequireDefault(require("./hooks/useDrawHandler"));
var _useTerrainClipPlan = _interopRequireDefault(require("./hooks/useTerrainClipPlan"));
var _excavate_bottom_min = _interopRequireDefault(require("../assets/excavate_bottom_min.png"));
var _excavate_kuangqu = _interopRequireDefault(require("../assets/excavate_kuangqu.png"));
var _useProps2 = _interopRequireDefault(require("../use-props"));
var _useTileSetCut = _interopRequireDefault(require("./hooks/useTileSetCut"));
var _cesium = require("cesium");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
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 && {}.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 ExcavationAnalysis = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
  var _useProps = (0, _useProps2["default"])(),
    map = _useProps.map;
  var excavateDepth = (0, _react.useRef)(30);
  var terrainClipPlan = (0, _useTerrainClipPlan["default"])({
    viewer: map
  });
  var drawHandler = (0, _useDrawHandler["default"])({
    viewer: map,
    type: 'polygon'
  });
  var tileSetCut = (0, _useTileSetCut["default"])({
    viewer: map,
    sceneId: props.sceneId
  });
  drawHandler.on('drawEnd', function (res) {
    // 再次绘制清除之前开挖分析
    terrainClipPlan.clear();
    var positions = res.map(function (item) {
      return {
        x: item.x,
        y: item.y,
        z: item.z
      };
    });
    positions.pop();
    // 开挖分析
    terrainClipPlan.start({
      height: excavateDepth.current,
      splitNum: 100,
      wallImg: _excavate_kuangqu["default"],
      bottomImg: _excavate_bottom_min["default"],
      positions: positions
    });
    // 移除绘制区域
    drawHandler.clear();

    // let cutTool = tileSetCut.loadTileSetCut();
    // if (cutTool) {
    //     cutTool.addRegion({
    //         positions : cartesiansToLnglats(res),
    //         id : new Date().getTime()
    //     })
    // }
  });
  var cartesiansToLnglats = function cartesiansToLnglats(cartesians) {
    if (!cartesians || cartesians.length < 1) return;
    var arr = [];
    for (var i = 0; i < cartesians.length; i++) {
      arr.push(cartesianToLnglat(cartesians[i]));
    }
    return arr;
  };
  var cartesianToLnglat = function cartesianToLnglat(cartesian) {
    if (!cartesian) return [];
    var lnglat = _cesium.Cartographic.fromCartesian(cartesian);
    var lat = _cesium.Math.toDegrees(lnglat.latitude);
    var lng = _cesium.Math.toDegrees(lnglat.longitude);
    var hei = lnglat.height;
    return [lng, lat, hei];
  };
  (0, _react.useImperativeHandle)(ref, function () {
    return {
      drawHandler: drawHandler,
      terrainClipPlan: terrainClipPlan,
      onDraw: onDraw,
      onClear: onClear,
      onChange: onChange
    };
  });
  var onDraw = function onDraw() {
    drawHandler.activate();
  };
  var onClear = function onClear() {
    terrainClipPlan.clear();
  };
  var onChange = function onChange(value) {
    excavateDepth.current = value;
    terrainClipPlan.updateExcavateDepth(value);
  };
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null);
});
var _default = exports["default"] = ExcavationAnalysis;
//# sourceMappingURL=index.js.map
