"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 _GwLayer = _interopRequireDefault(require("../_component/GwLayer"));
var _config = require("./config");
var _Status = _interopRequireDefault(require("./Status"));
var _olMap = require("@vtx/ol-map");
var _lodash = require("lodash");
var _moment = _interopRequireDefault(require("moment"));
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; }
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 _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } /* eslint-disable react/prop-types */
var Popup = function Popup(_ref) {
  var _facility$dataJson, _facility$dataJson2, _facility$dataJson3, _facility$dataJson4, _facility$dataJson5, _facility$dataJson6, _facility$dataJson7, _facility$dataJson8, _facility$dataJson9;
  var _ref$info = _ref.info,
    info = _ref$info === void 0 ? {} : _ref$info,
    openModal = _ref.openModal;
  var calDate = info.calDate,
    avgSunnyFlow = info.avgSunnyFlow,
    avgRainFlow = info.avgRainFlow,
    facility = info.facility,
    divisionName = info.divisionName;
  var _ref2 = facility || {},
    typeCode = _ref2.typeCode,
    dataJson = _ref2.dataJson;
  var lineList = [{
    label: '所在道路',
    value: (dataJson === null || dataJson === void 0 ? void 0 : dataJson.roadName) || '-'
  }, {
    label: '管材',
    value: (facility === null || facility === void 0 || (_facility$dataJson = facility.dataJson) === null || _facility$dataJson === void 0 ? void 0 : _facility$dataJson.lineTextureName) || '-'
  }, {
    label: '管长',
    value: (facility === null || facility === void 0 || (_facility$dataJson2 = facility.dataJson) === null || _facility$dataJson2 === void 0 ? void 0 : _facility$dataJson2.lineLength) + 'm'
  }, {
    label: '管径',
    value: (facility === null || facility === void 0 || (_facility$dataJson3 = facility.dataJson) === null || _facility$dataJson3 === void 0 ? void 0 : _facility$dataJson3.ds) + 'mm'
  }];
  var manholeList = [{
    label: '所在道路',
    value: (dataJson === null || dataJson === void 0 ? void 0 : dataJson.roadName) || '-'
  }, {
    label: '管材',
    value: (facility === null || facility === void 0 || (_facility$dataJson4 = facility.dataJson) === null || _facility$dataJson4 === void 0 ? void 0 : _facility$dataJson4.lineTextureName) || '-'
  }, {
    label: '地面高程',
    value: (facility === null || facility === void 0 || (_facility$dataJson5 = facility.dataJson) === null || _facility$dataJson5 === void 0 ? void 0 : _facility$dataJson5.groundElevation) + 'm'
  }, {
    label: '窨井井深',
    value: facility !== null && facility !== void 0 && (_facility$dataJson6 = facility.dataJson) !== null && _facility$dataJson6 !== void 0 && _facility$dataJson6.wellDeep ? (facility === null || facility === void 0 || (_facility$dataJson7 = facility.dataJson) === null || _facility$dataJson7 === void 0 ? void 0 : _facility$dataJson7.wellDeep) + 'm' : '-'
  }];
  var pumpStationList = [{
    label: '行政区划',
    value: divisionName,
    span: 24
  }, {
    label: '总额定流量',
    span: 24,
    value: (facility === null || facility === void 0 || (_facility$dataJson8 = facility.dataJson) === null || _facility$dataJson8 === void 0 ? void 0 : _facility$dataJson8.totalRatedFlow) + 'm³/s'
  }];
  var sewagePlantList = [{
    label: '行政区划',
    value: divisionName,
    span: 24
  }, {
    label: '日处理能力',
    span: 24,
    value: (facility === null || facility === void 0 || (_facility$dataJson9 = facility.dataJson) === null || _facility$dataJson9 === void 0 ? void 0 : _facility$dataJson9.supplyCapacity) + '万吨'
  }];
  var listMap = {
    line: lineList,
    manhole: manholeList,
    pump_station: pumpStationList,
    sewage_plant: sewagePlantList
  };
  var list = [{
    content: /*#__PURE__*/_react["default"].createElement(_Status["default"], {
      info: info
    }),
    span: 24
  }].concat(_toConsumableArray(listMap[typeCode] || []), [{
    label: '分析时间',
    value: "".concat((0, _moment["default"])(calDate).format('YYYY-MM-DD')),
    span: 24
  }, {
    label: '晴天平均流量',
    value: avgSunnyFlow + 'm³/h',
    span: 24
  }, {
    label: '雨天平均流量',
    value: avgRainFlow + 'm³/h',
    span: 24
  }]);
  return /*#__PURE__*/_react["default"].createElement(_olMap.Popup.Template, {
    contentList: list,
    column: 2,
    contentStyle: {
      width: 390
    },
    detail: {
      show: true,
      onClick: function onClick() {
        return openModal({
          id: info.id
        });
      }
    }
  });
};
var MapLayer = function MapLayer(_ref3) {
  var _ref3$data = _ref3.data,
    data = _ref3$data === void 0 ? [] : _ref3$data,
    openModal = _ref3.openModal;
  var _useMemo = (0, _react.useMemo)(function () {
      var lineList = [];
      var manholeList = [];
      var pumpStationList = [];
      var sewagePlantList = [];
      data.map(function (item) {
        var _item$facility2;
        var _item$facility = item.facility,
          facility = _item$facility === void 0 ? {} : _item$facility;
        var typeCode = facility.typeCode;
        var data = _objectSpread(_objectSpread({}, item), {}, {
          geometryInfo: item === null || item === void 0 || (_item$facility2 = item.facility) === null || _item$facility2 === void 0 ? void 0 : _item$facility2.geometryInfo
        });
        switch (typeCode) {
          case 'line':
            {
              lineList.push(data);
              break;
            }
          case 'manhole':
            {
              manholeList.push(data);
              break;
            }
          case 'pump_station':
            {
              pumpStationList.push(data);
              break;
            }
          case 'sewage_plant':
            {
              sewagePlantList.push(data);
            }
        }
      });
      return {
        lineList: lineList,
        manholeList: manholeList,
        pumpStationList: pumpStationList,
        sewagePlantList: sewagePlantList
      };
    }, [JSON.stringify(data)]),
    lineList = _useMemo.lineList,
    manholeList = _useMemo.manholeList,
    pumpStationList = _useMemo.pumpStationList,
    sewagePlantList = _useMemo.sewagePlantList;
  var lineGroup = [{
    name: '管线正常',
    color: '#FDA839',
    filter: function filter(info) {
      return !info.isAlarm;
    },
    key: "".concat(_config.facilityLayerId.line, "_NORMAL")
  }, {
    name: '管线异常',
    color: '#E90F0F',
    filter: function filter(info) {
      return info.isAlarm;
    },
    key: "".concat(_config.facilityLayerId.line, "_ERROR")
  }];
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, !(0, _lodash.isEmpty)(lineList) && /*#__PURE__*/_react["default"].createElement(_GwLayer["default"], {
    lineData: lineList,
    pointData: lineList.map(function (item) {
      var _item$geometryInfo;
      return _objectSpread(_objectSpread({}, item), {}, {
        geometryInfo: _objectSpread(_objectSpread({}, (item === null || item === void 0 ? void 0 : item.geometryInfo) || {}), {}, {
          lngLats: item === null || item === void 0 || (_item$geometryInfo = item.geometryInfo) === null || _item$geometryInfo === void 0 || (_item$geometryInfo = _item$geometryInfo.lngLats) === null || _item$geometryInfo === void 0 || (_item$geometryInfo = _item$geometryInfo.split(';')) === null || _item$geometryInfo === void 0 ? void 0 : _item$geometryInfo[0],
          type: 'point'
        })
      });
    }),
    deviceData: data.filter(function (item) {
      return item.device;
    }).map(function (item) {
      return _objectSpread(_objectSpread({}, item.device), {}, {
        geometryInfo: item.device.installLocationDTO
      });
    }),
    group: lineGroup,
    id: _config.facilityLayerId.line,
    labelField: 'name',
    template: function template(feature) {
      return /*#__PURE__*/_react["default"].createElement(Popup, {
        info: feature.values_,
        openModal: openModal
      });
    }
  }), /*#__PURE__*/_react["default"].createElement(_olMap.FeatureLayer, {
    data: manholeList,
    id: _config.facilityLayerId.manhole,
    layerControl: false,
    labelField: 'name',
    zIndex: 60,
    group: [{
      name: '正常污水窨井',
      key: "".concat(_config.facilityLayerId.manhole, "_NORMAL"),
      filter: function filter(info) {
        return !info.isAlarm;
      },
      show: !(0, _lodash.isEmpty)(manholeList),
      style: {
        type: 'Marker',
        style: {
          icon: 'WS_JG',
          color: '#FDA839'
        }
      }
    }, {
      name: '异常污水窨井',
      key: "".concat(_config.facilityLayerId.manhole, "_ERROR"),
      show: !(0, _lodash.isEmpty)(manholeList),
      style: {
        type: 'Marker',
        style: {
          icon: 'WS_JG',
          color: '#E90F0F'
        }
      },
      filter: function filter(info) {
        return info.isAlarm;
      }
    }],
    template: function template(feature) {
      return /*#__PURE__*/_react["default"].createElement(Popup, {
        info: feature.values_,
        openModal: openModal
      });
    }
  }), /*#__PURE__*/_react["default"].createElement(_olMap.FeatureLayer, {
    data: pumpStationList,
    id: _config.facilityLayerId.pump_station,
    layerControl: false,
    labelField: 'name',
    zIndex: 60,
    group: [{
      name: '正常污水泵站',
      key: "".concat(_config.facilityLayerId.pump_station, "_NORMAL"),
      filter: function filter(info) {
        return !info.isAlarm;
      },
      show: !(0, _lodash.isEmpty)(pumpStationList),
      style: {
        type: 'Marker',
        style: {
          icon: 'WSBZ',
          color: '#FDA839'
        }
      }
    }, {
      name: '异常污水泵站',
      key: "".concat(_config.facilityLayerId.pump_station, "_ERROR"),
      show: !(0, _lodash.isEmpty)(pumpStationList),
      style: {
        type: 'Marker',
        style: {
          icon: 'WSBZ',
          color: '#E90F0F'
        }
      },
      filter: function filter(info) {
        return info.isAlarm;
      }
    }],
    template: function template(feature) {
      return /*#__PURE__*/_react["default"].createElement(Popup, {
        info: feature.values_,
        openModal: openModal
      });
    }
  }), /*#__PURE__*/_react["default"].createElement(_olMap.FeatureLayer, {
    data: sewagePlantList,
    id: _config.facilityLayerId.sewage_plant,
    layerControl: false,
    labelField: 'name',
    zIndex: 60,
    group: [{
      name: '正常污水厂',
      key: "".concat(_config.facilityLayerId.sewage_plant, "_NORMAL"),
      filter: function filter(info) {
        return !info.isAlarm;
      },
      show: !(0, _lodash.isEmpty)(sewagePlantList),
      style: {
        type: 'Marker',
        style: {
          icon: 'WSC',
          color: '#FDA839'
        }
      }
    }, {
      name: '异常污水厂',
      key: "".concat(_config.facilityLayerId.sewage_plant, "_ERROR"),
      show: !(0, _lodash.isEmpty)(sewagePlantList),
      style: {
        type: 'Marker',
        style: {
          icon: 'WSC',
          color: '#E90F0F'
        }
      },
      filter: function filter(info) {
        return info.isAlarm;
      }
    }],
    template: function template(feature) {
      return /*#__PURE__*/_react["default"].createElement(Popup, {
        info: feature.values_,
        openModal: openModal
      });
    }
  }));
};
var _default = exports["default"] = MapLayer;
//# sourceMappingURL=MapLayer.js.map
