@dra2020/baseclient 1.0.35 → 1.0.38

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
  }
@@ -6496,6 +6509,7 @@ function featureRewind(poly) {
6496
6509
  closePoly(poly.geometry.coordinates);
6497
6510
  else if (d === 5)
6498
6511
  poly.geometry.coordinates.forEach(closePoly);
6512
+ poly.geometry.type = d === 4 ? 'Polygon' : 'MultiPolygon';
6499
6513
  }
6500
6514
  return poly;
6501
6515
  }
@@ -8278,12 +8292,15 @@ function getGEOID(f) {
8278
8292
  f = f.features[0];
8279
8293
  else if (Array.isArray(f))
8280
8294
  f = f[0];
8295
+ else
8296
+ return '';
8281
8297
  if (f.properties.id !== undefined)
8282
8298
  return 'id';
8283
8299
  if (f.properties.GEOID !== undefined)
8284
8300
  return 'GEOID';
8285
8301
  if (f.properties.GEOID10 !== undefined)
8286
8302
  return 'GEOID10';
8303
+ return '';
8287
8304
  }
8288
8305
  function topoFromCollection(col) {
8289
8306
  if (col == null)