@dra2020/baseclient 1.0.89 → 1.0.91
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/baseclient.js +25 -4
- package/dist/baseclient.js.map +1 -1
- package/dist/geo/geo.d.ts +2 -0
- package/lib/geo/geo.ts +31 -5
- package/package.json +1 -1
package/dist/geo/geo.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export declare type GeoCentroidMap = {
|
|
|
10
10
|
y: number;
|
|
11
11
|
};
|
|
12
12
|
};
|
|
13
|
+
export declare function dumpMetrics(): void;
|
|
13
14
|
export interface NormalizeOptions {
|
|
14
15
|
joinPolygons?: boolean;
|
|
15
16
|
checkRewind?: boolean;
|
|
@@ -72,6 +73,7 @@ export declare class GeoMultiCollection {
|
|
|
72
73
|
forEach(cb: FeatureFunc): void;
|
|
73
74
|
map(cb: (f: GeoFeature) => GeoFeature): GeoFeature[];
|
|
74
75
|
isHidden(id: string): boolean;
|
|
76
|
+
findNoHide(id: string): GeoFeature;
|
|
75
77
|
find(id: string): GeoFeature;
|
|
76
78
|
filter(test: (f: GeoFeature) => boolean): GeoMultiCollection;
|
|
77
79
|
}
|
package/lib/geo/geo.ts
CHANGED
|
@@ -8,6 +8,24 @@ export type GeoFeatureArray = GeoFeature[];
|
|
|
8
8
|
export type GeoFeatureCollection = geojson.FeatureCollection;
|
|
9
9
|
export type GeoCentroidMap = { [geoid: string]: { x: number, y: number } };
|
|
10
10
|
|
|
11
|
+
// Tracing/debugging aid
|
|
12
|
+
let metrics: { [action: string]: { count: number, total: number } } = {};
|
|
13
|
+
|
|
14
|
+
function record(action: string, total: number): void
|
|
15
|
+
{
|
|
16
|
+
if (metrics[action] === undefined)
|
|
17
|
+
metrics[action] = { count: 0, total: 0 };
|
|
18
|
+
metrics[action].count++;
|
|
19
|
+
metrics[action].total += total;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function dumpMetrics(): void
|
|
23
|
+
{
|
|
24
|
+
Object.keys(metrics).forEach(action => {
|
|
25
|
+
console.log(`G.${action}: count: ${metrics[action].count}, total: ${metrics[action].total}`);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
11
29
|
export interface NormalizeOptions
|
|
12
30
|
{
|
|
13
31
|
joinPolygons?: boolean,
|
|
@@ -128,6 +146,7 @@ export function geoNormalizeCollection(col: GeoFeatureCollection, options?: Norm
|
|
|
128
146
|
export function geoCollectionToMap(col: GeoFeatureCollection): GeoFeatureMap
|
|
129
147
|
{
|
|
130
148
|
if (col == null) return null;
|
|
149
|
+
record('coltomap', col.features.length);
|
|
131
150
|
let map: GeoFeatureMap = {};
|
|
132
151
|
col.features.forEach((f: GeoFeature) => { map[String(f.properties.id)] = f; });
|
|
133
152
|
return map;
|
|
@@ -144,6 +163,7 @@ export function geoMapToCollectionNonNull(map: GeoFeatureMap): GeoFeatureCollect
|
|
|
144
163
|
if (map == null) return null;
|
|
145
164
|
let col: GeoFeatureCollection = { type: 'FeatureCollection', features: [] };
|
|
146
165
|
Object.keys(map).forEach((geoid: string) => { col.features.push(map[geoid]) });
|
|
166
|
+
record('maptocol', col.features.length);
|
|
147
167
|
return col;
|
|
148
168
|
}
|
|
149
169
|
|
|
@@ -151,6 +171,7 @@ export function geoCollectionToTopo(col: GeoFeatureCollection): Poly.Topo
|
|
|
151
171
|
{
|
|
152
172
|
let topo = Poly.topoFromCollection(col);
|
|
153
173
|
Poly.topoPack(topo);
|
|
174
|
+
record('coltotopo', col.features.length);
|
|
154
175
|
return topo;
|
|
155
176
|
}
|
|
156
177
|
|
|
@@ -163,6 +184,7 @@ export function geoTopoToCollection(topo: Poly.Topo): GeoFeatureCollection
|
|
|
163
184
|
{
|
|
164
185
|
let col = Poly.topoToCollection(topo);
|
|
165
186
|
Poly.featurePack(col);
|
|
187
|
+
record('topotocol', col.features.length);
|
|
166
188
|
return col;
|
|
167
189
|
}
|
|
168
190
|
|
|
@@ -519,11 +541,8 @@ export class GeoMultiCollection
|
|
|
519
541
|
return this.hidden[id] !== undefined;
|
|
520
542
|
}
|
|
521
543
|
|
|
522
|
-
|
|
544
|
+
findNoHide(id: string): GeoFeature
|
|
523
545
|
{
|
|
524
|
-
if (this.hidden[id] !== undefined)
|
|
525
|
-
return undefined;
|
|
526
|
-
|
|
527
546
|
let entries = Object.values(this.entries);
|
|
528
547
|
for (let i = 0; i < entries.length; i++)
|
|
529
548
|
{
|
|
@@ -531,10 +550,17 @@ export class GeoMultiCollection
|
|
|
531
550
|
if (map[id])
|
|
532
551
|
return map[id];
|
|
533
552
|
}
|
|
534
|
-
|
|
535
553
|
return undefined;
|
|
536
554
|
}
|
|
537
555
|
|
|
556
|
+
find(id: string): GeoFeature
|
|
557
|
+
{
|
|
558
|
+
if (this.hidden[id] !== undefined)
|
|
559
|
+
return undefined;
|
|
560
|
+
|
|
561
|
+
return this.findNoHide(id);
|
|
562
|
+
}
|
|
563
|
+
|
|
538
564
|
filter(test: (f: GeoFeature) => boolean): GeoMultiCollection
|
|
539
565
|
{
|
|
540
566
|
let m = new GeoMultiCollection();
|