"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 _analysisLayer = _interopRequireDefault(require("@vtx/ol-map/lib/analysis-layer"));
var _service = _interopRequireDefault(require("../_mapUtil/service"));
var _style = require("ol/style");
var _http = _interopRequireDefault(require("../_util/http"));
var _config = _interopRequireDefault(require("../_mapUtil/config"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(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 _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
var IsolatedRegionDiagnosis = exports["default"] = /*#__PURE__*/function (_AnalysisLayer) {
  _inherits(IsolatedRegionDiagnosis, _AnalysisLayer);
  var _super = _createSuper(IsolatedRegionDiagnosis);
  function IsolatedRegionDiagnosis(props) {
    var _this;
    _classCallCheck(this, IsolatedRegionDiagnosis);
    _this = _super.call(this, props);
    _this.map = props.map;
    _this.analysisLayer = {};
    _this.codesArr = [];
    _this.key = 'IsolatedRegionDiagnosis'; // 相应的分析标识
    // 孤立区域管线颜色
    _this.colors = ['#FF0000', '#FF9900', '#FFFF00', '#33FF00', '#00FFFF', '#9900FF', '#FF00FF', '#FF0066', '#FFCC00', '#CCFF00', '#00FFCC', '#CC00FF', '#FF0099', '#C43C3C', '#C4C43C', '#3CC4A9', '#3C57C4', '#A93CC4', '#C43C8D', '#A2945E', '#5EA287', '#5E79A2', '#A25E79'];
    _this.initFn();
    return _this;
  }
  _createClass(IsolatedRegionDiagnosis, [{
    key: "initFn",
    value: function initFn() {
      var _this2 = this;
      var layers = this.map.layers.getAllLayers().filter(function (_layer) {
        return _layer === null || _layer === void 0 ? void 0 : _layer.show;
      });
      this.analysisLayer = {};
      layers.map(function (v) {
        if (v.key) {
          _this2.analysisLayer[v.key] = new _analysisLayer["default"]({
            map: _this2.map,
            url: v.url,
            key: v.key,
            layerName: v.params.typeName,
            cql_filter: v.cql_filter || '',
            field: v.field || v.labelField || '',
            typeName: v.params.typeName,
            filter: v.cql_filter || '',
            otherParams: {
              // 最小缩放等级
              minZoom: 15,
              declutter: true,
              style: function style(feature) {
                return [_this2.styleFun(feature, v.key)];
              }
            }
          });
        }
      });
    }
  }, {
    key: "destroy",
    value: function destroy() {
      for (var key in this.analysisLayer) {
        var _this$analysisLayer;
        (_this$analysisLayer = this.analysisLayer) === null || _this$analysisLayer === void 0 || (_this$analysisLayer = _this$analysisLayer[key]) === null || _this$analysisLayer === void 0 || _this$analysisLayer.destroy();
      }
    }
  }, {
    key: "getData",
    value: function getData(activeKey, options, callback) {
      var _this3 = this;
      var url = "".concat(_config["default"].publicUrlZNFX, "/api/gisAnalyze/isolatedArea");
      var lineType = _service["default"].getLineType(options, activeKey);
      if (!lineType) {
        return false;
      }
      var params = {
        lineType: lineType
      };
      _http["default"].post(url, {
        body: params
      }).then(function (res) {
        var _res$data, _res$data2, _dataSource$, _res$data3;
        var dataSource = [];
        var _dataSource = Array.isArray(res === null || res === void 0 || (_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.analysisData) ? res === null || res === void 0 || (_res$data2 = res.data) === null || _res$data2 === void 0 ? void 0 : _res$data2.analysisData : Array.isArray(res === null || res === void 0 ? void 0 : res.data) ? res === null || res === void 0 ? void 0 : res.data : [];
        _this3.codesArr = [];
        _dataSource.map(function (v, i) {
          if (v !== null && v !== void 0 && v.length) {
            var layerArr = [];
            var totalLength = 0;
            v.map(function (d) {
              var length = d.length;
              if (length) {
                totalLength += Number(length);
              }
            });
            v.map(function (item, index) {
              if (item.code) {
                _this3.codesArr.push(item);
                layerArr.push(item);
              }
            });
            dataSource.push({
              num: i + 1,
              code: v,
              total: v === null || v === void 0 ? void 0 : v.length,
              totalLength: totalLength,
              id: "".concat(dataSource.length + 1),
              layer: layerArr
            });
          }
        });
        if (Array.isArray(dataSource === null || dataSource === void 0 || (_dataSource$ = dataSource[0]) === null || _dataSource$ === void 0 ? void 0 : _dataSource$.layer)) {
          var _dataSource$2;
          // this.initFn();
          _this3.loadLayer(dataSource === null || dataSource === void 0 || (_dataSource$2 = dataSource[0]) === null || _dataSource$2 === void 0 ? void 0 : _dataSource$2.layer, activeKey);
        }
        callback && callback({
          dataSource: dataSource,
          totalData: _dataSource,
          lineLength: (res === null || res === void 0 || (_res$data3 = res.data) === null || _res$data3 === void 0 ? void 0 : _res$data3.lineLength) || 0
        });
      })["catch"]();
    }
  }, {
    key: "loadLayer",
    value: function loadLayer(layer, activeKey) {
      var _this$analysisLayer$a;
      (_this$analysisLayer$a = this.analysisLayer[activeKey]) === null || _this$analysisLayer$a === void 0 || _this$analysisLayer$a.loadData(layer);
    }
    // 样式
  }, {
    key: "styleFun",
    value: function styleFun(feature, key) {
      var _this$analysisLayer2,
        _this4 = this;
      var field = (_this$analysisLayer2 = this.analysisLayer) === null || _this$analysisLayer2 === void 0 ? void 0 : _this$analysisLayer2[key].field;
      var code = feature.get(field);
      var color = null;
      this.codesArr.map(function (v, i) {
        var _v$code;
        var index = i;
        // 孤立区域取颜色，超出后循环使用
        if (i > _this4.colors.length - 1) {
          index = i - _this4.colors.length * parseInt(i / _this4.colors.length);
        }
        if (v !== null && v !== void 0 && (_v$code = v.code) !== null && _v$code !== void 0 && _v$code.includes(code)) {
          color = _this4.colors[index];
        }
      });
      return new _style.Style({
        // 高亮样式
        image: new _style.Circle({
          radius: 7,
          fill: new _style.Fill({
            color: color
          }),
          stroke: new _style.Stroke({
            color: color,
            width: 2
          })
        }),
        fill: new _style.Fill({
          color: color
        }),
        stroke: new _style.Stroke({
          color: color,
          width: 4
        })
      });
    }
  }]);
  return IsolatedRegionDiagnosis;
}(_analysisLayer["default"]);
//# sourceMappingURL=IsolatedRegionDiagnosis.js.map
