"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 _request = require("./request");
var _analysisLayer = require("@vtx/ol-map/lib/analysis-layer");
var _Polygon = require("ol/geom/Polygon");
var _FeatureLayer = _interopRequireDefault(require("@vtx/ol-map/lib/feature-layer/FeatureLayer"));
var _ImageLayer = _interopRequireDefault(require("@vtx/ol-map/lib/image-layer/ImageLayer"));
var _react = _interopRequireDefault(require("react"));
var _http = _interopRequireDefault(require("../_util/http"));
var _style = require("ol/style");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
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; }
// 并集 or
function unionComplexArrays(arr1, arr2) {
  // 合并数组并转换为Set去除重复元素
  var uniqueElements = _toConsumableArray(new Set(arr1.concat(arr2)));
  // 将Set转换回数组
  return uniqueElements;
}
// 交集 and
function intersection(arr1, arr2) {
  if (arr1.length == 0) {
    return arr2;
  }
  return arr1.filter(function (item) {
    return arr2.includes(item);
  });
}
var getAllVisibleLayers = function getAllVisibleLayers(map) {
  var _map$layers;
  return ((_map$layers = map.layers) === null || _map$layers === void 0 ? void 0 : _map$layers.getShowKeys().map(function (_keys) {
    var layer = map.layers.getLayerByKey(_keys);
    return layer;
  })) || [];
};

