@dra2020/baseclient 1.0.36 → 1.0.37

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.
@@ -5390,6 +5390,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
5390
5390
  };
5391
5391
  Object.defineProperty(exports, "__esModule", ({ value: true }));
5392
5392
  exports.polyMapTo = exports.polyMapToByCentroid = void 0;
5393
+ const P = __importStar(__webpack_require__(/*! ./poly */ "./lib/poly/poly.ts"));
5393
5394
  const PL = __importStar(__webpack_require__(/*! ./polylabel */ "./lib/poly/polylabel.ts"));
5394
5395
  const BB = __importStar(__webpack_require__(/*! ./boundbox */ "./lib/poly/boundbox.ts"));
5395
5396
  const pointinpoly_1 = __webpack_require__(/*! ./pointinpoly */ "./lib/poly/pointinpoly.ts");
@@ -5421,19 +5422,31 @@ function setLabels(c) {
5421
5422
  function polyMapToByCentroid(districts, centroids) {
5422
5423
  let map = {};
5423
5424
  // Cache district boundboxes for quick containment exclusion
5424
- let bbDistricts = districts.features.map(f => BB.boundbox(f));
5425
+ let fs = districts.features;
5426
+ let bbDistricts = fs.map(f => BB.boundbox(f));
5427
+ let aDistricts = fs.map(f => P.polyArea(f));
5425
5428
  // Walk over blocks, mapping centroid to district
5426
5429
  Object.keys(centroids).forEach(blockid => {
5427
5430
  let x = centroids[blockid].x;
5428
5431
  let y = centroids[blockid].y;
5429
5432
  let fIn = [];
5430
- districts.features.forEach((fDistrict, i) => {
5433
+ fs.forEach((fDistrict, i) => {
5431
5434
  if (BB.boundboxContains(bbDistricts[i], x, y))
5432
5435
  if (pointinpoly_1.polyContainsPoint(fDistrict, x, y))
5433
- fIn.push(fDistrict);
5436
+ fIn.push(i);
5434
5437
  });
5435
5438
  if (fIn.length == 1)
5436
- map[blockid] = fIn[0].properties.id;
5439
+ map[blockid] = fs[fIn[0]].properties.id;
5440
+ else if (fIn.length > 1) {
5441
+ // Pick district with smallest area since some times we get malformed content that doesn't
5442
+ // reflect holes in districts when one is nested in another. So theory is smaller district
5443
+ // is a hole in containing larger one(s).
5444
+ let iLow = fIn[0];
5445
+ for (let i = 1; i < fIn.length; i++)
5446
+ if (aDistricts[fIn[i]] < aDistricts[iLow])
5447
+ iLow = fIn[i];
5448
+ map[blockid] = fs[iLow].properties.id;
5449
+ }
5437
5450
  });
5438
5451
  return map;
5439
5452
  }