"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.transformLonLatToWGS84 = exports.transformGeometryInfoToWGS84 = exports.transformGeometry = exports.getDataByHttp = exports.createFeatureCollection = exports.createFeature = void 0;
var _http = _interopRequireDefault(require("../_util/http"));
var _mapTool = _interopRequireDefault(require("../_util/mapTool"));
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 _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
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; }
var transformLonLatToWGS84 = exports.transformLonLatToWGS84 = function transformLonLatToWGS84(lonLat, coordType) {
  var _lonLat = _toConsumableArray(lonLat).map(function (v) {
    return Number(v);
  });
  if (coordType === 'bmap') {
    var gcj = _mapTool["default"].bd09togcj02(lonLat[0], lonLat[1]);
    _lonLat = _mapTool["default"].gcj02towgs84(gcj[0], gcj[1]);
  } else if (coordType === 'amap') {
    _lonLat = _mapTool["default"].gcj02towgs84(lonLat[0], lonLat[1]);
  }
  return _lonLat;
};
var transformGeometryInfoToWGS84 = exports.transformGeometryInfoToWGS84 = function transformGeometryInfoToWGS84(lngLats, type, coordType) {
  var lngLatArr = [];
  if (lngLats) {
    if (type === 'point') {
      var _l = typeof lngLats === 'string' ? lngLats.split(',') : lngLats;
      lngLatArr = transformLonLatToWGS84(_l, coordType);
    } else if (['polygon', 'polyline'].includes(type)) {
      lngLatArr[0] = [];
      lngLats.split(';').map(function (res) {
        var _res$split = res.split(','),
          _res$split2 = _slicedToArray(_res$split, 2),
          lng = _res$split2[0],
          lat = _res$split2[1];
        lngLatArr[0].push(transformLonLatToWGS84([Number(lng), Number(lat)], coordType));
      });
    } else {
      if (Array.isArray(lngLats)) {
        lngLatArr = lngLats;
      }
    }
  }
  return lngLatArr;
};
var transformGeometry = exports.transformGeometry = function transformGeometry(geometryInfo) {
  /**
   * geometry: {
   *  "type": "Point | LineString | Polygon | MultiPoint | MultiLineString | MultiPolygon | GeometryCollection",
   *  "coordinates": []
   * }
   */

  var type = geometryInfo.type,
    lngLats = geometryInfo.lngLats,
    coordType = geometryInfo.coordType;

  /**
   * geometryInfo: {
   *  coordType: "wgs84"
   *  lngLats: "119.02486914921874,25.63890915087647"
   *  type: "point"
   * }
   */

  var _type = type.replace(/^\S/, function (s) {
    return s.toUpperCase();
  });
  return {
    type: _type,
    coordinates: transformGeometryInfoToWGS84(lngLats, type, coordType)
  };
};
var createFeature = exports.createFeature = function createFeature(v) {
  return {
    type: 'Feature',
    geometry: transformGeometry(v.geometryInfo),
    properties: _objectSpread({}, v)
  };
};
var createFeatureCollection = exports.createFeatureCollection = function createFeatureCollection(data) {
  var featureCollection = {
    type: 'FeatureCollection',
    features: []
  };
  var features = [];
  data.map(function (v) {
    if (v.geometryInfo) {
      features.push(createFeature(v));
    }
  });
  featureCollection.features = features;
  return featureCollection;
};
var getDataByHttp = exports.getDataByHttp = function getDataByHttp(url, params, method, afterGetData) {
  var request = _http["default"].get;
  if (method === 'POST' || method === 'post') {
    request = _http["default"].post;
  }
  return request(url, {
    body: params
  }).then(function (res) {
    var _res;
    res = afterGetData ? afterGetData(res) : res;
    if (url.indexOf('/geoserver/') !== -1) {
      return res;
    }
    if ((_res = res) !== null && _res !== void 0 && (_res = _res.data) !== null && _res !== void 0 && _res.length) {
      return createFeatureCollection(res.data);
    }
  });
};
//# sourceMappingURL=createFeatureCollection.js.map
