@loaders.gl/gis 3.1.0-beta.3 → 3.1.0
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/es5/bundle.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/index.js +6 -6
- package/dist/es5/lib/binary-to-geojson.js +139 -93
- package/dist/es5/lib/binary-to-geojson.js.map +1 -1
- package/dist/es5/lib/geojson-to-binary.js +377 -200
- package/dist/es5/lib/geojson-to-binary.js.map +1 -1
- package/dist/es5/lib/transform.js +24 -9
- package/dist/es5/lib/transform.js.map +1 -1
- package/dist/esm/lib/geojson-to-binary.js +13 -6
- package/dist/esm/lib/geojson-to-binary.js.map +1 -1
- package/dist/lib/geojson-to-binary.d.ts +4 -0
- package/dist/lib/geojson-to-binary.d.ts.map +1 -1
- package/dist/lib/geojson-to-binary.js +15 -11
- package/package.json +4 -4
- package/src/lib/geojson-to-binary.ts +19 -10
|
@@ -25,9 +25,12 @@ export const TEST_EXPORTS = {
|
|
|
25
25
|
secondPass
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
+
type PropArrayConstructor = Float32ArrayConstructor | Float64ArrayConstructor | ArrayConstructor;
|
|
29
|
+
|
|
28
30
|
type FirstPassData = {
|
|
29
31
|
coordLength: number;
|
|
30
32
|
numericPropKeys: string[];
|
|
33
|
+
propArrayTypes: {[key: string]: PropArrayConstructor};
|
|
31
34
|
|
|
32
35
|
pointPositionsCount: number;
|
|
33
36
|
pointFeaturesCount: number;
|
|
@@ -58,7 +61,7 @@ function firstPass(features: Feature[]): FirstPassData {
|
|
|
58
61
|
let polygonRingsCount = 0;
|
|
59
62
|
let polygonFeaturesCount = 0;
|
|
60
63
|
const coordLengths = new Set<number>();
|
|
61
|
-
const
|
|
64
|
+
const propArrayTypes = {};
|
|
62
65
|
|
|
63
66
|
for (const feature of features) {
|
|
64
67
|
const geometry = feature.geometry;
|
|
@@ -129,11 +132,9 @@ function firstPass(features: Feature[]): FirstPassData {
|
|
|
129
132
|
|
|
130
133
|
// If property has not been seen before, or if property has been numeric
|
|
131
134
|
// in all previous features, check if numeric in this feature
|
|
132
|
-
// If not numeric,
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
? isNumeric(val)
|
|
136
|
-
: numericPropKeys[key];
|
|
135
|
+
// If not numeric, Array is stored to prevent rechecking in the future
|
|
136
|
+
// Additionally, detects if 64 bit precision is required
|
|
137
|
+
propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);
|
|
137
138
|
}
|
|
138
139
|
}
|
|
139
140
|
}
|
|
@@ -152,7 +153,8 @@ function firstPass(features: Feature[]): FirstPassData {
|
|
|
152
153
|
polygonFeaturesCount,
|
|
153
154
|
|
|
154
155
|
// Array of keys whose values are always numeric
|
|
155
|
-
numericPropKeys: Object.keys(
|
|
156
|
+
numericPropKeys: Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array),
|
|
157
|
+
propArrayTypes
|
|
156
158
|
};
|
|
157
159
|
}
|
|
158
160
|
|
|
@@ -175,6 +177,7 @@ function secondPass(
|
|
|
175
177
|
polygonPositionsCount,
|
|
176
178
|
polygonObjectsCount,
|
|
177
179
|
polygonRingsCount,
|
|
180
|
+
propArrayTypes,
|
|
178
181
|
polygonFeaturesCount
|
|
179
182
|
} = firstPassData;
|
|
180
183
|
const {coordLength, numericPropKeys, PositionDataType = Float32Array} = options;
|
|
@@ -233,7 +236,8 @@ function secondPass(
|
|
|
233
236
|
for (const propName of numericPropKeys || []) {
|
|
234
237
|
// If property has been numeric in all previous features in which the property existed, check
|
|
235
238
|
// if numeric in this feature
|
|
236
|
-
|
|
239
|
+
const TypedArray = propArrayTypes[propName];
|
|
240
|
+
object.numericProps[propName] = new TypedArray(object.positions.length / coordLength);
|
|
237
241
|
}
|
|
238
242
|
}
|
|
239
243
|
|
|
@@ -457,6 +461,11 @@ function flatten(arrays): number[][] {
|
|
|
457
461
|
return [].concat(...arrays);
|
|
458
462
|
}
|
|
459
463
|
|
|
460
|
-
function
|
|
461
|
-
|
|
464
|
+
function deduceArrayType(x: any, constructor: PropArrayConstructor): PropArrayConstructor {
|
|
465
|
+
if (constructor === Array || !Number.isFinite(x)) {
|
|
466
|
+
return Array;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
// If this or previous value required 64bits use Float64Array
|
|
470
|
+
return constructor === Float64Array || Math.fround(x) !== x ? Float64Array : Float32Array;
|
|
462
471
|
}
|