@dra2020/baseclient 1.0.98 → 1.0.100

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
@@ -10,7 +10,11 @@ export declare type GeoCentroidMap = {
10
10
  y: number;
11
11
  };
12
12
  };
13
+ export declare type HideMap = {
14
+ [id: string]: boolean;
15
+ };
13
16
  export declare function dumpMetrics(): void;
17
+ export declare function hidemapConcat(...args: HideMap[]): HideMap;
14
18
  export interface NormalizeOptions {
15
19
  joinPolygons?: boolean;
16
20
  checkRewind?: boolean;
@@ -44,7 +48,7 @@ export declare function geoMapEqual(m1: GeoFeatureMap, m2: GeoFeatureMap): boole
44
48
  export declare class GeoMultiCollection {
45
49
  entries: GeoEntryMap;
46
50
  all: GeoEntry;
47
- hidden: any;
51
+ hidden: HideMap;
48
52
  stamp: number;
49
53
  constructor(tag?: string, topo?: Poly.Topo, col?: GeoFeatureCollection, map?: GeoFeatureMap);
50
54
  empty(): void;
@@ -65,6 +69,7 @@ export declare class GeoMultiCollection {
65
69
  allCol(): GeoFeatureCollection;
66
70
  allMap(): GeoFeatureMap;
67
71
  allTopo(): Poly.Topo;
72
+ hideSetAll(hm: HideMap): void;
68
73
  hide(id: any): void;
69
74
  show(id: any): void;
70
75
  showAll(): void;
@@ -2,6 +2,7 @@ import * as FSM from '../fsm/all';
2
2
  import * as Poly from './poly';
3
3
  import * as Q from './quad';
4
4
  export declare function polyIntersects(p1: any, p2: any): boolean;
5
+ export declare function polyIntersectArea(p1: any, p2: any): number;
5
6
  export declare function polyDifference(main: any, parts: any[]): any;
6
7
  declare class FsmDifference extends FSM.Fsm {
7
8
  accum: any;
package/lib/geo/geo.ts CHANGED
@@ -7,6 +7,7 @@ export type GeoFeature = geojson.Feature;
7
7
  export type GeoFeatureArray = GeoFeature[];
8
8
  export type GeoFeatureCollection = geojson.FeatureCollection;
9
9
  export type GeoCentroidMap = { [geoid: string]: { x: number, y: number } };
10
+ export type HideMap = { [id: string]: boolean };
10
11
 
11
12
  // Tracing/debugging aid
12
13
  let metrics: { [action: string]: { count: number, total: number } } = {};
@@ -26,6 +27,15 @@ export function dumpMetrics(): void
26
27
  });
27
28
  }
28
29
 
30
+ export function hidemapConcat(...args: HideMap[]): HideMap
31
+ {
32
+ let hm: HideMap = {};
33
+
34
+ for (let i = 0; i < args.length; i++)
35
+ if (args[i]) Object.keys(args[i]).forEach(id => hm[id] = true);
36
+ return hm;
37
+ }
38
+
29
39
  export interface NormalizeOptions
30
40
  {
31
41
  joinPolygons?: boolean,
@@ -241,7 +251,7 @@ export class GeoMultiCollection
241
251
  {
242
252
  entries: GeoEntryMap;
243
253
  all: GeoEntry;
244
- hidden: any;
254
+ hidden: HideMap;
245
255
  stamp: number;
246
256
 
247
257
  constructor(tag?: string, topo?: Poly.Topo, col?: GeoFeatureCollection, map?: GeoFeatureMap)
@@ -475,6 +485,16 @@ export class GeoMultiCollection
475
485
  return this.all.topo;
476
486
  }
477
487
 
488
+ hideSetAll(hm: HideMap): void
489
+ {
490
+ // Prevents onChange when resetting to same value
491
+ if (! Util.shallowEqual(this.hidden, hm))
492
+ {
493
+ this.showAll();
494
+ this.hide(hm);
495
+ }
496
+ }
497
+
478
498
  hide(id: any): void
479
499
  {
480
500
  if (id)
package/lib/poly/union.ts CHANGED
@@ -59,6 +59,30 @@ export function polyIntersects(p1: any, p2: any): boolean
59
59
  return bIntersects;
60
60
  }
61
61
 
62
+ export function polyIntersectArea(p1: any, p2: any): number
63
+ {
64
+ let pp1 = Poly.polyNormalize(p1);
65
+ let pp2 = Poly.polyNormalize(p2);
66
+ let area: number = 0;
67
+
68
+ PP.polyPackEachRing(pp1, (buffer1: Float64Array, iPoly1: number, iRing1: number, iOffset1: number, nPoints1: number) => {
69
+ if (iRing1 == 0)
70
+ {
71
+ let c1 = unpackCoords(buffer1, iOffset1, nPoints1);
72
+ PP.polyPackEachRing(pp2, (buffer2: Float64Array, iPoly2: number, iRing2: number, iOffset2: number, nPoints2: number) => {
73
+ if (iRing2 == 0)
74
+ {
75
+ let c2 = unpackCoords(buffer2, iOffset2, nPoints2);
76
+ let result = _intersection(c1, c2);
77
+ if (result && result.length > 0)
78
+ area += Poly.polyArea(result);
79
+ }
80
+ });
81
+ }
82
+ });
83
+ return area;
84
+ }
85
+
62
86
  export function polyDifference(main: any, parts: any[]): any
63
87
  {
64
88
  main = PP.polyUnpack(coords(main));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dra2020/baseclient",
3
- "version": "1.0.98",
3
+ "version": "1.0.100",
4
4
  "description": "Utility functions for Javascript projects.",
5
5
  "main": "dist/baseclient.js",
6
6
  "types": "./dist/all/all.d.ts",