@dra2020/baseclient 1.0.36 → 1.0.39
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 +20 -4
- package/dist/baseclient.js.map +1 -1
- package/dist/util/util.d.ts +2 -1
- package/lib/poly/mapto.ts +18 -5
- package/lib/poly/poly.ts +1 -0
- package/lib/util/util.ts +3 -1
- package/package.json +4 -1
package/dist/util/util.d.ts
CHANGED
|
@@ -41,7 +41,8 @@ export interface EqOptions {
|
|
|
41
41
|
[key: string]: boolean;
|
|
42
42
|
};
|
|
43
43
|
unorderedArrays?: boolean;
|
|
44
|
-
emptyStringIsNull
|
|
44
|
+
emptyStringIsNull?: boolean;
|
|
45
|
+
epsilon?: number;
|
|
45
46
|
}
|
|
46
47
|
export declare function deepEqual(o1: any, o2: any, options?: EqOptions): boolean;
|
|
47
48
|
export declare function prettyDate(d: Date): string;
|
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
|
|
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:
|
|
49
|
-
|
|
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(
|
|
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/lib/poly/poly.ts
CHANGED
|
@@ -683,6 +683,7 @@ export function featureRewind(poly: any): any
|
|
|
683
683
|
let d = Util.depthof(poly.geometry.coordinates);
|
|
684
684
|
if (d === 4) closePoly(poly.geometry.coordinates);
|
|
685
685
|
else if (d === 5) poly.geometry.coordinates.forEach(closePoly);
|
|
686
|
+
poly.geometry.type = d === 4 ? 'Polygon' : 'MultiPolygon';
|
|
686
687
|
}
|
|
687
688
|
return poly;
|
|
688
689
|
}
|
package/lib/util/util.ts
CHANGED
|
@@ -264,12 +264,14 @@ export interface EqOptions
|
|
|
264
264
|
{
|
|
265
265
|
omitKey?: { [key: string]: boolean },
|
|
266
266
|
unorderedArrays?: boolean,
|
|
267
|
-
emptyStringIsNull
|
|
267
|
+
emptyStringIsNull?: boolean,
|
|
268
|
+
epsilon?: number,
|
|
268
269
|
}
|
|
269
270
|
|
|
270
271
|
function exactEqual(o1: any, o2: any, options?: EqOptions): boolean
|
|
271
272
|
{
|
|
272
273
|
if (o1 === o2) return true;
|
|
274
|
+
if (options && options.epsilon && typeof o1 === 'number' && typeof o2 === 'number' && Math.abs(o1-o2) < options.epsilon) return true;
|
|
273
275
|
if (options && options.emptyStringIsNull)
|
|
274
276
|
if ((o1 == null && o2 == '') || (o2 == null && o1 == ''))
|
|
275
277
|
return true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dra2020/baseclient",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.39",
|
|
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",
|