index.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. var bbox_1 = __importDefault(require("@turf/bbox"));
  7. var helpers_1 = require("@turf/helpers");
  8. /**
  9. * Takes a {@link Feature} or {@link FeatureCollection} and returns the absolute center point of all features.
  10. *
  11. * @name center
  12. * @param {GeoJSON} geojson GeoJSON to be centered
  13. * @param {Object} [options={}] Optional parameters
  14. * @param {Object} [options.properties={}] Translate GeoJSON Properties to Point
  15. * @param {Object} [options.bbox={}] Translate GeoJSON BBox to Point
  16. * @param {Object} [options.id={}] Translate GeoJSON Id to Point
  17. * @returns {Feature<Point>} a Point feature at the absolute center point of all input features
  18. * @example
  19. * var features = turf.points([
  20. * [-97.522259, 35.4691],
  21. * [-97.502754, 35.463455],
  22. * [-97.508269, 35.463245]
  23. * ]);
  24. *
  25. * var center = turf.center(features);
  26. *
  27. * //addToMap
  28. * var addToMap = [features, center]
  29. * center.properties['marker-size'] = 'large';
  30. * center.properties['marker-color'] = '#000';
  31. */
  32. function center(geojson, options) {
  33. if (options === void 0) { options = {}; }
  34. var ext = bbox_1.default(geojson);
  35. var x = (ext[0] + ext[2]) / 2;
  36. var y = (ext[1] + ext[3]) / 2;
  37. return helpers_1.point([x, y], options.properties, options);
  38. }
  39. exports.default = center;