@dra2020/baseclient 1.0.16 → 1.0.19
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 +88 -7
- package/dist/baseclient.js.map +1 -1
- package/dist/geo/geo.d.ts +1 -0
- package/dist/poly/all.d.ts +1 -0
- package/dist/poly/pointinpoly.d.ts +1 -0
- package/lib/geo/geo.ts +15 -0
- package/lib/poly/all.ts +1 -0
- package/lib/poly/pointinpoly.ts +29 -0
- package/lib/poly/polybin.ts +5 -4
- package/lib/poly/polypack.ts +4 -2
- package/package.json +1 -1
package/dist/geo/geo.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ 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 function geoEnsureID(col: GeoFeatureCollection): void;
|
|
7
8
|
export declare function geoCollectionToMap(col: GeoFeatureCollection): GeoFeatureMap;
|
|
8
9
|
export declare function geoMapToCollection(map: GeoFeatureMap): GeoFeatureCollection;
|
|
9
10
|
export declare function geoCollectionToTopo(col: GeoFeatureCollection): Poly.Topo;
|
package/dist/poly/all.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function polyContainsPoint(poly: any, x: number, y: number): boolean;
|
package/lib/geo/geo.ts
CHANGED
|
@@ -7,6 +7,21 @@ export type GeoFeature = geojson.Feature;
|
|
|
7
7
|
export type GeoFeatureArray = GeoFeature[];
|
|
8
8
|
export type GeoFeatureCollection = geojson.FeatureCollection;
|
|
9
9
|
|
|
10
|
+
export function geoEnsureID(col: GeoFeatureCollection): void
|
|
11
|
+
{
|
|
12
|
+
let prop: string;
|
|
13
|
+
const props = ['id', 'GEOID', 'GEOID10', 'GEOID20', 'GEOID30' ];
|
|
14
|
+
|
|
15
|
+
if (col && col.features && col.features.length > 0)
|
|
16
|
+
{
|
|
17
|
+
let f = col.features[0];
|
|
18
|
+
if (f.properties.id !== undefined) return;
|
|
19
|
+
props.forEach(p => { if (prop === undefined && f.properties[p] !== undefined) prop = p; });
|
|
20
|
+
if (prop)
|
|
21
|
+
col.features.forEach(f => { f.properties.id = f.properties[prop] });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
10
25
|
export function geoCollectionToMap(col: GeoFeatureCollection): GeoFeatureMap
|
|
11
26
|
{
|
|
12
27
|
if (col == null) return null;
|
package/lib/poly/all.ts
CHANGED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as PP from './polypack';
|
|
2
|
+
|
|
3
|
+
export function polyContainsPoint(poly: any, x: number, y: number): boolean
|
|
4
|
+
{
|
|
5
|
+
let pp = PP.polyPack(poly);
|
|
6
|
+
if (pp == null) return false;
|
|
7
|
+
let bFound = false;
|
|
8
|
+
let bInside = false;
|
|
9
|
+
|
|
10
|
+
PP.polyPackEachRing(pp, (b: Float64Array, iPoly: number, iRing: number, iOffset: number, nPoints: number) => {
|
|
11
|
+
if (bFound) return;
|
|
12
|
+
let inside = false;
|
|
13
|
+
let iEnd = iOffset + (nPoints - 1) * 2;
|
|
14
|
+
for (let i = iOffset, j = iEnd; i < iEnd; j = i, i += 2)
|
|
15
|
+
{
|
|
16
|
+
let xi = b[i], yi = b[i+1];
|
|
17
|
+
let xj = b[j], yj = b[j+1];
|
|
18
|
+
let intersect = ((yi > y) !== (yj > y))
|
|
19
|
+
&& (x < (xj - xi) * (y - yi) / (yj - yi) + xi);
|
|
20
|
+
if (intersect) inside = !inside;
|
|
21
|
+
}
|
|
22
|
+
if (inside)
|
|
23
|
+
{
|
|
24
|
+
bFound = iRing > 0; // if inside a hole, don't need to process further
|
|
25
|
+
bInside = iRing == 0; // not inside if inside a hole
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return bInside;
|
|
29
|
+
}
|
package/lib/poly/polybin.ts
CHANGED
|
@@ -54,9 +54,10 @@ export function packCollection(coder: Util.Coder, col: any): ArrayBuffer
|
|
|
54
54
|
{
|
|
55
55
|
// Compute size
|
|
56
56
|
let pp = PP.featurePack(col) as PP.PolyPack;
|
|
57
|
-
let
|
|
57
|
+
let f: any = col.features.find((f: any) => { return f.geometry.packed ? f.geometry.packed.buffer : null });
|
|
58
|
+
let buffer: any = f ? f.geometry.packed.buffer : null;
|
|
58
59
|
let size = 16; // int endiness, offset to coordinates, float endiness
|
|
59
|
-
col.features.forEach((f: any) => { delete f.geometry.packed.buffer; }); // reconstructed when unpacking
|
|
60
|
+
col.features.forEach((f: any) => { if (f.geometry.packed) delete f.geometry.packed.buffer; }); // reconstructed when unpacking
|
|
60
61
|
let j = JSON.stringify(col);
|
|
61
62
|
size += sizeOfString(coder, j);
|
|
62
63
|
size += pad(size, 8);
|
|
@@ -84,7 +85,7 @@ export function packCollection(coder: Util.Coder, col: any): ArrayBuffer
|
|
|
84
85
|
buf64[foff++] = buf[i];
|
|
85
86
|
|
|
86
87
|
// Now restore
|
|
87
|
-
col.features.forEach((f: any) => { f.geometry.packed.buffer = buffer; });
|
|
88
|
+
col.features.forEach((f: any) => { if (f.geometry.packed) f.geometry.packed.buffer = buffer; });
|
|
88
89
|
PP.featureUnpack(col);
|
|
89
90
|
|
|
90
91
|
return ab;
|
|
@@ -144,7 +145,7 @@ export function unpackCollection(coder: Util.Coder, ab: ArrayBuffer): any
|
|
|
144
145
|
let offset = 16;
|
|
145
146
|
let j = unpackString(coder, buf8, buf32, offset);
|
|
146
147
|
col = JSON.parse(j);
|
|
147
|
-
col.features.forEach((f: any) => { f.geometry.packed.buffer = buf64 });
|
|
148
|
+
col.features.forEach((f: any) => { if (f.geometry.packed) f.geometry.packed.buffer = buf64 });
|
|
148
149
|
return col;
|
|
149
150
|
}
|
|
150
151
|
|
package/lib/poly/polypack.ts
CHANGED
|
@@ -326,7 +326,7 @@ export function polyUnpack(prepack: any): any
|
|
|
326
326
|
|
|
327
327
|
export function featurePackSize(f: any): number
|
|
328
328
|
{
|
|
329
|
-
if (f && f.geometry && f.geometry.coordinates)
|
|
329
|
+
if (f && f.geometry && f.geometry.coordinates && f.geometry.type !== 'Point')
|
|
330
330
|
return polyPackSize(f.geometry.coordinates);
|
|
331
331
|
return 0;
|
|
332
332
|
}
|
|
@@ -335,7 +335,9 @@ export function featurePack(f: any, prepack?: PolyPack): any
|
|
|
335
335
|
{
|
|
336
336
|
if (f && f.type === 'Feature')
|
|
337
337
|
{
|
|
338
|
-
if (f.geometry && f.geometry.
|
|
338
|
+
if (f.geometry && f.geometry.type === 'Point')
|
|
339
|
+
return prepack ? { offset: prepack.offset, length: 0, buffer: prepack.buffer } : { offset: 0, length: 0, buffer: null };
|
|
340
|
+
else if (f.geometry && f.geometry.coordinates)
|
|
339
341
|
{
|
|
340
342
|
f.geometry.packed = polyPack(f.geometry.coordinates, prepack);
|
|
341
343
|
delete f.geometry.coordinates;
|