@dra2020/baseclient 1.0.26 → 1.0.29

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.
@@ -1429,6 +1429,7 @@ class GeoMultiCollection {
1429
1429
  this.add(tag, topo, col, map);
1430
1430
  }
1431
1431
  empty() {
1432
+ this.all = { tag: 'all' };
1432
1433
  this.entries = {};
1433
1434
  this.hidden = {};
1434
1435
  this._onChange();
@@ -1469,7 +1470,8 @@ class GeoMultiCollection {
1469
1470
  }
1470
1471
  }
1471
1472
  _onChange() {
1472
- this.all = { tag: 'all' };
1473
+ if (this.all.topo || this.all.col || this.all.map)
1474
+ this.all = { tag: 'all' };
1473
1475
  this.stamp++;
1474
1476
  }
1475
1477
  _col(e) {
@@ -1560,28 +1562,34 @@ class GeoMultiCollection {
1560
1562
  }
1561
1563
  hide(id) {
1562
1564
  if (id) {
1563
- if (typeof id === 'string')
1564
- this.hidden[id] = true;
1565
+ if (typeof id === 'string') {
1566
+ if (!this.hidden[id]) {
1567
+ this.hidden[id] = true;
1568
+ this._onChange();
1569
+ }
1570
+ }
1565
1571
  else if (Array.isArray(id))
1566
- id.forEach((i) => { this.hidden[i] = true; });
1572
+ id.forEach((i) => this.hide(i));
1567
1573
  else if (typeof id === 'object')
1568
1574
  for (let p in id)
1569
1575
  if (id.hasOwnProperty(p))
1570
- this.hidden[p] = true;
1571
- this._onChange();
1576
+ this.hide(p);
1572
1577
  }
1573
1578
  }
1574
1579
  show(id) {
1575
1580
  if (id) {
1576
- if (typeof id === 'string')
1577
- delete this.hidden[id];
1581
+ if (typeof id === 'string') {
1582
+ if (this.hidden[id]) {
1583
+ delete this.hidden[id];
1584
+ this._onChange();
1585
+ }
1586
+ }
1578
1587
  else if (Array.isArray(id))
1579
- id.forEach((i) => { delete this.hidden[i]; });
1588
+ id.forEach((i) => this.show(i));
1580
1589
  else if (typeof id === 'object')
1581
1590
  for (let p in id)
1582
1591
  if (id.hasOwnProperty(p))
1583
- delete this.hidden[p];
1584
- this._onChange();
1592
+ this.show(p);
1585
1593
  }
1586
1594
  }
1587
1595
  showAll() {
@@ -4655,6 +4663,7 @@ __exportStar(__webpack_require__(/*! ./topo */ "./lib/poly/topo.ts"), exports);
4655
4663
  __exportStar(__webpack_require__(/*! ./selfintersect */ "./lib/poly/selfintersect.ts"), exports);
4656
4664
  __exportStar(__webpack_require__(/*! ./shamos */ "./lib/poly/shamos.ts"), exports);
4657
4665
  __exportStar(__webpack_require__(/*! ./pointinpoly */ "./lib/poly/pointinpoly.ts"), exports);
4666
+ __exportStar(__webpack_require__(/*! ./mapto */ "./lib/poly/mapto.ts"), exports);
4658
4667
 
4659
4668
 
4660
4669
  /***/ }),
@@ -4740,7 +4749,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
4740
4749
  return result;
4741
4750
  };
4742
4751
  Object.defineProperty(exports, "__esModule", ({ value: true }));
4743
- exports.boundboxContains = exports.boundboxIntersects = exports.boundboxArea = exports.boundboxPoly = exports.boundbox = exports.boundboxExtend = exports.clipLon = exports.boundboxCY = exports.boundboxCX = exports.boundboxHeight = exports.boundboxWidth = void 0;
4752
+ exports.boundboxContains = exports.boundboxIntersects = exports.boundboxArea = exports.boundboxEmpty = exports.boundboxPoly = exports.boundbox = exports.boundboxExtend = exports.clipLon = exports.boundboxCY = exports.boundboxCX = exports.boundboxHeight = exports.boundboxWidth = void 0;
4744
4753
  const P = __importStar(__webpack_require__(/*! ./poly */ "./lib/poly/poly.ts"));
4745
4754
  function boundboxWidth(bb) { return Math.abs(bb.right - bb.left); }
4746
4755
  exports.boundboxWidth = boundboxWidth;
@@ -4797,7 +4806,7 @@ function boundbox(poly, bbox) {
4797
4806
  boundbox(poly[i], bbox);
4798
4807
  }
4799
4808
  // single point
4800
- else
4809
+ else if (Array.isArray(poly) && poly.length >= 2)
4801
4810
  boundboxExtend(bbox, poly[0], poly[1]);
4802
4811
  }
4803
4812
  return bbox;
@@ -4807,6 +4816,10 @@ function boundboxPoly(bb) {
4807
4816
  return [[[bb.left, bb.top], [bb.left, bb.bottom], [bb.right, bb.bottom], [bb.right, bb.top], [bb.left, bb.top]]];
4808
4817
  }
