index.cjs 1.7 KB

12345678910111213141516171819202122232425262728293031323334
  1. "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }// index.ts
  2. var _helpers = require('@turf/helpers');
  3. var _invariant = require('@turf/invariant');
  4. var _clone = require('@turf/clone');
  5. var _d3voronoi = require('d3-voronoi'); var d3voronoi = _interopRequireWildcard(_d3voronoi);
  6. function coordsToPolygon(coords) {
  7. coords = coords.slice();
  8. coords.push(coords[0]);
  9. return _helpers.polygon.call(void 0, [coords]);
  10. }
  11. function voronoi2(points, options) {
  12. options = options || {};
  13. if (!_helpers.isObject.call(void 0, options)) throw new Error("options is invalid");
  14. const bbox = options.bbox || [-180, -85, 180, 85];
  15. if (!points) throw new Error("points is required");
  16. if (!Array.isArray(bbox)) throw new Error("bbox is invalid");
  17. _invariant.collectionOf.call(void 0, points, "Point", "points");
  18. return _helpers.featureCollection.call(void 0,
  19. d3voronoi.voronoi().x((feature) => feature.geometry.coordinates[0]).y((feature) => feature.geometry.coordinates[1]).extent([
  20. [bbox[0], bbox[1]],
  21. [bbox[2], bbox[3]]
  22. ]).polygons(points.features).map(function(coords, index) {
  23. return Object.assign(coordsToPolygon(coords), {
  24. properties: _clone.cloneProperties.call(void 0, points.features[index].properties)
  25. });
  26. })
  27. );
  28. }
  29. var turf_voronoi_default = voronoi2;
  30. exports.default = turf_voronoi_default; exports.voronoi = voronoi2;
  31. //# sourceMappingURL=index.cjs.map