@dra2020/baseclient 1.0.167 → 1.0.168
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 +87 -15
- package/dist/baseclient.js.map +1 -1
- package/dist/geo/geo.d.ts +9 -3
- package/dist/poly/topovalidate.d.ts +146 -0
- package/lib/geo/geo.ts +65 -16
- package/lib/poly/polybin.ts +27 -0
- package/lib/poly/topovalidate.ts +389 -0
- package/package.json +2 -2
package/dist/baseclient.js
CHANGED
|
@@ -2768,6 +2768,10 @@ exports.geoCollectionToTopo = geoCollectionToTopo;
|
|
|
2768
2768
|
exports.geoCollectionToTopoNonNull = geoCollectionToTopoNonNull;
|
|
2769
2769
|
exports.geoTopoToCollection = geoTopoToCollection;
|
|
2770
2770
|
exports.geoTopoToCollectionNonNull = geoTopoToCollectionNonNull;
|
|
2771
|
+
exports.geoFilterFromHidden = geoFilterFromHidden;
|
|
2772
|
+
exports.geoFilteredTopo = geoFilteredTopo;
|
|
2773
|
+
exports.geoFilteredCollection = geoFilteredCollection;
|
|
2774
|
+
exports.geoFilteredMap = geoFilteredMap;
|
|
2771
2775
|
exports.geoEqual = geoEqual;
|
|
2772
2776
|
exports.geoMapEqual = geoMapEqual;
|
|
2773
2777
|
exports.geoIntersect = geoIntersect;
|
|
@@ -2944,6 +2948,37 @@ function geoTopoToCollection(topo) {
|
|
|
2944
2948
|
function geoTopoToCollectionNonNull(topo) {
|
|
2945
2949
|
return geoTopoToCollection(topo);
|
|
2946
2950
|
}
|
|
2951
|
+
function geoFilterFromHidden(hidden) {
|
|
2952
|
+
if (Util.isEmpty(hidden))
|
|
2953
|
+
return undefined;
|
|
2954
|
+
return (s) => { return !hidden[s]; };
|
|
2955
|
+
}
|
|
2956
|
+
function geoFilteredTopo(topo, filter) {
|
|
2957
|
+
if (!topo || !filter)
|
|
2958
|
+
return topo;
|
|
2959
|
+
let copy = Util.shallowCopy(topo);
|
|
2960
|
+
copy.objects = {};
|
|
2961
|
+
Object.keys(topo.objects).forEach(geoid => {
|
|
2962
|
+
if (filter(geoid))
|
|
2963
|
+
copy.objects[geoid] = topo.objects[geoid];
|
|
2964
|
+
});
|
|
2965
|
+
return copy;
|
|
2966
|
+
}
|
|
2967
|
+
function geoFilteredCollection(col, filter) {
|
|
2968
|
+
if (!col || !filter)
|
|
2969
|
+
return col;
|
|
2970
|
+
let copy = Util.shallowCopy(col);
|
|
2971
|
+
copy.features = col.features.filter(f => filter(f.properties.id));
|
|
2972
|
+
return copy;
|
|
2973
|
+
}
|
|
2974
|
+
function geoFilteredMap(map, filter) {
|
|
2975
|
+
if (!map || !filter)
|
|
2976
|
+
return map;
|
|
2977
|
+
let copy = {};
|
|
2978
|
+
Object.keys(map).forEach(geoid => { if (filter(geoid))
|
|
2979
|
+
copy[geoid] = map[geoid]; });
|
|
2980
|
+
return copy;
|
|
2981
|
+
}
|
|
2947
2982
|
function geoEqual(m1, m2) {
|
|
2948
2983
|
let n1 = m1 ? m1.length : 0;
|
|
2949
2984
|
let n2 = m2 ? m2.length : 0;
|
|
@@ -3009,12 +3044,15 @@ class GeoMultiCollection {
|
|
|
3009
3044
|
});
|
|
3010
3045
|
for (let p in multi.hidden)
|
|
3011
3046
|
if (multi.hidden.hasOwnProperty(p)) {
|
|
3012
|
-
this.hidden[p]
|
|
3013
|
-
|
|
3047
|
+
if (!this.hidden[p]) {
|
|
3048
|
+
this.hidden[p] = true;
|
|
3049
|
+
this._onChange();
|
|
3050
|
+
}
|
|
3014
3051
|
}
|
|
3015
3052
|
}
|
|
3016
3053
|
// Add the "all" collection from the passed in multi, but do not force compute of any things not computed yet.
|
|
3017
3054
|
addAll(tag, multi) {
|
|
3055
|
+
var _a;
|
|
3018
3056
|
if (multi == null || Util.isEmpty(multi.entries))
|
|
3019
3057
|
this.remove(tag);
|
|
3020
3058
|
else {
|
|
@@ -3022,11 +3060,15 @@ class GeoMultiCollection {
|
|
|
3022
3060
|
if (nEntries) {
|
|
3023
3061
|
// Make sure all collection is created
|
|
3024
3062
|
if (!multi.all.topo && !multi.all.col && !multi.all.map) {
|
|
3025
|
-
//
|
|
3026
|
-
|
|
3027
|
-
|
|
3063
|
+
// Make sure at least one all entry is built, preferably topo if there is a base topo
|
|
3064
|
+
let e = (_a = multi.entries['main']) !== null && _a !== void 0 ? _a : multi.nthEntry(0);
|
|
3065
|
+
if (nEntries > 1) {
|
|
3066
|
+
if (e.topo)
|
|
3067
|
+
multi.allTopo();
|
|
3068
|
+
else
|
|
3069
|
+
multi.allCol();
|
|
3070
|
+
}
|
|
3028
3071
|
else {
|
|
3029
|
-
let e = multi.nthEntry(0);
|
|
3030
3072
|
multi.all.topo = e.topo;
|
|
3031
3073
|
multi.all.col = e.col;
|
|
3032
3074
|
multi.all.map = e.map;
|
|
@@ -3182,19 +3224,19 @@ class GeoMultiCollection {
|
|
|
3182
3224
|
if (!this.all.topo) {
|
|
3183
3225
|
// optimise case where one entry
|
|
3184
3226
|
let n = this.nEntries;
|
|
3185
|
-
let e = this.nthEntry(0);
|
|
3227
|
+
let e = this.entries['main'] || this.nthEntry(0);
|
|
3186
3228
|
if (n == 1) {
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
this.all.
|
|
3190
|
-
this.all.
|
|
3191
|
-
this.all.map = this.all.map || e.map;
|
|
3229
|
+
let filter = geoFilterFromHidden(this.hidden);
|
|
3230
|
+
this.all.topo = geoFilteredTopo(this._topo(e), filter);
|
|
3231
|
+
this.all.col = this.all.col || geoFilteredCollection(e.col, filter);
|
|
3232
|
+
this.all.map = this.all.map || geoFilteredMap(e.map, filter);
|
|
3192
3233
|
}
|
|
3193
3234
|
else if (e.topo) {
|
|
3194
|
-
// Old-style, goes through map (to filter hidden) and then collection
|
|
3195
|
-
// this.all.topo = geoCollectionToTopoNonNull(this.allCol());
|
|
3196
3235
|
// New style, use splice on packed topologies
|
|
3197
|
-
let filterout =
|
|
3236
|
+
let filterout = this.someHidden() ? this.hidden : null; // splice function requires NULL for empty
|
|
3237
|
+
// DEBUGGING
|
|
3238
|
+
filterout = null;
|
|
3239
|
+
// DEBUGGING
|
|
3198
3240
|
let topoarray = Object.values(this.entries).filter((e) => this._length(e) > 0)
|
|
3199
3241
|
.map((e) => { return { topology: this._topo(e), filterout }; });
|
|
3200
3242
|
this.all.topo = topoarray.length == 0 ? null : topoarray.length == 1 ? topoarray[0].topology : Poly.topoSplice(topoarray);
|
|
@@ -3336,6 +3378,9 @@ class GeoMultiCollection {
|
|
|
3336
3378
|
});
|
|
3337
3379
|
return m;
|
|
3338
3380
|
}
|
|
3381
|
+
someHidden() {
|
|
3382
|
+
return !Util.isEmpty(this.hidden);
|
|
3383
|
+
}
|
|
3339
3384
|
}
|
|
3340
3385
|
exports.GeoMultiCollection = GeoMultiCollection;
|
|
3341
3386
|
var geoIntersectOptions;
|
|
@@ -9055,8 +9100,23 @@ function topoToBuffer(coder, topo) {
|
|
|
9055
9100
|
// Make sure we're packed
|
|
9056
9101
|
T.topoPack(topo);
|
|
9057
9102
|
let savepack = topo.packed;
|
|
9103
|
+
// On-disk format predates the topology.packed.objectArcs WeakMap: each object
|
|
9104
|
+
// carried its own `packedarcs: number` field in the serialized JSON. Preserve
|
|
9105
|
+
// that format. We temporarily project the WeakMap entries back onto each object
|
|
9106
|
+
// before stringifying, then strip them so the in-memory topology is unchanged.
|
|
9107
|
+
let projected = [];
|
|
9108
|
+
if (savepack.objectArcs)
|
|
9109
|
+
for (let id in topo.objects) {
|
|
9110
|
+
let o = topo.objects[id];
|
|
9111
|
+
let off = savepack.objectArcs.get(o);
|
|
9112
|
+
if (off !== undefined) {
|
|
9113
|
+
o.packedarcs = off;
|
|
9114
|
+
projected.push(o);
|
|
9115
|
+
}
|
|
9116
|
+
}
|
|
9058
9117
|
delete topo.packed;
|
|
9059
9118
|
let json = JSON.stringify(topo);
|
|
9119
|
+
projected.forEach(o => { delete o.packedarcs; });
|
|
9060
9120
|
let byteLength = HeaderSize; // 3 lengths + padding
|
|
9061
9121
|
let stringLength = sizeOfString(coder, json);
|
|
9062
9122
|
stringLength += pad(stringLength, 8);
|
|
@@ -9100,6 +9160,18 @@ function topoFromBuffer(coder, ab) {
|
|
|
9100
9160
|
topo.packed = {};
|
|
9101
9161
|
topo.packed.arcs = new Float64Array(ab, stringLength + HeaderSize, arcsByteLength / 8);
|
|
9102
9162
|
topo.packed.arcindices = new Int32Array(ab, stringLength + HeaderSize + arcsByteLength, arcindicesByteLength / 4);
|
|
9163
|
+
// Reconstruct the WeakMap from the legacy per-object `packedarcs` field, then
|
|
9164
|
+
// strip the field so the object representation matches a freshly-packed one.
|
|
9165
|
+
let objectArcs = new WeakMap();
|
|
9166
|
+
if (topo.objects)
|
|
9167
|
+
for (let id in topo.objects) {
|
|
9168
|
+
let o = topo.objects[id];
|
|
9169
|
+
if (o && o.packedarcs !== undefined) {
|
|
9170
|
+
objectArcs.set(o, o.packedarcs);
|
|
9171
|
+
delete o.packedarcs;
|
|
9172
|
+
}
|
|
9173
|
+
}
|
|
9174
|
+
topo.packed.objectArcs = objectArcs;
|
|
9103
9175
|
return topo;
|
|
9104
9176
|
}
|
|
9105
9177
|
|