index.cjs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 _meta = require('@turf/meta');
  5. var _flatten = require('@turf/flatten');
  6. var _polyclipts = require('polyclip-ts'); var polyclip = _interopRequireWildcard(_polyclipts);
  7. function dissolve(fc, options = {}) {
  8. options = options || {};
  9. if (!_helpers.isObject.call(void 0, options)) throw new Error("options is invalid");
  10. const { propertyName } = options;
  11. _invariant.collectionOf.call(void 0, fc, "Polygon", "dissolve");
  12. const outFeatures = [];
  13. if (!propertyName) {
  14. return _flatten.flatten.call(void 0,
  15. _helpers.multiPolygon.call(void 0,
  16. polyclip.union.apply(
  17. null,
  18. // List of polygons expressed as Position[][][] a.k.a. Geom[]
  19. fc.features.map(function(f) {
  20. return f.geometry.coordinates;
  21. })
  22. )
  23. )
  24. );
  25. } else {
  26. const uniquePropertyVals = {};
  27. _meta.featureEach.call(void 0, fc, function(feature) {
  28. if (feature.properties) {
  29. if (!Object.prototype.hasOwnProperty.call(
  30. uniquePropertyVals,
  31. feature.properties[propertyName]
  32. )) {
  33. uniquePropertyVals[feature.properties[propertyName]] = [];
  34. }
  35. uniquePropertyVals[feature.properties[propertyName]].push(feature);
  36. }
  37. });
  38. const vals = Object.keys(uniquePropertyVals);
  39. for (let i = 0; i < vals.length; i++) {
  40. const mp = _helpers.multiPolygon.call(void 0,
  41. polyclip.union.apply(
  42. null,
  43. // List of polygons expressed as Position[][][] a.k.a. Geom[]
  44. uniquePropertyVals[vals[i]].map(function(f) {
  45. return f.geometry.coordinates;
  46. })
  47. )
  48. );
  49. if (mp && mp.properties) {
  50. mp.properties[propertyName] = vals[i];
  51. outFeatures.push(mp);
  52. }
  53. }
  54. }
  55. return _flatten.flatten.call(void 0, _helpers.featureCollection.call(void 0, outFeatures));
  56. }
  57. var turf_dissolve_default = dissolve;
  58. exports.default = turf_dissolve_default; exports.dissolve = dissolve;
  59. //# sourceMappingURL=index.cjs.map