// 判断是排水，供水，原水图层
var getLayerType = function getLayerType(options, activeKey) {
  var code = getCodeByOptions(options, activeKey);
  switch (code) {
    case 'line':
      return '排水图层';
    case 'point':
      return '排水图层';
    case 'water_supply_line':
      return '供水图层';
    case 'water_supply_point':
      return '供水图层';
    case 'raw_water_line':
      return '原水图层';
    case 'raw_water_point':
      return '原水图层';
    default:
      return '';
  }
};
// 根据列表找到图层的设施的code
var getCodeByOptions = function getCodeByOptions(options, activeKey) {
  var _options$find, _options$find2;
  return (options === null || options === void 0 || (_options$find = options.find(function (item) {
    return item.key == activeKey;
  })) === null || _options$find === void 0 ? void 0 : _options$find.codeField) || (options === null || options === void 0 || (_options$find2 = options.find(function (item) {
    return item.key == activeKey;
  })) === null || _options$find2 === void 0 || (_options$find2 = _options$find2.valueField) === null || _options$find2 === void 0 ? void 0 : _options$find2.code);
};
// TODO 根据code 查询所有图层的feature，此方法应该还不完善
var getfeatureByCode = function getfeatureByCode(_ref) {
  var record = _ref.record,
    map = _ref.map,
    activeKey = _ref.activeKey;
  return new Promise(function (resolve, reject) {
    var _layer$renderer_;
    var layer = map.layers.getAllLayers().find(function (_layer) {
      var _layer$group;
      return !(_layer !== null && _layer !== void 0 && _layer.viewOnly) && (_layer === null || _layer === void 0 ? void 0 : _layer.key) == activeKey || (layer === null || layer === void 0 || (_layer$group = layer.group) === null || _layer$group === void 0 || (_layer$group = _layer$group.map(function (item) {
        return item.key;
      })) === null || _layer$group === void 0 ? void 0 : _layer$group.includes(activeKey));
    });
    if (layer !== null && layer !== void 0 && (_layer$renderer_ = layer.renderer_) !== null && _layer$renderer_ !== void 0 && _layer$renderer_.image_) {
      var filter = "code = '".concat(record.code, "'");
      (0, _analysisLayer.getWFSFeatureInfoByLayer)(layer, filter).then(function (features) {
        resolve(features === null || features === void 0 ? void 0 : features[0]);
      });
    } else {
      var feature = layer === null || layer === void 0 ? void 0 : layer.getFeatureByFieldValue('facilityId', record.facilityId);
      resolve(feature);
    }
  });
};
var getActiveKeyByCode = function getActiveKeyByCode(options, code) {
  var _options$find3;
  return options === null || options === void 0 || (_options$find3 = options.find(function (item) {
    var _item$valueField;
    return ((_item$valueField = item.valueField) === null || _item$valueField === void 0 ? void 0 : _item$valueField.code) == code;
  })) === null || _options$find3 === void 0 ? void 0 : _options$find3.key;
};
var _default = exports["default"] = {
  /**
   * @description: wms图层时获取框选数据
   * @return {*}
   */
  getWmsData: function getWmsData(_ref2) {
    var layers = _ref2.layers,
      tableData = _ref2.tableData,
      callBack = _ref2.callBack,
      loadingFn = _ref2.loadingFn,
      HighLayerFn = _ref2.HighLayerFn,
      cqFilter = _ref2.cqFilter;
    (0, _analysisLayer.getWFSFeatureInfoByLayers)(layers, cqFilter).then(function (features) {
      var _features = [];
      loadingFn && loadingFn(false);
      if (features !== null && features !== void 0 && features.length) {
        _features = features;
        HighLayerFn && HighLayerFn(features);
        features.forEach(function (item) {
          var listKeys = item.getKeys();
          var _dataJson = {};
          var dataJson = item.get('data_json');
          if (dataJson) _dataJson = JSON.parse(dataJson);
          var data = {};
          listKeys.forEach(function (itemk) {
            if (item.get(itemk)) {
              data[itemk] = item.get(itemk);
              data.feature = item;
            }
          });
          tableData.push(_objectSpread(_objectSpread({}, data), _dataJson));
        });
      } else {
        // message.info('暂无数据', 2);
      }
      callBack && callBack(tableData, _features);
    });
  },
  /**
   * @description: wfs图层时获取框选数据
   * @param {*} geometry
   * @param {*} layer
   * @param {*} tableData
   * @return {*}
   */
  getWfsData: function getWfsData(_ref3) {
    var geometry = _ref3.geometry,
      layers = _ref3.layers,
      tableData = _ref3.tableData,
      callBack = _ref3.callBack,
      loadingFn = _ref3.loadingFn,
      HighLayerFn = _ref3.HighLayerFn;
    var features = [];
    var getFeatures = function getFeatures(feature, layer) {
      var listKeys = feature.getKeys();
      var data = {};
      listKeys.forEach(function (item) {
        if (feature.get(item)) {
          data[item] = feature.get(item);
          data.feature = feature;
          data.label = layer.name;
          data.codeField = layer.codeField;
        }
      });
      tableData.push(data);
      features.push(feature);
    };
    if (geometry) {
      var extent = geometry.getExtent();
      layers.map(function (layer) {
        var source = layer.getSource();
        if (source.forEachFeatureIntersectingExtent && extent) {
          source.forEachFeatureIntersectingExtent(extent, function (feature) {
            return getFeatures(feature, layer);
          });
        }
      });
    } else {
      layers.map(function (layer) {
        var source = layer.getSource();
        if (source.forEachFeature) {
          source.forEachFeature(function (feature) {
            return getFeatures(feature, layer);
          });
        }
      });
    }
    loadingFn && loadingFn(false);
    HighLayerFn && HighLayerFn(features);
    callBack && callBack(tableData);
  },
  // 获取图层下拉
  getLayerOption: function getLayerOption(map, keys) {
    var layers = getAllVisibleLayers(map);
    var layersOption = [];
    layers === null || layers === void 0 || layers.map(function (layer) {
      if (layer !== null && layer !== void 0 && layer.name) {
        if (keys) {
          if (Array.isArray(keys) && keys.includes(layer.key)) {
            layersOption.push({
              name: layer.name,
              value: layer.key,
              label: layer.name,
              codeField: layer.key
            });
          }
        } else {
          layersOption.push({
            name: layer.name,
            value: layer.key,
            label: layer.name,
            codeField: layer.key
          });
        }
      }
    });
    return layersOption;
  },
  // 获取当前tab页对应的图层的系统code
  getCode: function getCode(items, activeKey) {
    if (!activeKey) {
      return '';
    }
    var _ref4 = items.find(function (item) {
        var _item$valueField2;
        return item.key === activeKey && (item === null || item === void 0 || (_item$valueField2 = item.valueField) === null || _item$valueField2 === void 0 ? void 0 : _item$valueField2.origin) == 'facility';
      }) || {},
      _ref4$codeField = _ref4.codeField,
      codeField = _ref4$codeField === void 0 ? '' : _ref4$codeField;
    return codeField;
  },
  // 获取数据id集合
  getField: function getField() {
    var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
    var field = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'id';
    var keys = [];
    data.map(function (item) {
      if (item[field]) keys.push(item[field]);
    });
    return keys;
  },
  // 获取数据
  getData: function getData() {
    var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
    var key = arguments.length > 1 ? arguments[1] : undefined;
    var field = arguments.length > 2 ? arguments[2] : undefined;
    var _data = data === null || data === void 0 ? void 0 : data.filter(function (item) {
      return (item === null || item === void 0 ? void 0 : item[field]) === key;
    });
    return _data;
  },
  // 图层选择
  btnList: [{
    label: '框选',
    key: 'DragBox',
    isActive: false,
    icon: 'icon-kuangxuan'
  }, {
    label: '圈选',
    key: 'Circle',
    isActive: false,
    icon: 'icon-quanxuan'
  }, {
    label: '多边形选择',
    key: 'Polygon',
    isActive: false,
    icon: 'icon-duobianxingxuanze'
  }, {
    label: '当前范围',
    key: 'CurrentView',
    isActive: false,
    icon: 'icon-morenshijiao'
  }],
  CurrentExtent: {
    label: '当前范围',
    key: 'CurrentView',
    isActive: false,
    icon: 'icon-morenshijiao'
  },
  point: {
    label: '点选',
    key: 'Point',
    isActive: false,
    icon: 'icon-dianxuan'
  },
  DragBox: {
    label: '框选',
    key: 'DragBox',
    isActive: false,
    icon: 'icon-kuangxuan'
  },
  Circle: {
    label: '圈选',
    key: 'Circle',
    isActive: false,
    icon: 'icon-quanxuan'
  },
  Polygon: {
    label: '多边形选择',
    key: 'Polygon',
    isActive: false,
    icon: 'icon-duobianxingxuanze'
  },
  // 图层选择
  btnList1: [{
    label: '点选',
    key: 'Point',
    isActive: false,
    icon: 'icon-dianxuan'
  }, {
    label: '框选',
    key: 'DragBox',
    isActive: false,
    icon: 'icon-kuangxuan'
  }, {
    label: '圈选',
    key: 'Circle',
    isActive: false,
    icon: 'icon-quanxuan'
  }, {
    label: '多边形选择',
    key: 'Polygon',
    isActive: false,
    icon: 'icon-duobianxingxuanze'
  }],
  // 框选传参处理
  getCoorStr: function getCoorStr(geometry, drawType, flatCoordinates) {
    var _coordinates;
    if (!drawType) return {
      coorStr: '',
      cqFilter: ''
    };
    var coorStr = '';
    var coordinates = (geometry === null || geometry === void 0 ? void 0 : geometry.getCoordinates()) || (geometry === null || geometry === void 0 ? void 0 : geometry.flatCoordinates);

    // 圈选处理
    if (drawType === 'Circle') {
      var polygonGeometry = new _Polygon.fromCircle(geometry);
      coordinates = polygonGeometry.getCoordinates();
    }

    // 当前范围
    if (drawType === 'CurrentView') {
      coordinates = flatCoordinates;
    }
    (_coordinates = coordinates) === null || _coordinates === void 0 || (_coordinates = _coordinates[0]) === null || _coordinates === void 0 || _coordinates.forEach(function (v, i) {
      if (i == 0) {
        coorStr += "".concat(v[0], " ").concat(v[1]);
      } else {
        coorStr += ", ".concat(v[0], " ").concat(v[1]);
      }
    });
    var cqFilter = coorStr ? "INTERSECTS(geo_location, POLYGON((".concat(coorStr, ")))") : '';
    return {
      coorStr: coorStr,
      cqFilter: cqFilter
    };
  },
  //点击编码高亮
  setFieldListClick: function setFieldListClick(_ref5) {
    var record = _ref5.record,
      map = _ref5.map,
      activeKey = _ref5.activeKey,
      highLayer = _ref5.highLayer;
    getfeatureByCode({
      record: record,
      map: map,
      activeKey: activeKey
    }).then(function (feature) {
      if (feature) {
        highLayer === null || highLayer === void 0 || highLayer.clearFeatures();
        highLayer === null || highLayer === void 0 || highLayer.setHighlight([feature]);
        map === null || map === void 0 || map.showTemplate(feature);
      }
    });
  },
  //点击编码高亮 废弃 因为分析图层高亮无法控制样式
  setFieldListClickByAnalysisLayer: function setFieldListClickByAnalysisLayer(_ref6) {
    var record = _ref6.record,
      map = _ref6.map,
      analysisLayer = _ref6.analysisLayer,
      activeKey = _ref6.activeKey,
      highLayer = _ref6.highLayer;
    // analysisLayer.setCenterByCode(record.code, feature => {
    //     return [flowDirectionStyle(feature, '#2491fc')];
    // });
    getfeatureByCode({
      record: record,
      map: map,
      activeKey: activeKey
    }).then(function (feature) {
      if (feature) {
        highLayer === null || highLayer === void 0 || highLayer.clearFeatures();
        highLayer === null || highLayer === void 0 || highLayer.setHighlight([feature]);
        map === null || map === void 0 || map.showTemplate(feature);
      }
    });
  },
  // 获取设备、设施表格表头
  getFieldList: function getFieldList(setData, params, callBack) {
    var defaultData = [{
      title: '编码',
      dataIndex: 'code',
      width: 100,
      ellipsis: true,
      render: function render(_, record) {
        return /*#__PURE__*/_react["default"].createElement("a", {
          onClick: function onClick() {
            callBack && callBack((record === null || record === void 0 ? void 0 : record.CODE) || (record === null || record === void 0 ? void 0 : record.code), record);
          }
        }, (record === null || record === void 0 ? void 0 : record.CODE) || (record === null || record === void 0 ? void 0 : record.code));
      }
    }
    // {
    //     title: '名称',
    //     dataIndex: 'name',
    //     width: 100,
    // },
    ];
    // 如果没有code 直接返回默认字段
    if (!(params !== null && params !== void 0 && params.code)) {
      return new Promise(function (resolve) {
        resolve(defaultData);
      });
    }
    var isFacility = false;
    if (Array.isArray(params === null || params === void 0 ? void 0 : params.options)) {
      var obj = params === null || params === void 0 ? void 0 : params.options.find(function (item) {
        return item.valueField.code == (params === null || params === void 0 ? void 0 : params.code);
      });
      if ((obj === null || obj === void 0 ? void 0 : obj.valueField.origin) == 'facility') {
        isFacility = true;
      }
    }
    if (isFacility) {
      var url = "/cloud/jcss-reborn/facility/type/view/detail";
      return (0, _request.getDataAndSetState)({
        url: url,
        method: 'get',
        params: params
      }, setData, {
        init: {}
      }).then(function (res) {
        var _res$baseFields;
        var data = [];
        var baseFields = (res === null || res === void 0 || (_res$baseFields = res.baseFields) === null || _res$baseFields === void 0 ? void 0 : _res$baseFields.length) && res.baseFields.filter(function (r) {
          return r.tableShow || r.showKey === 'code';
        }) || [];
        var fieldLists = _toConsumableArray(baseFields);
        if (fieldLists.length) {
          fieldLists.map(function (v) {
            if (v.showKey === 'code') {
              data.push({
                title: v.showName,
                dataIndex: v.showKey,
                width: 100,
                ellipsis: true,
                render: function render(_, record) {
                  return /*#__PURE__*/_react["default"].createElement("a", {
                    onClick: function onClick(text) {
                      callBack && callBack((record === null || record === void 0 ? void 0 : record.CODE) || (record === null || record === void 0 ? void 0 : record.code), record);
                    }
                  }, (record === null || record === void 0 ? void 0 : record.CODE) || (record === null || record === void 0 ? void 0 : record.code));
                }
              });
            } else {
              data.push({
                title: v.showName,
                dataIndex: v.showKey,
                ellipsis: true,
                width: v.showKey === 'address' ? 200 : 100
              });
            }
          });
        } else {
          data = defaultData;
        }
        return data;
      });
    } else {
      return new Promise(function (resolve) {
        resolve(defaultData);
      });
    }
  },
  // 视野范围经纬度
  getExtend: function getExtend(map) {
    var extend = map.getView().calculateExtent(map.getSize());
    // 视野范围经纬度组成面-闭环
    extend = [[[extend[0], extend[1]],
    // 左下
    [extend[0], extend[3]],
    // 左上
    [extend[2], extend[3]],
    // 右上
    [extend[2], extend[1]],
    // 右下
    [extend[0], extend[1]] // 左下
    ]];
    return extend;
  },
  /**
   * @description: 获取管线总长度
   * @param {*} field
   * @return {*}
   */
  getLineTotalLength: function getLineTotalLength() {
    var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
    var field = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'length';
    var length = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2;
    var totalLength = 0;
    data === null || data === void 0 || data.forEach(function (item) {
      if (item[field]) {
        totalLength += Number(item[field]);
      }
    });
    return totalLength.toFixed(length);
  },
  getLineTotalLengthBycode: function getLineTotalLengthBycode() {
    var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
    var field = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'length';
    var length = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2;
    var totalLength = 0;
    data === null || data === void 0 || data.forEach(function (item) {
      var _item$code;
      (_item$code = item.code) === null || _item$code === void 0 || _item$code.forEach(function (v) {
        if (v[field]) {
          totalLength += Number(v[field]);
        }
      });
    });
    return totalLength.toFixed(length);
  },
  getLineTotalBycode: function getLineTotalBycode() {
    var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
    var total = 0;
    data === null || data === void 0 || data.forEach(function (item) {
      var _item$code2;
      total += ((_item$code2 = item.code) === null || _item$code2 === void 0 ? void 0 : _item$code2.length) || 0;
    });
    return total;
  },
  /**
   * @description: 获取图层key
   * @param {*} field
   * @return {*}
   */
  getAllKeys: function getAllKeys(map) {
    var keys = [];
    map.getAllLayers().map(function (layer) {
      if (layer.key) keys.push(layer.key);
    });
    return keys;
  },
  /**
   * @description: 获取显示的key
   *  其中，有些key是group下面的，拿到name 和key 就是 options
   */
  getOptions: function getOptions(map, layersConfig) {
    var options = [];
    var showkeys = map.layers.getShowKeys();
    var layers = map.layers.getAllLayers().filter(function (_layer) {
      return _layer === null || _layer === void 0 ? void 0 : _layer.show;
    });
    var wmsLayers = layers.filter(function (_layer) {
      return _layer instanceof _ImageLayer["default"];
    });
    var wfsLayers = layers.filter(function (_layer) {
      return _layer instanceof _FeatureLayer["default"];
    });
    wmsLayers.map(function (layer) {
      var _layersConfig$find, _layer$group2;
      var valueField = (layersConfig === null || layersConfig === void 0 || (_layersConfig$find = layersConfig.find(function (item) {
        return item.key == layer.name;
      })) === null || _layersConfig$find === void 0 ? void 0 : _layersConfig$find.valueField) || (layer === null || layer === void 0 ? void 0 : layer.valueField);
      if (showkeys.includes(layer.key)) {
        options.push({
          name: layer.name,
          key: layer.key,
          codeField: valueField === null || valueField === void 0 ? void 0 : valueField.code,
          label: layer.name,
          value: layer.key,
          valueField: valueField
        });
      }
      layer === null || layer === void 0 || (_layer$group2 = layer.group) === null || _layer$group2 === void 0 || _layer$group2.map(function (_group) {
        if (showkeys.includes(_group.key)) {
          var _layer$valueField;
          options.push({
            name: _group.name,
            key: _group.key,
            filter: _group.filter,
            codeField: layer === null || layer === void 0 || (_layer$valueField = layer.valueField) === null || _layer$valueField === void 0 ? void 0 : _layer$valueField.code,
            label: _group.name,
            value: _group.key,
            valueField: layer === null || layer === void 0 ? void 0 : layer.valueField
          });
        }
      });
    });
    wfsLayers.map(function (layer) {
      var _layersConfig$find2, _layer$group3;
      var valueField = (layersConfig === null || layersConfig === void 0 || (_layersConfig$find2 = layersConfig.find(function (item) {
        return item.key == layer.name;
      })) === null || _layersConfig$find2 === void 0 ? void 0 : _layersConfig$find2.valueField) || (layer === null || layer === void 0 ? void 0 : layer.valueField);
      if (showkeys.includes(layer.key)) {
        options.push({
          name: layer.name,
          key: layer.key,
          codeField: valueField === null || valueField === void 0 ? void 0 : valueField.code,
          label: layer.name,
          value: layer.key,
          valueField: valueField
        });
      }
      layer === null || layer === void 0 || (_layer$group3 = layer.group) === null || _layer$group3 === void 0 || _layer$group3.map(function (_group) {
        if (showkeys.includes(_group.key)) {
          var _layer$valueField2;
          options.push({
            name: _group.name,
            key: _group.key,
            filter: _group.filter,
            codeField: layer === null || layer === void 0 || (_layer$valueField2 = layer.valueField) === null || _layer$valueField2 === void 0 ? void 0 : _layer$valueField2.code,
            label: _group.name,
            value: _group.key,
            valueField: layer.valueField
          });
        }
      });
    });
    return options;
  },
  // 根据地图上的分析数据 拿接口里的list
  getSimpleList: function getSimpleList(_ref7) {
    var _ref7$options = _ref7.options,
      options = _ref7$options === void 0 ? [] : _ref7$options,
      _ref7$tableData = _ref7.tableData,
      tableData = _ref7$tableData === void 0 ? [] : _ref7$tableData,
      _ref7$activeKey = _ref7.activeKey,
      activeKey = _ref7$activeKey === void 0 ? '' : _ref7$activeKey;
    var option = options.find(function (_option) {
      return _option.key == activeKey;
    });
    return new Promise(function (resolve) {
      var _option$valueField, _option$valueField2;
      if (tableData.length == 0) {
        resolve({
          dataSource: []
        });
      }
      // 是设施 并且 不是FacilityLayer，即只有可能是Imagelayer
      if ((option === null || option === void 0 || (_option$valueField = option.valueField) === null || _option$valueField === void 0 ? void 0 : _option$valueField.origin) == 'facility' || (option === null || option === void 0 ? void 0 : option.valueField) == 'facilityId') {
        var _params$ids;
        var params = {
          ids: tableData === null || tableData === void 0 ? void 0 : tableData.map(function (v) {
            return v.facility_id || v.facilityId;
          }).join(',')
        };
        if (((_params$ids = params.ids) === null || _params$ids === void 0 || (_params$ids = _params$ids.split(',')) === null || _params$ids === void 0 ? void 0 : _params$ids.length) > 0) {
          var _Object$keys;
          var fmd = new FormData();
          ((_Object$keys = Object.keys(params)) === null || _Object$keys === void 0 ? void 0 : _Object$keys.length) && Object.keys(params).map(function (key) {
            fmd.append(key, params[key]);
          });
          // // 查询设施列表
          _http["default"].post("/cloud/jcss-reborn/facility/simpleList", {
            body: fmd
          }).then(function (res) {
            if (res.result === 0 && res.data) {
              var _res$data;
              resolve({
                dataSource: (_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.map(function (item) {
                  return _objectSpread(_objectSpread({}, item), tableData.find(function (_tableData) {
                    return _tableData.facilityId == item.id || _tableData.facility_id == item.id;
                  }));
                })
              });
            } else {
              resolve({
                dataSource: []
              });
            }
          });
        }
      } else if ((option === null || option === void 0 || (_option$valueField2 = option.valueField) === null || _option$valueField2 === void 0 ? void 0 : _option$valueField2.origin) == 'device'
      // &&option?.valueField?.type !== 'DeviceLayer'
      ) {
        var _Object$keys2;
        // TODO 是设备 并且 不是DeviceLayer，即只有可能是Imagelayer
        var _params = {
          ids: tableData === null || tableData === void 0 ? void 0 : tableData.map(function (v) {
            return v.id;
          }).join(',')
        };
        var _fmd = new FormData();
        ((_Object$keys2 = Object.keys(_params)) === null || _Object$keys2 === void 0 ? void 0 : _Object$keys2.length) && Object.keys(_params).map(function (key) {
          _fmd.append(key, _params[key]);
        });
        // 查询设施列表
        _http["default"].post("/cloud/device/entity/list", {
          body: _fmd
        }).then(function (res) {
          if (res.result === 0 && res.data) {
            resolve({
              dataSource: res.data.map(function (v) {
                return _objectSpread(_objectSpread({}, v), {}, {
                  typeName: v.modelName
                }, tableData.find(function (_tableData) {
                  return _tableData.code == v.code;
                }));
              })
            });
          } else {
            resolve({
              dataSource: []
            });
          }
        });
      } else {
        resolve({
          dataSource: tableData
        });
      }
    });
  },
  // 根据key获取当前图层
  getLayerByActiveKey: function getLayerByActiveKey(map, activeKey) {
    var _map$getAllLayers;
    var layer = (_map$getAllLayers = map.getAllLayers()) === null || _map$getAllLayers === void 0 ? void 0 : _map$getAllLayers.find(function (_layer) {
      var _layer$group4;
      return _layer.key == activeKey || (_layer === null || _layer === void 0 || (_layer$group4 = _layer.group) === null || _layer$group4 === void 0 ? void 0 : _layer$group4.map(function (_group) {
        return _group.key;
      }).includes(activeKey));
    });
    return layer;
  },
  // 判断该排水图层是雨水管网,污水管网,雨污合流
  getLayerTypeByLine: function getLayerTypeByLine(code) {
    switch (code) {
      case 1:
        return '雨水管网';
      case 2:
        return '污水管网';
      case 3:
        return '雨污合流';
    }
  },
  //
  getLayerTypeByLineType: function getLayerTypeByLineType(lineType) {
    switch (lineType) {
      case 1:
        return '雨水';
      case 2:
        return '污水';
      case 3:
        return '雨污';
      case 4:
        return '供水';
    }
  },
  // 判断排水还是供水   1 排水 2 供水
  getLineType: function getLineType(options, activeKey) {
    var layerType = getLayerType(options, activeKey);
    switch (layerType) {
      case '排水图层':
        return 1;
      case '供水图层':
        return 2;
      case '原水图层':
        return 3;
      default:
        return '';
    }
  },
  getCodeByOptions: getCodeByOptions,
  /**
   * @description: 点选后获取feature
   * @param {*} feature
   * @param {*} type 类型：起点、终点
   * @return {*}
   */
  getFeature: function getFeature(feature, map) {
    var type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
    return new Promise(function (resolve, reject) {
      var _feature$getGeometry;
      var coordinate = feature === null || feature === void 0 || (_feature$getGeometry = feature.getGeometry()) === null || _feature$getGeometry === void 0 ? void 0 : _feature$getGeometry.getCoordinates();
      if (coordinate) {
        var layers = map.layers.getAllLayers().filter(function (_layer) {
          return (_layer === null || _layer === void 0 ? void 0 : _layer.show) && (_layer === null || _layer === void 0 ? void 0 : _layer.name.includes(type));
        });
        (0, _analysisLayer.getWMSFeatureInfoByLayers)({
          coordinate: coordinate
        }, map, layers).then(function (features) {
          if (features && features.length) {
            resolve(features === null || features === void 0 ? void 0 : features[0]);
          } else {
            resolve(null);
          }
        });
      }
    });
  },
  getActiveKeyfromPointToLine: function getActiveKeyfromPointToLine(options, pointActiveKey) {
    var code = getCodeByOptions(options, pointActiveKey);
    var lineCode = '';
    switch (code) {
      case 'point':
        lineCode = 'line';
        break;
      case 'water_supply_point':
        lineCode = 'water_supply_line';
        break;
      case 'raw_water_point':
        lineCode = 'raw_water_line';
        break;
      default:
        break;
    }
    return getActiveKeyByCode(options, lineCode);
  },
  getFeaturesByFieldValueOpera: function getFeaturesByFieldValueOpera(_ref8) {
    var features = _ref8.features,
      dataSource = _ref8.dataSource,
      whereValue = _ref8.whereValue;
    return new Promise(function (resolve, reject) {
      var _features = features;
      var arr = [],
        results = [];
      dataSource === null || dataSource === void 0 || dataSource.map(function (_ref9) {
        var field = _ref9.field,
          operator = _ref9.operator,
          value = _ref9.value;
        if (['>', '<', '>=', '<=', '='].includes(operator)) {
          try {
            // 通过动态创建方法自动传入操作符
            var operation = operator == '=' ? '==' : operator;
            var fun = new Function('features', 'field', 'value', "return features.filter(v => v.values_[field] ".concat(operation, " value)"));
            var result = fun(_features, field, value);
            arr.push(result);
          } catch (err) {
            reject(err);
          }
        } else if (operator === '包含') {
          var _result = _features.filter(function (v) {
            var _v$values_$field;
            return ((_v$values_$field = v.values_[field]) === null || _v$values_$field === void 0 ? void 0 : _v$values_$field.indexOf(value)) !== -1;
          });
          arr.push(_result);
        }
      });
      if (whereValue == 'and') {
        arr === null || arr === void 0 || arr.map(function (_, index) {
          results = intersection(results, arr[index]);
        });
      }
      if (whereValue == 'or') {
        arr === null || arr === void 0 || arr.map(function (_, index) {
          results = unionComplexArrays(results, arr[index]);
        });
      }
      resolve(results);
    });
  }
};
//# sourceMappingURL=service.js.map
