index.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var meta_1 = require("@turf/meta");
  4. /**
  5. * Takes a set of features, calculates the bbox of all input features, and returns a bounding box.
  6. *
  7. * @name bbox
  8. * @param {GeoJSON} geojson any GeoJSON object
  9. * @returns {BBox} bbox extent in [minX, minY, maxX, maxY] order
  10. * @example
  11. * var line = turf.lineString([[-74, 40], [-78, 42], [-82, 35]]);
  12. * var bbox = turf.bbox(line);
  13. * var bboxPolygon = turf.bboxPolygon(bbox);
  14. *
  15. * //addToMap
  16. * var addToMap = [line, bboxPolygon]
  17. */
  18. function bbox(geojson) {
  19. var result = [Infinity, Infinity, -Infinity, -Infinity];
  20. meta_1.coordEach(geojson, function (coord) {
  21. if (result[0] > coord[0]) {
  22. result[0] = coord[0];
  23. }
  24. if (result[1] > coord[1]) {
  25. result[1] = coord[1];
  26. }
  27. if (result[2] < coord[0]) {
  28. result[2] = coord[0];
  29. }
  30. if (result[3] < coord[1]) {
  31. result[3] = coord[1];
  32. }
  33. });
  34. return result;
  35. }
  36. bbox["default"] = bbox;
  37. exports.default = bbox;