@dra2020/baseclient 1.0.147 → 1.0.148

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2602,7 +2602,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
2602
2602
  return result;
2603
2603
  };
2604
2604
  Object.defineProperty(exports, "__esModule", ({ value: true }));
2605
- exports.geoIntersect = exports.geoIntersectOptions = exports.GeoMultiCollection = exports.geoMapEqual = exports.geoEqual = exports.geoTopoToCollectionNonNull = exports.geoTopoToCollection = exports.geoCollectionToTopoNonNull = exports.geoCollectionToTopo = exports.geoMapToCollectionNonNull = exports.geoMapToCollection = exports.geoCollectionToMap = exports.geoNormalizeCollection = exports.geoNormalizeFeature = exports.geoEnsureID = exports.hidemapConcat = exports.dumpMetrics = void 0;
2605
+ exports.geoIntersect = exports.geoIntersectOptions = exports.GeoMultiCollection = exports.geoMapEqual = exports.geoEqual = exports.geoTopoToCollectionNonNull = exports.geoTopoToCollection = exports.geoCollectionToTopoNonNull = exports.geoCollectionToTopo = exports.geoMapToCollectionNonNull = exports.geoMapToCollection = exports.geoCollectionToMap = exports.geoNormalizeCollection = exports.geoNormalizeFeature = exports.geoEnsureID = exports.isValidId = exports.applyCanonicalID = exports.hidemapConcat = exports.dumpMetrics = void 0;
2606
2606
  const Util = __importStar(__webpack_require__(/*! ../util/all */ "./lib/util/all.ts"));
2607
2607
  const Poly = __importStar(__webpack_require__(/*! ../poly/all */ "./lib/poly/all.ts"));
2608
2608
  // Tracing/debugging aid
@@ -2628,6 +2628,26 @@ function hidemapConcat(...args) {
2628
2628
  }
2629
2629
  exports.hidemapConcat = hidemapConcat;
2630
2630
  const NormalizeAll = { joinPolygons: true, checkRewind: true, ensureID: true };
2631
+ function applyCanonicalID(col) {
2632
+ if (col && Array.isArray(col.features))
2633
+ col.features.forEach((f, n) => { f.properties.id = String(n + 1); });
2634
+ }
2635
+ exports.applyCanonicalID = applyCanonicalID;
2636
+ function isValidId(col) {
2637
+ if (!col || !Array.isArray(col.features))
2638
+ return true;
2639
+ let set = new Set();
2640
+ for (let i = 0; i < col.features.length; i++) {
2641
+ let f = col.features[i];
2642
+ if (typeof f.properties.id !== 'string')
2643
+ return false; // id must be string
2644
+ if (set.has(f.properties.id))
2645
+ return false; // id must be unique
2646
+ set.add(f.properties.id);
2647
+ }
2648
+ return true;
2649
+ }
2650
+ exports.isValidId = isValidId;
2631
2651
  // set the canonical 'id' property from the best property value.
2632
2652
  // if joinPolygons is true, we do not enforce uniqueness.
2633
2653
  //
@@ -2637,8 +2657,6 @@ function geoEnsureID(col, options) {
2637
2657
  const props = ['id', 'GEOID', 'GEOID10', 'GEOID20', 'GEOID30', 'DISTRICT', 'DISTRICTNO', 'DISTRICTNAME'];
2638
2658
  if (col && col.features && col.features.length > 0) {
2639
2659
  let f = col.features[0];
2640
- if (f.properties.id !== undefined)
2641
- return; // short-cut - assume if 'id' is set, we're all good.
2642
2660
  props.forEach(p => {
2643
2661
  if (prop === undefined)
2644
2662
  if (f.properties[p] !== undefined)
@@ -2649,12 +2667,13 @@ function geoEnsureID(col, options) {
2649
2667
  prop = p;
2650
2668
  }
2651
2669
  });
2652
- if (prop)
2670
+ if (prop) {
2653
2671
  col.features.forEach(f => { f.properties.id = f.properties[prop]; });
2654
- else {
2655
- let n = 1;
2656
- col.features.forEach(f => { f.properties.id = String(n++); });
2672
+ if (!isValidId(col))
2673
+ applyCanonicalID(col);
2657
2674
  }
2675
+ else
2676
+ applyCanonicalID(col);
2658
2677
  }
2659
2678
  }
2660
2679
  exports.geoEnsureID = geoEnsureID;