@dra2020/baseclient 1.0.29 → 1.0.30

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/dist/geo/geo.d.ts CHANGED
@@ -4,6 +4,12 @@ export declare type GeoProperties = geojson.GeoJsonProperties;
4
4
  export declare type GeoFeature = geojson.Feature;
5
5
  export declare type GeoFeatureArray = GeoFeature[];
6
6
  export declare type GeoFeatureCollection = geojson.FeatureCollection;
7
+ export declare type GeoCentroidMap = {
8
+ [geoid: string]: {
9
+ x: number;
10
+ y: number;
11
+ };
12
+ };
7
13
  export declare function geoEnsureID(col: GeoFeatureCollection): void;
8
14
  export declare function geoCollectionToMap(col: GeoFeatureCollection): GeoFeatureMap;
9
15
  export declare function geoMapToCollection(map: GeoFeatureMap): GeoFeatureCollection;
@@ -1,2 +1,3 @@
1
1
  import * as G from '../geo/all';
2
+ export declare function polyMapToByCentroid(districts: G.GeoFeatureCollection, centroids: G.GeoCentroidMap): any;
2
3
  export declare function polyMapTo(districts: G.GeoFeatureCollection, blocks: G.GeoFeatureCollection): any;
package/lib/geo/geo.ts CHANGED
@@ -6,6 +6,7 @@ export type GeoProperties = geojson.GeoJsonProperties;
6
6
  export type GeoFeature = geojson.Feature;
7
7
  export type GeoFeatureArray = GeoFeature[];
8
8
  export type GeoFeatureCollection = geojson.FeatureCollection;
9
+ export type GeoCentroidMap = { [geoid: string]: { x: number, y: number } };
9
10
 
10
11
  export function geoEnsureID(col: GeoFeatureCollection): void
11
12
  {
package/lib/poly/mapto.ts CHANGED
@@ -33,21 +33,17 @@ function setLabels(c: G.GeoFeatureCollection): void
33
33
  //
34
34
  // The return value is an object that maps the block feature ids to the district feature id.
35
35
  //
36
-
37
- export function polyMapTo(districts: G.GeoFeatureCollection, blocks: G.GeoFeatureCollection): any
36
+ export function polyMapToByCentroid(districts: G.GeoFeatureCollection, centroids: G.GeoCentroidMap): any
38
37
  {
39
38
  let map: any = {};
40
39
 
41
- // Cache labelx, labely if necessary
42
- setLabels(blocks);
43
-
44
40
  // Cache district boundboxes for quick containment exclusion
45
41
  let bbDistricts: BB.BoundBox[] = districts.features.map(f => BB.boundbox(f));
46
42
 
47
43
  // Walk over blocks, mapping centroid to district
48
- blocks.features.forEach(fBlock => {
49
- let x = fBlock.properties.labelx;
50
- let y = fBlock.properties.labely;
44
+ Object.keys(centroids).forEach(blockid => {
45
+ let x = centroids[blockid].x;
46
+ let y = centroids[blockid].y;
51
47
 
52
48
  let fIn: G.GeoFeature[] = [];
53
49
  districts.features.forEach((fDistrict: G.GeoFeature, i: number) => {
@@ -57,8 +53,21 @@ export function polyMapTo(districts: G.GeoFeatureCollection, blocks: G.GeoFeatur
57
53
  });
58
54
 
59
55
  if (fIn.length == 1)
60
- map[fBlock.properties.id] = fIn[0].properties.id;
56
+ map[blockid] = fIn[0].properties.id;
61
57
  });
62
58
 
63
59
  return map;
64
60
  }
61
+
62
+ export function polyMapTo(districts: G.GeoFeatureCollection, blocks: G.GeoFeatureCollection): any
63
+ {
64
+ // Cache labelx, labely if necessary
65
+ setLabels(blocks);
66
+
67
+ let centroids: G.GeoCentroidMap = {};
68
+ blocks.features.forEach(f => {
69
+ centroids[f.properties.id] = { x: f.properties.labelx, y: f.properties.labely }
70
+ });
71
+
72
+ return polyMapToByCentroid(districts, centroids);
73
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dra2020/baseclient",
3
- "version": "1.0.29",
3
+ "version": "1.0.30",
4
4
  "description": "Utility functions for Javascript projects.",
5
5
  "main": "dist/baseclient.js",
6
6
  "types": "./dist/all/all.d.ts",