4809
4818
  exports.boundboxPoly = boundboxPoly;
4819
+ function boundboxEmpty(bb) {
4820
+ return !bb || bb.left === undefined || P.polyArea(boundboxPoly(bb)) == 0;
4821
+ }
4822
+ exports.boundboxEmpty = boundboxEmpty;
4810
4823
  function boundboxArea(poly) {
4811
4824
  return P.polyArea(boundboxPoly(boundbox(poly)));
4812
4825
  }
@@ -5329,6 +5342,88 @@ if (typeof module !== 'undefined') {
5329
5342
  */
5330
5343
 
5331
5344
 
5345
+ /***/ }),
5346
+
5347
+ /***/ "./lib/poly/mapto.ts":
5348
+ /*!***************************!*\
5349
+ !*** ./lib/poly/mapto.ts ***!
5350
+ \***************************/
5351
+ /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
5352
+
5353
+
5354
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5355
+ if (k2 === undefined) k2 = k;
5356
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5357
+ }) : (function(o, m, k, k2) {
5358
+ if (k2 === undefined) k2 = k;
5359
+ o[k2] = m[k];
5360
+ }));
5361
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
5362
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
5363
+ }) : function(o, v) {
5364
+ o["default"] = v;
5365
+ });
5366
+ var __importStar = (this && this.__importStar) || function (mod) {
5367
+ if (mod && mod.__esModule) return mod;
5368
+ var result = {};
5369
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
5370
+ __setModuleDefault(result, mod);
5371
+ return result;
5372
+ };
5373
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
5374
+ exports.polyMapTo = void 0;
5375
+ const PL = __importStar(__webpack_require__(/*! ./polylabel */ "./lib/poly/polylabel.ts"));
5376
+ const BB = __importStar(__webpack_require__(/*! ./boundbox */ "./lib/poly/boundbox.ts"));
5377
+ const pointinpoly_1 = __webpack_require__(/*! ./pointinpoly */ "./lib/poly/pointinpoly.ts");
5378
+ function setLabels(c) {
5379
+ c.features.forEach(f => {
5380
+ if (f.properties.labelx === undefined) {
5381
+ let { x, y } = PL.polyLabel(f);
5382
+ f.properties.labelx = x;
5383
+ f.properties.labely = y;
5384
+ }
5385
+ });
5386
+ }
5387
+ // polyMapTo:
5388
+ //
5389
+ // Given a set of underlying blocks (or precincts), map them to the district (or any other feature)
5390
+ // they are contained in.
5391
+ //
5392
+ // If a block maps to multiple districts or no district, it is left out of the result.
5393
+ //
5394
+ // Note that the algorithm is to see where the centroid of the block overlaps. So a block
5395
+ // could potentially overlap multiple districts and this would return only the one containing
5396
+ // the centroid.
5397
+ //
5398
+ // The thinking is that if you want fine granularity, use real blocks as the base collection.
5399
+ // If you provide precincts, you will get a result on precinct granularity.
5400
+ //
5401
+ // The return value is an object that maps the block feature ids to the district feature id.
5402
+ //
5403
+ function polyMapTo(districts, blocks) {
5404
+ let map = {};
5405
+ // Cache labelx, labely if necessary
5406
+ setLabels(blocks);
5407
+ // Cache district boundboxes for quick containment exclusion
5408
+ let bbDistricts = districts.features.map(f => BB.boundbox(f));
5409
+ // Walk over blocks, mapping centroid to district
5410
+ blocks.features.forEach(fBlock => {
5411
+ let x = fBlock.properties.labelx;
5412
+ let y = fBlock.properties.labely;
5413
+ let fIn = [];
5414
+ districts.features.forEach((fDistrict, i) => {
5415
+ if (BB.boundboxContains(bbDistricts[i], x, y))
5416
+ if (pointinpoly_1.polyContainsPoint(fDistrict, x, y))
5417
+ fIn.push(fDistrict);
5418
+ });
5419
+ if (fIn.length == 1)
5420
+ map[fBlock.properties.id] = fIn[0].properties.id;
5421
+ });
5422
+ return map;
5423
+ }
5424
+ exports.polyMapTo = polyMapTo;
5425
+
5426
+
5332
5427
  /***/ }),
5333
5428
 
5334
5429
  /***/ "./lib/poly/matrix.ts":
@@ -5782,7 +5877,7 @@ function polyContainsPoint(poly, x, y) {
5782
5877
  return;
5783
5878
  let inside = false;
5784
5879
  let iEnd = iOffset + (nPoints - 1) * 2;
5785
- for (let i = iOffset, j = iEnd; i < iEnd; j = i, i += 2) {
5880
+ for (let i = iOffset, j = iEnd; i <= iEnd; j = i, i += 2) {
5786
5881
  let xi = b[i], yi = b[i + 1];
5787
5882
  let xj = b[j], yj = b[j + 1];
5788
5883
  let intersect = ((yi > y) !== (yj > y))