"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"] = FlowMap;
var _react = _interopRequireWildcard(require("react"));
require("./index.less");
var _olMap = require("@vtx/ol-map");
var turf = _interopRequireWildcard(require("@turf/turf"));
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 FlowMap(_ref) {
  var flowData = _ref.flowData,
    info = _ref.info;
  var _a, _b, _c, _d, _e, _f, _g;
  var startData = ((_a = info === null || info === void 0 ? void 0 : info.geometryInfo) === null || _a === void 0 ? void 0 : _a.lngLats) ? [{
      name: info === null || info === void 0 ? void 0 : info.name,
      geometryInfo: info === null || info === void 0 ? void 0 : info.geometryInfo
    }] : [],
    endData = [],
    endCenters = [];
  flowData.map(function (item) {
    var _a, _b, _c, _d, _e, _f;
    if ((_a = item === null || item === void 0 ? void 0 : item.startingPointAddress) === null || _a === void 0 ? void 0 : _a.lngLats) {
      endData.push({
        name: item.startingPointName,
        geometryInfo: {
          type: 'polygon',
          lngLats: item.startingPointAddress.lngLats,
          coordType: 'wgs84'
        }
      });
      var endFeatures = turf.points((_c = (_b = item.startingPointAddress) === null || _b === void 0 ? void 0 : _b.lngLats) === null || _c === void 0 ? void 0 : _c.split(';').map(function (item) {
        return item.split(',').map(function (item) {
          return Number(item);
        });
      }));
      endCenters.push((_f = (_e = (_d = turf.center(endFeatures)) === null || _d === void 0 ? void 0 : _d.geometry) === null || _e === void 0 ? void 0 : _e.coordinates) === null || _f === void 0 ? void 0 : _f.join());
    }
  });
  var startFeatures = turf.points((_c = (_b = info === null || info === void 0 ? void 0 : info.geometryInfo) === null || _b === void 0 ? void 0 : _b.lngLats) === null || _c === void 0 ? void 0 : _c.split(';').map(function (item) {
    return item.split(',').map(function (item) {
      return Number(item);
    });
  }));
  var startCenter = (_f = (_e = (_d = turf.center(startFeatures)) === null || _d === void 0 ? void 0 : _d.geometry) === null || _e === void 0 ? void 0 : _e.coordinates) === null || _f === void 0 ? void 0 : _f.join();
  var mapRef = (0, _react.useRef)(null);
  (0, _react.useEffect)(function () {
    if (mapRef.current) {
      mapRef.current.fitView([].concat(endData, startData));
    }
  }, [JSON.stringify(endData), JSON.stringify(startData)]);
  var flyLineData = endCenters.map(function (item) {
    return {
      geometryInfo: {
        coordType: 'wgs84',
        lngLats: "".concat(item, ";").concat(startCenter),
        type: 'polyline'
      }
    };
  });
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "jzlj-df-dpd-dispose-container-flowMap"
  }, /*#__PURE__*/_react["default"].createElement(_olMap.Map, {
    tk: "1adbb6e47668cb33757cd799548bf1f4",
    createdMap: function createdMap(map) {
      mapRef.current = map;
    }
  }, /*#__PURE__*/_react["default"].createElement(_olMap.Legend, null), /*#__PURE__*/_react["default"].createElement(_olMap.FeatureLayer, {
    data: startData,
    style: ((_g = info === null || info === void 0 ? void 0 : info.geometryInfo) === null || _g === void 0 ? void 0 : _g.type) === 'point' ? {
      type: 'Marker',
      style: {
        icon: 'DF',
        color: '#3ab4b4'
      }
    } : {
      type: 'Polygon',
      style: {
        stroke: {
          color: '#3ab4b4',
          opacity: 1,
          width: 2
        },
        fill: {
          color: '#3ab4b4',
          opacity: 0.4
        }
      }
    },
    id: "end",
    labelField: "name",
    name: "\u7EC8\u70B9"
  }), /*#__PURE__*/_react["default"].createElement(_olMap.FeatureLayer, {
    data: endData,
    style: {
      type: 'Polygon',
      style: {
        stroke: {
          color: '#2968eb',
          opacity: 1,
          width: 2
        },
        fill: {
          color: '#2968eb',
          opacity: 0.4
        }
      }
    },
    id: "start",
    labelField: "name",
    name: "\u8D77\u70B9"
  }), (flyLineData === null || flyLineData === void 0 ? void 0 : flyLineData.length) > 0 && (/*#__PURE__*/_react["default"].createElement(_olMap.FlyLineLayer, {
    color: "#0080ff",
    id: "fly_line_czz",
    width: 3,
    flyWidth: 6,
    lineStyle: {
      color: '#0080ff'
    },
    data: flyLineData
  }))));
}
//# sourceMappingURL=FlowMap.js.map
