@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.
package/lib/poly/mapto.ts CHANGED
@@ -38,22 +38,35 @@ export function polyMapToByCentroid(districts: G.GeoFeatureCollection, centroids
38
38
  let map: any = {};
39
39
 
40
40
  // Cache district boundboxes for quick containment exclusion
41
- let bbDistricts: BB.BoundBox[] = districts.features.map(f => BB.boundbox(f));
41
+ let fs: G.GeoFeature[] = districts.features;
42
+ let bbDistricts: BB.BoundBox[] = fs.map(f => BB.boundbox(f));
43
+ let aDistricts: number[] = fs.map(f => P.polyArea(f));
42
44
 
43
45
  // Walk over blocks, mapping centroid to district
44
46
  Object.keys(centroids).forEach(blockid => {
45
47
  let x = centroids[blockid].x;
46
48
  let y = centroids[blockid].y;
47
49
 
48
- let fIn: G.GeoFeature[] = [];
49
- districts.features.forEach((fDistrict: G.GeoFeature, i: number) => {
50
+ let fIn: number[] = [];
51
+ fs.forEach((fDistrict: G.GeoFeature, i: number) => {
50
52
  if (BB.boundboxContains(bbDistricts[i], x, y))
51
53
  if (polyContainsPoint(fDistrict, x, y))
52
- fIn.push(fDistrict);
54
+ fIn.push(i);
53
55
  });
54
56
 
55
57
  if (fIn.length == 1)
56
- map[blockid] = fIn[0].properties.id;
58
+ map[blockid] = fs[fIn[0]].properties.id;
59
+ else if (fIn.length > 1)
60
+ {
61
+ // Pick district with smallest area since some times we get malformed content that doesn't
62
+ // reflect holes in districts when one is nested in another. So theory is smaller district
63
+ // is a hole in containing larger one(s).
64
+ let iLow = fIn[0];
65
+ for (let i = 1; i < fIn.length; i++)
66
+ if (aDistricts[fIn[i]] < aDistricts[iLow])
67
+ iLow = fIn[i];
68
+ map[blockid] = fs[iLow].properties.id;
69
+ }
57
70
  });
58
71
 
59
72
  return map;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dra2020/baseclient",
3
- "version": "1.0.36",
3
+ "version": "1.0.37",
4
4
  "description": "Utility functions for Javascript projects.",
5
5
  "main": "dist/baseclient.js",
6
6
  "types": "./dist/all/all.d.ts",
@@ -40,6 +40,9 @@
40
40
  "webpack-cli": "^4.4.0"
41
41
  },
42
42
  "dependencies": {
43
+ "@dra2020/baseclient": "^1.0.36",
44
+ "@dra2020/baseserver": "^1.0.21",
45
+ "@dra2020/dra-types": "^1.8.26",
43
46
  "@dra2020/topojson-client": "^3.2.7",
44
47
  "@dra2020/topojson-server": "^3.0.103",
45
48
  "@dra2020/topojson-simplify": "^3.0.102",