@dra2020/baseclient 1.0.29 → 1.0.32

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.
@@ -1359,6 +1359,10 @@ function geoEnsureID(col) {
1359
1359
  prop = p; });
1360
1360
  if (prop)
1361
1361
  col.features.forEach(f => { f.properties.id = f.properties[prop]; });
1362
+ else {
1363
+ let n = 1;
1364
+ col.features.forEach(f => { f.properties.id = String(n++); });
1365
+ }
1362
1366
  }
1363
1367
  }
1364
1368
  exports.geoEnsureID = geoEnsureID;
@@ -5371,7 +5375,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
5371
5375
  return result;
5372
5376
  };
5373
5377
  Object.defineProperty(exports, "__esModule", ({ value: true }));
5374
- exports.polyMapTo = void 0;
5378
+ exports.polyMapTo = exports.polyMapToByCentroid = void 0;
5375
5379
  const PL = __importStar(__webpack_require__(/*! ./polylabel */ "./lib/poly/polylabel.ts"));
5376
5380
  const BB = __importStar(__webpack_require__(/*! ./boundbox */ "./lib/poly/boundbox.ts"));
5377
5381
  const pointinpoly_1 = __webpack_require__(/*! ./pointinpoly */ "./lib/poly/pointinpoly.ts");
@@ -5400,16 +5404,14 @@ function setLabels(c) {
5400
5404
  //
5401
5405
  // The return value is an object that maps the block feature ids to the district feature id.
5402
5406
  //
5403
- function polyMapTo(districts, blocks) {
5407
+ function polyMapToByCentroid(districts, centroids) {
5404
5408
  let map = {};
5405
- // Cache labelx, labely if necessary
5406
- setLabels(blocks);
5407
5409
  // Cache district boundboxes for quick containment exclusion
5408
5410
  let bbDistricts = districts.features.map(f => BB.boundbox(f));
5409
5411
  // Walk over blocks, mapping centroid to district
5410
- blocks.features.forEach(fBlock => {
5411
- let x = fBlock.properties.labelx;
5412
- let y = fBlock.properties.labely;
5412
+ Object.keys(centroids).forEach(blockid => {
5413
+ let x = centroids[blockid].x;
5414
+ let y = centroids[blockid].y;
5413
5415
  let fIn = [];
5414
5416
  districts.features.forEach((fDistrict, i) => {
5415
5417
  if (BB.boundboxContains(bbDistricts[i], x, y))
@@ -5417,10 +5419,20 @@ function polyMapTo(districts, blocks) {
5417
5419
  fIn.push(fDistrict);
5418
5420
  });
5419
5421
  if (fIn.length == 1)
5420
- map[fBlock.properties.id] = fIn[0].properties.id;
5422
+ map[blockid] = fIn[0].properties.id;
5421
5423
  });
5422
5424
  return map;
5423
5425
  }
5426
+ exports.polyMapToByCentroid = polyMapToByCentroid;
5427
+ function polyMapTo(districts, blocks) {
5428
+ // Cache labelx, labely if necessary
5429
+ setLabels(blocks);
5430
+ let centroids = {};
5431
+ blocks.features.forEach(f => {
5432
+ centroids[f.properties.id] = { x: f.properties.labelx, y: f.properties.labely };
5433
+ });
5434
+ return polyMapToByCentroid(districts, centroids);
5435
+ }
5424
5436
  exports.polyMapTo = polyMapTo;
5425
5437
 
5426
5438
 
@@ -5872,9 +5884,19 @@ function polyContainsPoint(poly, x, y) {
5872
5884
  return false;
5873
5885
  let bFound = false;
5874
5886
  let bInside = false;
5887
+ let iCurPoly = -1;
5888
+ let bCurInside = false;
5875
5889
  PP.polyPackEachRing(pp, (b, iPoly, iRing, iOffset, nPoints) => {
5876
5890
  if (bFound)
5877
5891
  return;
5892
+ if (iRing == 0) {
5893
+ if (iCurPoly >= 0 && bCurInside) {
5894
+ bInside = true;
5895
+ bFound = true;
5896
+ }
5897
+ iCurPoly = iPoly;
5898
+ bCurInside = false;
5899
+ }
5878
5900
  let inside = false;
5879
5901
  let iEnd = iOffset + (nPoints - 1) * 2;
5880
5902
  for (let i = iOffset, j = iEnd; i <= iEnd; j = i, i += 2) {
@@ -5885,11 +5907,11 @@ function polyContainsPoint(poly, x, y) {
5885
5907
  if (intersect)
5886
5908
  inside = !inside;
5887
5909
  }
5888
- if (inside) {
5889
- bFound = iRing > 0; // if inside a hole, don't need to process further
5890
- bInside = iRing == 0; // not inside if inside a hole
5891
- }
5910
+ if (inside)
5911
+ bCurInside = iRing == 0; // not inside if inside a hole
5892
5912
  });
5913
+ if (iCurPoly >= 0 && bCurInside)
5914
+ bInside = true;
5893
5915
  return bInside;
5894
5916
  }
5895
5917
  exports.polyContainsPoint = polyContainsPoint;