@dra2020/baseclient 1.0.2 → 1.0.5
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 +35 -35
- package/dist/baseclient.js.map +1 -1
- package/dist/geo/geo.d.ts +2 -0
- package/lib/geo/geo.ts +39 -2
- package/lib/poly/topo.ts +4 -35
- package/package.json +1 -1
package/dist/geo/geo.d.ts
CHANGED
|
@@ -51,10 +51,12 @@ export declare class GeoMultiCollection {
|
|
|
51
51
|
showAll(): void;
|
|
52
52
|
get length(): number;
|
|
53
53
|
nthFeature(n: number): GeoFeature;
|
|
54
|
+
nthFilteredFeature(n: number, cb: (f: GeoFeature) => boolean): GeoFeature;
|
|
54
55
|
forEach(cb: FeatureFunc): void;
|
|
55
56
|
map(cb: (f: GeoFeature) => GeoFeature): GeoFeature[];
|
|
56
57
|
isHidden(id: string): boolean;
|
|
57
58
|
find(id: string): GeoFeature;
|
|
59
|
+
filter(test: (f: GeoFeature) => boolean): GeoMultiCollection;
|
|
58
60
|
}
|
|
59
61
|
export declare enum geoIntersectOptions {
|
|
60
62
|
Intersects = 0,
|
package/lib/geo/geo.ts
CHANGED
|
@@ -325,12 +325,37 @@ export class GeoMultiCollection
|
|
|
325
325
|
return found;
|
|
326
326
|
}
|
|
327
327
|
|
|
328
|
-
|
|
328
|
+
nthFilteredFeature(n: number, cb: (f: GeoFeature) => boolean)
|
|
329
329
|
{
|
|
330
|
+
let found: GeoFeature;
|
|
331
|
+
|
|
330
332
|
this.forEachEntry(e => {
|
|
333
|
+
if (found) return;
|
|
331
334
|
let col = this._col(e);
|
|
332
335
|
if (col)
|
|
333
|
-
|
|
336
|
+
for (let i = 0; !found && i < col.features.length; i++)
|
|
337
|
+
{
|
|
338
|
+
let f = col.features[i];
|
|
339
|
+
if (this.hidden[f.properties.id] === undefined && cb(f))
|
|
340
|
+
{
|
|
341
|
+
if (n === 0)
|
|
342
|
+
{
|
|
343
|
+
found = f;
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
n--;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
return found;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
forEach(cb: FeatureFunc): void
|
|
354
|
+
{
|
|
355
|
+
this.forEachEntry(e => {
|
|
356
|
+
let col = this._col(e);
|
|
357
|
+
if (e.col)
|
|
358
|
+
e.col.features.forEach(f => { if (this.hidden[f.properties.id] === undefined) cb(f) })
|
|
334
359
|
});
|
|
335
360
|
}
|
|
336
361
|
|
|
@@ -361,6 +386,18 @@ export class GeoMultiCollection
|
|
|
361
386
|
|
|
362
387
|
return undefined;
|
|
363
388
|
}
|
|
389
|
+
|
|
390
|
+
filter(test: (f: GeoFeature) => boolean): GeoMultiCollection
|
|
391
|
+
{
|
|
392
|
+
let m = new GeoMultiCollection();
|
|
393
|
+
this.forEachEntry(e => {
|
|
394
|
+
let col = this._col(e);
|
|
395
|
+
let features = col ? col.features.filter(test) : null;
|
|
396
|
+
if (features && features.length)
|
|
397
|
+
m.add(e.tag, null, { type: 'FeatureCollection', features: features }, null);
|
|
398
|
+
});
|
|
399
|
+
return m;
|
|
400
|
+
}
|
|
364
401
|
}
|
|
365
402
|
|
|
366
403
|
export enum geoIntersectOptions { Intersects, Bounds, BoundsCenter };
|
package/lib/poly/topo.ts
CHANGED
|
@@ -59,19 +59,6 @@ function correctGeometry(f: any): any
|
|
|
59
59
|
{
|
|
60
60
|
let multiPoly = f.geometry.coordinates;
|
|
61
61
|
|
|
62
|
-
/* Comment this out right now - might have been do to not rewinding merge output
|
|
63
|
-
// topojson will under certain circumstances return a MultiPolygon with the first Polygon containing holes
|
|
64
|
-
// that are precisely filled by a subsequent polygon. We make a secondary union pass to try to correct for this.
|
|
65
|
-
// If we have a really degenerate multipolygon (test above some number of polygons) omit this expensive pass
|
|
66
|
-
// since cleanup is unlikely.
|
|
67
|
-
if (multiPoly.length > 1 && multiPoly.length < 50)
|
|
68
|
-
{
|
|
69
|
-
let result = Q.unionPolys(multiPoly);
|
|
70
|
-
if (Util.depthof(result) == 4) result = [ result ];
|
|
71
|
-
multiPoly = result;
|
|
72
|
-
}
|
|
73
|
-
*/
|
|
74
|
-
|
|
75
62
|
// Convert degenerate MultiPolygon to Polygon
|
|
76
63
|
if (multiPoly.length == 1)
|
|
77
64
|
{
|
|
@@ -80,6 +67,9 @@ function correctGeometry(f: any): any
|
|
|
80
67
|
}
|
|
81
68
|
}
|
|
82
69
|
|
|
70
|
+
// TopoJSON does not guarantee proper winding order which messes up later processing. Fix it.
|
|
71
|
+
P.featureRewind(f);
|
|
72
|
+
|
|
83
73
|
return f;
|
|
84
74
|
}
|
|
85
75
|
|
|
@@ -318,28 +308,7 @@ export function topoMerge(topo: Topo, geoids: string[]): any
|
|
|
318
308
|
if (geoids == null || geoids.length == 0) return null;
|
|
319
309
|
let objects: any[] = [];
|
|
320
310
|
geoids.forEach((geoid) => objects.push(topo.objects[geoid]));
|
|
321
|
-
|
|
322
|
-
P.featureRewind(f);
|
|
323
|
-
|
|
324
|
-
/* Comment out for now - may be due to merge output needing to be rewound
|
|
325
|
-
// If I get a bad output from topoMerge, just do more expensive poly union. This can happen if input polygons
|
|
326
|
-
// are a little funky (in particular, if they double back along the same edge.
|
|
327
|
-
if (selfIntersectFast(f))
|
|
328
|
-
{
|
|
329
|
-
//console.log('topoMerge: patching selfIntersect');
|
|
330
|
-
let polys: any[] = [];
|
|
331
|
-
geoids.forEach((geoid) => polys.push(topoToFeature(topo, geoid).geometry.coordinates));
|
|
332
|
-
let result = Q.unionPolys(polys);
|
|
333
|
-
let depth = Util.depthof(result);
|
|
334
|
-
if (depth === 5 && result.length === 1)
|
|
335
|
-
{
|
|
336
|
-
depth = 4;
|
|
337
|
-
result = result[0];
|
|
338
|
-
}
|
|
339
|
-
f = { type: 'feature', properties: {}, geometry: { type: depth == 4 ? 'Polygon' : 'MultiPolygon', coordinates: result } };
|
|
340
|
-
}
|
|
341
|
-
*/
|
|
342
|
-
return f;
|
|
311
|
+
return correctGeometry({ type: 'Feature', properties: {}, geometry: TopoClient.merge(topo, objects) });
|
|
343
312
|
}
|
|
344
313
|
|
|
345
314
|
export function topoMergeFeatures(topo: Topo, features: any[]): any
|