"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getBox = exports["default"] = exports.computeMinMax = void 0;
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _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(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
/**
 * 兼容最小最大值
 * @param minCoordinate
 * @param maxCoordinate
 * @param gutter
 * @returns {[*,*,*,*]}
 */
var computeMinMax = function computeMinMax(minCoordinate, maxCoordinate) {
  var gutter = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0.035;
  maxCoordinate[0] = maxCoordinate[0] + gutter;
  minCoordinate[0] = minCoordinate[0] - gutter;
  maxCoordinate[1] = maxCoordinate[1] + gutter;
  minCoordinate[1] = minCoordinate[1] - gutter;
  return [minCoordinate[0], minCoordinate[1], maxCoordinate[0], maxCoordinate[1]];
};

/**
 * 获取边界
 * @param coordinates
 * @returns {[*,*,*,*]}
 */
exports.computeMinMax = computeMinMax;
var getBox = function getBox(coordinates, gutter) {
  var minCoordinate = [];
  var maxCoordinate = [];
  coordinates.forEach(function (c, index) {
    var i = index % 2;
    if (i === 0) {
      if (minCoordinate[0] === undefined || c < minCoordinate[0]) {
        minCoordinate[0] = c;
      }
      if (maxCoordinate[0] === undefined || c > maxCoordinate[0]) {
        maxCoordinate[0] = c;
      }
    } else if (i === 1) {
      if (minCoordinate[1] === undefined || c < minCoordinate[1]) {
        minCoordinate[1] = c;
      }
      if (maxCoordinate[1] === undefined || c > maxCoordinate[1]) {
        maxCoordinate[1] = c;
      }
    }
  });
  return computeMinMax(minCoordinate, maxCoordinate, gutter);
};
exports.getBox = getBox;
var _default = function _default(geoJson) {
  var coordinates = [];
  geoJson.features.map(function (feature) {
    var c = feature.geometry.coordinates.flat(Infinity);
    coordinates.push.apply(coordinates, _toConsumableArray(c));
  });
  return getBox(coordinates, 0.035);
};
exports["default"] = _default;
//# sourceMappingURL=getBBoxFromGeojson.js.map
