@dra2020/baseclient 1.0.154 → 1.0.156

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/all.d.ts CHANGED
@@ -2,3 +2,4 @@ export * from './geo';
2
2
  export * from './vfeature';
3
3
  export * from './flexname';
4
4
  export * from './multiblockmapping';
5
+ export * from './ensurecentroid';
@@ -0,0 +1,3 @@
1
+ import * as G from './geo';
2
+ export declare function ensureCentroidInFeature(f: G.GeoFeature): void;
3
+ export declare function ensureCentroidInCollection(col: G.GeoFeatureCollection): void;
package/lib/geo/all.ts CHANGED
@@ -2,3 +2,4 @@ export * from './geo';
2
2
  export * from './vfeature';
3
3
  export * from './flexname';
4
4
  export * from './multiblockmapping';
5
+ export * from './ensurecentroid';
@@ -0,0 +1,49 @@
1
+ import * as geojson from 'geojson';
2
+ import * as Util from '../util/all'
3
+ import * as Poly from '../poly/all'
4
+ import * as G from './geo'
5
+
6
+ function oneNumberOf(f: G.GeoFeature, props: string[]): number
7
+ {
8
+ for (let i = 0; i < props.length; i++)
9
+ if (f.properties[props[i]])
10
+ return Number(f.properties[props[i]]);
11
+ return 0;
12
+ }
13
+
14
+ export function ensureCentroidInFeature(f: G.GeoFeature): void
15
+ {
16
+ if (f.geometry && f.properties.labelx === undefined)
17
+ {
18
+ f.properties.labelx = oneNumberOf(f, ['INTPTLON30', 'INTPTLON20','INTPTLON10','INTPTLON']);
19
+ f.properties.labely = oneNumberOf(f, ['INTPTLAT30', 'INTPTLAT20','INTPTLAT10','INTPTLAT']);
20
+ if (f.properties.labelx && f.properties.labely)
21
+ if (! Poly.polyContainsPoint(f, f.properties.labelx, f.properties.labely))
22
+ {
23
+ delete f.properties.labelx;
24
+ delete f.properties.labely;
25
+ }
26
+
27
+ // If internal point not specified, compute it
28
+ if (!f.properties.labelx || !f.properties.labely)
29
+ {
30
+ let result = Poly.polyLabel(f);
31
+ f.properties.labelx = Util.precisionRound(result.x, 6);
32
+ f.properties.labely = Util.precisionRound(result.y, 6);
33
+ }
34
+
35
+ delete f.properties.INTPTLAT30;
36
+ delete f.properties.INTPTLON30;
37
+ delete f.properties.INTPTLAT20;
38
+ delete f.properties.INTPTLON20;
39
+ delete f.properties.INTPTLAT10;
40
+ delete f.properties.INTPTLON10;
41
+ delete f.properties.INTPTLAT;
42
+ delete f.properties.INTPTLON;
43
+ }
44
+ }
45
+
46
+ export function ensureCentroidInCollection(col: G.GeoFeatureCollection): void
47
+ {
48
+ col.features.forEach(ensureCentroidInFeature);
49
+ }
package/lib/util/util.ts CHANGED
@@ -310,6 +310,35 @@ export function deepEqual(o1: any, o2: any, options?: EqOptions): boolean
310
310
  if (typeof o1 !== 'object' || o1 == null) return false;
311
311
  if (typeof o2 !== 'object' || o2 == null) return false;
312
312
 
313
+ // Special case Set
314
+ if (o1 instanceof Set && o2 instanceof Set)
315
+ {
316
+ if (o1.size !== o2.size) return false;
317
+ let eq = true;
318
+ o1.forEach((k: any) => { if (! o2.has(k)) eq = false });
319
+ return eq;
320
+ }
321
+
322
+ // Special case Map
323
+ if (o1 instanceof Map && o2 instanceof Map)
324
+ {
325
+ if (o1.size !== o2.size) return false;
326
+ let eq = true;
327
+ o1.forEach((v1: any, k1: any) => {
328
+ if (eq)
329
+ {
330
+ if (! o2.has(k1))
331
+ eq = false;
332
+ else
333
+ {
334
+ let v2 = o2.get(k1);
335
+ eq = deepEqual(v1, v2, options);
336
+ }
337
+ }
338
+ });
339
+ return eq;
340
+ }
341
+
313
342
  // Special case array
314
343
  if (Array.isArray(o1))
315
344
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dra2020/baseclient",
3
- "version": "1.0.154",
3
+ "version": "1.0.156",
4
4
  "description": "Utility functions for Javascript projects.",
5
5
  "main": "dist/baseclient.js",
6
6
  "types": "./dist/all/all.d.ts",