@loaders.gl/mvt 3.1.0-beta.5 → 3.1.0-beta.7
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/bundle.js +17 -13
- package/dist/es5/lib/binary-vector-tile/features-to-binary.js +18 -14
- package/dist/es5/lib/binary-vector-tile/features-to-binary.js.map +1 -1
- package/dist/es5/mvt-loader.js +1 -1
- package/dist/esm/lib/binary-vector-tile/features-to-binary.js +18 -14
- package/dist/esm/lib/binary-vector-tile/features-to-binary.js.map +1 -1
- package/dist/esm/mvt-loader.js +1 -1
- package/dist/lib/binary-vector-tile/features-to-binary.d.ts +0 -8
- package/dist/lib/binary-vector-tile/features-to-binary.d.ts.map +1 -1
- package/dist/lib/binary-vector-tile/features-to-binary.js +21 -16
- package/dist/lib/types.d.ts +4 -0
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/mvt-worker.js +17 -13
- package/package.json +4 -4
- package/src/lib/binary-vector-tile/features-to-binary.ts +25 -16
- package/src/lib/types.ts +6 -0
package/dist/bundle.js
CHANGED
|
@@ -1144,25 +1144,25 @@
|
|
|
1144
1144
|
|
|
1145
1145
|
// src/lib/binary-vector-tile/features-to-binary.ts
|
|
1146
1146
|
function featuresToBinary(features, firstPassData, options) {
|
|
1147
|
+
const propArrayTypes = extractNumericPropTypes(features);
|
|
1148
|
+
const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
|
|
1147
1149
|
return fillArrays(features, firstPassData, {
|
|
1148
|
-
numericPropKeys: options ? options.numericPropKeys :
|
|
1150
|
+
numericPropKeys: options ? options.numericPropKeys : numericPropKeys,
|
|
1151
|
+
propArrayTypes,
|
|
1149
1152
|
PositionDataType: options ? options.PositionDataType : Float32Array
|
|
1150
1153
|
});
|
|
1151
1154
|
}
|
|
1152
|
-
function
|
|
1153
|
-
const
|
|
1155
|
+
function extractNumericPropTypes(features) {
|
|
1156
|
+
const propArrayTypes = {};
|
|
1154
1157
|
for (const feature of features) {
|
|
1155
1158
|
if (feature.properties) {
|
|
1156
1159
|
for (const key in feature.properties) {
|
|
1157
|
-
const
|
|
1158
|
-
|
|
1159
|
-
const val = feature.properties[key];
|
|
1160
|
-
numericPropKeys[key] = isNumeric(val);
|
|
1161
|
-
}
|
|
1160
|
+
const val = feature.properties[key];
|
|
1161
|
+
propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);
|
|
1162
1162
|
}
|
|
1163
1163
|
}
|
|
1164
1164
|
}
|
|
1165
|
-
return
|
|
1165
|
+
return propArrayTypes;
|
|
1166
1166
|
}
|
|
1167
1167
|
function fillArrays(features, firstPassData, options) {
|
|
1168
1168
|
const {
|
|
@@ -1176,7 +1176,7 @@
|
|
|
1176
1176
|
polygonRingsCount,
|
|
1177
1177
|
polygonFeaturesCount
|
|
1178
1178
|
} = firstPassData;
|
|
1179
|
-
const { numericPropKeys, PositionDataType = Float32Array } = options;
|
|
1179
|
+
const { numericPropKeys, propArrayTypes, PositionDataType = Float32Array } = options;
|
|
1180
1180
|
const hasGlobalId = features[0] && "id" in features[0];
|
|
1181
1181
|
const coordLength = 2;
|
|
1182
1182
|
const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
|
|
@@ -1210,7 +1210,8 @@
|
|
|
1210
1210
|
};
|
|
1211
1211
|
for (const object of [points, lines, polygons]) {
|
|
1212
1212
|
for (const propName of numericPropKeys) {
|
|
1213
|
-
|
|
1213
|
+
const TypedArray = propArrayTypes[propName];
|
|
1214
|
+
object.numericProps[propName] = new TypedArray(object.positions.length / coordLength);
|
|
1214
1215
|
}
|
|
1215
1216
|
}
|
|
1216
1217
|
lines.pathIndices[linePathsCount] = linePositionsCount;
|
|
@@ -1375,8 +1376,11 @@
|
|
|
1375
1376
|
}
|
|
1376
1377
|
return props;
|
|
1377
1378
|
}
|
|
1378
|
-
function
|
|
1379
|
-
|
|
1379
|
+
function deduceArrayType(x2, constructor) {
|
|
1380
|
+
if (constructor === Array || !Number.isFinite(x2)) {
|
|
1381
|
+
return Array;
|
|
1382
|
+
}
|
|
1383
|
+
return constructor === Float64Array || Math.fround(x2) !== x2 ? Float64Array : Float32Array;
|
|
1380
1384
|
}
|
|
1381
1385
|
var init_features_to_binary = __esm({
|
|
1382
1386
|
"src/lib/binary-vector-tile/features-to-binary.ts"() {
|
|
@@ -9,35 +9,33 @@ exports.TEST_EXPORTS = void 0;
|
|
|
9
9
|
var _polygon = require("@math.gl/polygon");
|
|
10
10
|
|
|
11
11
|
function featuresToBinary(features, firstPassData, options) {
|
|
12
|
+
const propArrayTypes = extractNumericPropTypes(features);
|
|
13
|
+
const numericPropKeys = Object.keys(propArrayTypes).filter(k => propArrayTypes[k] !== Array);
|
|
12
14
|
return fillArrays(features, firstPassData, {
|
|
13
|
-
numericPropKeys: options ? options.numericPropKeys :
|
|
15
|
+
numericPropKeys: options ? options.numericPropKeys : numericPropKeys,
|
|
16
|
+
propArrayTypes,
|
|
14
17
|
PositionDataType: options ? options.PositionDataType : Float32Array
|
|
15
18
|
});
|
|
16
19
|
}
|
|
17
20
|
|
|
18
21
|
const TEST_EXPORTS = {
|
|
19
|
-
extractNumericPropKeys,
|
|
20
22
|
fillArrays
|
|
21
23
|
};
|
|
22
24
|
exports.TEST_EXPORTS = TEST_EXPORTS;
|
|
23
25
|
|
|
24
|
-
function
|
|
25
|
-
const
|
|
26
|
+
function extractNumericPropTypes(features) {
|
|
27
|
+
const propArrayTypes = {};
|
|
26
28
|
|
|
27
29
|
for (const feature of features) {
|
|
28
30
|
if (feature.properties) {
|
|
29
31
|
for (const key in feature.properties) {
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
if (numericSoFar || numericSoFar === undefined) {
|
|
33
|
-
const val = feature.properties[key];
|
|
34
|
-
numericPropKeys[key] = isNumeric(val);
|
|
35
|
-
}
|
|
32
|
+
const val = feature.properties[key];
|
|
33
|
+
propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);
|
|
36
34
|
}
|
|
37
35
|
}
|
|
38
36
|
}
|
|
39
37
|
|
|
40
|
-
return
|
|
38
|
+
return propArrayTypes;
|
|
41
39
|
}
|
|
42
40
|
|
|
43
41
|
function fillArrays(features, firstPassData, options) {
|
|
@@ -54,6 +52,7 @@ function fillArrays(features, firstPassData, options) {
|
|
|
54
52
|
} = firstPassData;
|
|
55
53
|
const {
|
|
56
54
|
numericPropKeys,
|
|
55
|
+
propArrayTypes,
|
|
57
56
|
PositionDataType = Float32Array
|
|
58
57
|
} = options;
|
|
59
58
|
const hasGlobalId = features[0] && 'id' in features[0];
|
|
@@ -90,7 +89,8 @@ function fillArrays(features, firstPassData, options) {
|
|
|
90
89
|
|
|
91
90
|
for (const object of [points, lines, polygons]) {
|
|
92
91
|
for (const propName of numericPropKeys) {
|
|
93
|
-
|
|
92
|
+
const TypedArray = propArrayTypes[propName];
|
|
93
|
+
object.numericProps[propName] = new TypedArray(object.positions.length / coordLength);
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
|
|
@@ -332,7 +332,11 @@ function keepStringProperties(properties, numericKeys) {
|
|
|
332
332
|
return props;
|
|
333
333
|
}
|
|
334
334
|
|
|
335
|
-
function
|
|
336
|
-
|
|
335
|
+
function deduceArrayType(x, constructor) {
|
|
336
|
+
if (constructor === Array || !Number.isFinite(x)) {
|
|
337
|
+
return Array;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
return constructor === Float64Array || Math.fround(x) !== x ? Float64Array : Float32Array;
|
|
337
341
|
}
|
|
338
342
|
//# sourceMappingURL=features-to-binary.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/binary-vector-tile/features-to-binary.ts"],"names":["featuresToBinary","features","firstPassData","options","fillArrays","numericPropKeys","extractNumericPropKeys","PositionDataType","Float32Array","TEST_EXPORTS","feature","properties","key","numericSoFar","undefined","val","isNumeric","Object","keys","filter","k","pointPositionsCount","pointFeaturesCount","linePositionsCount","linePathsCount","lineFeaturesCount","polygonPositionsCount","polygonObjectsCount","polygonRingsCount","polygonFeaturesCount","hasGlobalId","coordLength","GlobalFeatureIdsDataType","length","Uint32Array","Uint16Array","points","positions","globalFeatureIds","featureIds","numericProps","fields","lines","pathIndices","polygons","polygonIndices","primitivePolygonIndices","triangles","object","propName","indexMap","pointPosition","pointFeature","linePosition","linePath","lineFeature","polygonPosition","polygonObject","polygonRing","polygonFeature","geometry","type","handlePoint","push","keepStringProperties","id","handleLineString","handlePolygon","Error","makeAccessorObjects","set","data","nPositions","fillNumericProperties","fill","i","il","start","end","l","ll","startPosition","areas","nextLines","endPosition","triangulatePolygon","polygonPositions","subarray","offset","holes","slice","map","n","indices","t","tl","returnObj","value","size","geomType","numericProp","index","numericPropName","numericKeys","props","includes","x","Number","isFinite"],"mappings":";;;;;;;;AACA;;AAwBO,SAASA,gBAAT,CACLC,QADK,EAELC,aAFK,EAGLC,OAHK,EAIL;AACA,SAAOC,UAAU,CAACH,QAAD,EAAWC,aAAX,EAA0B;AACzCG,IAAAA,eAAe,EAAEF,OAAO,GAAGA,OAAO,CAACE,eAAX,GAA6BC,sBAAsB,CAACL,QAAD,CADlC;AAEzCM,IAAAA,gBAAgB,EAAEJ,OAAO,GAAGA,OAAO,CAACI,gBAAX,GAA8BC;AAFd,GAA1B,CAAjB;AAID;;AAEM,MAAMC,YAAY,GAAG;AAC1BH,EAAAA,sBAD0B;AAE1BF,EAAAA;AAF0B,CAArB;;;AAWP,SAASE,sBAAT,CAAgCL,QAAhC,EAA4E;AAC1E,QAAMI,eAAe,GAAG,EAAxB;;AACA,OAAK,MAAMK,OAAX,IAAsBT,QAAtB,EAAgC;AAC9B,QAAIS,OAAO,CAACC,UAAZ,EAAwB;AACtB,WAAK,MAAMC,GAAX,IAAkBF,OAAO,CAACC,UAA1B,EAAsC;AAIpC,cAAME,YAAY,GAAGR,eAAe,CAACO,GAAD,CAApC;;AACA,YAAIC,YAAY,IAAIA,YAAY,KAAKC,SAArC,EAAgD;AAC9C,gB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AJF,EAKQ;AACN,OAAK,MAAMqE,eAAX,IAA8BtD,MAAM,CAACR,YAArC,EAAmD;AACjD,QAAI8D,eAAe,IAAI3F,UAAvB,EAAmC;AACjCqC,MAAAA,MAAM,CAACR,YAAP,CAAoB8D,eAApB,EAAqC5B,IAArC,CAA0C/D,UAAU,CAAC2F,eAAD,CAApD,EAAuED,KAAvE,EAA8EA,KAAK,GAAGpE,MAAtF;AACD;AACF;AACF;;AASD,SAAS+B,oBAAT,CACErD,UADF,EAEE4F,WAFF,EAGE;AACA,QAAMC,KAAK,GAAG,EAAd;;AACA,OAAK,MAAM5F,GAAX,IAAkBD,UAAlB,EAA8B;AAC5B,QAAI,CAAC4F,WAAW,CAACE,QAAZ,CAAqB7F,GAArB,CAAL,EAAgC;AAC9B4F,MAAAA,KAAK,CAAC5F,GAAD,CAAL,GAAaD,UAAU,CAACC,GAAD,CAAvB;AACD;AACF;;AACD,SAAO4F,KAAP;AACD;;AAED,SAASxF,SAAT,CAAmB0F,CAAnB,EAA+B;AAC7B,SAAOC,MAAM,CAACC,QAAP,CAAgBF,CAAhB,CAAP;AACD","sourcesContent":["/* eslint-disable indent */\nimport {earcut} from '@math.gl/polygon';\nimport {\n MvtBinaryCoordinates,\n MvtBinaryGeometry,\n MvtBinaryOptions,\n MvtFirstPassedData,\n MvtLines,\n MvtPoints,\n MvtPolygons\n} from '../types';\n\n/**\n * Convert binary features to flat binary arrays. Similar to\n * `geojsonToBinary` helper function, except that it expects\n * a binary representation of the feature data, which enables\n * 2X-3X speed increase in parse speed, compared to using\n * geoJSON. See `binary-vector-tile/VectorTileFeature` for\n * data format detais\n *\n * @param features\n * @param firstPassData\n * @param options\n * @returns filled arrays\n */\nexport function featuresToBinary(\n features: MvtBinaryCoordinates[],\n firstPassData: MvtFirstPassedData,\n options?: MvtBinaryOptions\n) {\n return fillArrays(features, firstPassData, {\n numericPropKeys: options ? options.numericPropKeys : extractNumericPropKeys(features),\n PositionDataType: options ? options.PositionDataType : Float32Array\n });\n}\n\nexport const TEST_EXPORTS = {\n extractNumericPropKeys,\n fillArrays\n};\n\n/**\n * Extracts properties that are always numeric\n *\n * @param features\n * @returns object with numeric keys\n */\nfunction extractNumericPropKeys(features: MvtBinaryCoordinates[]): string[] {\n const numericPropKeys = {};\n for (const feature of features) {\n if (feature.properties) {\n for (const key in feature.properties) {\n // If property has not been seen before, or if property has been numeric\n // in all previous features, check if numeric in this feature\n // If not numeric, false is stored to prevent rechecking in the future\n const numericSoFar = numericPropKeys[key];\n if (numericSoFar || numericSoFar === undefined) {\n const val = feature.properties[key];\n numericPropKeys[key] = isNumeric(val);\n }\n }\n }\n }\n\n return Object.keys(numericPropKeys).filter((k) => numericPropKeys[k]);\n}\n\n/**\n * Fills coordinates into pre-allocated typed arrays\n *\n * @param features\n * @param firstPassData\n * @param options\n * @returns an accessor object with value and size keys\n */\n// eslint-disable-next-line complexity\nfunction fillArrays(\n features: MvtBinaryCoordinates[],\n firstPassData: MvtFirstPassedData,\n options: MvtBinaryOptions\n) {\n const {\n pointPositionsCount,\n pointFeaturesCount,\n linePositionsCount,\n linePathsCount,\n lineFeaturesCount,\n polygonPositionsCount,\n polygonObjectsCount,\n polygonRingsCount,\n polygonFeaturesCount\n } = firstPassData;\n const {numericPropKeys, PositionDataType = Float32Array} = options;\n const hasGlobalId = features[0] && 'id' in features[0];\n const coordLength = 2;\n const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;\n const points: MvtPoints = {\n positions: new PositionDataType(pointPositionsCount * coordLength),\n globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),\n featureIds:\n pointFeaturesCount > 65535\n ? new Uint32Array(pointPositionsCount)\n : new Uint16Array(pointPositionsCount),\n numericProps: {},\n properties: [],\n fields: []\n };\n const lines: MvtLines = {\n pathIndices:\n linePositionsCount > 65535\n ? new Uint32Array(linePathsCount + 1)\n : new Uint16Array(linePathsCount + 1),\n positions: new PositionDataType(linePositionsCount * coordLength),\n globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),\n featureIds:\n lineFeaturesCount > 65535\n ? new Uint32Array(linePositionsCount)\n : new Uint16Array(linePositionsCount),\n numericProps: {},\n properties: [],\n fields: []\n };\n const polygons: MvtPolygons = {\n polygonIndices:\n polygonPositionsCount > 65535\n ? new Uint32Array(polygonObjectsCount + 1)\n : new Uint16Array(polygonObjectsCount + 1),\n primitivePolygonIndices:\n polygonPositionsCount > 65535\n ? new Uint32Array(polygonRingsCount + 1)\n : new Uint16Array(polygonRingsCount + 1),\n positions: new PositionDataType(polygonPositionsCount * coordLength),\n triangles: [],\n globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),\n featureIds:\n polygonFeaturesCount > 65535\n ? new Uint32Array(polygonPositionsCount)\n : new Uint16Array(polygonPositionsCount),\n numericProps: {},\n properties: [],\n fields: []\n };\n\n // Instantiate numeric properties arrays; one value per vertex\n for (const object of [points, lines, polygons]) {\n for (const propName of numericPropKeys) {\n // If property has been numeric in all previous features in which the property existed, check\n // if numeric in this feature\n object.numericProps[propName] = new Float32Array(object.positions.length / coordLength);\n }\n }\n\n // Set last element of path/polygon indices as positions length\n lines.pathIndices[linePathsCount] = linePositionsCount;\n polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;\n polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;\n\n const indexMap = {\n pointPosition: 0,\n pointFeature: 0,\n linePosition: 0,\n linePath: 0,\n lineFeature: 0,\n polygonPosition: 0,\n polygonObject: 0,\n polygonRing: 0,\n polygonFeature: 0,\n feature: 0\n };\n\n for (const feature of features) {\n const geometry = feature.geometry;\n const properties = feature.properties || {};\n\n switch (geometry.type) {\n case 'Point':\n case 'MultiPoint':\n handlePoint(geometry, points, indexMap, coordLength, properties);\n points.properties.push(keepStringProperties(properties, numericPropKeys));\n if (hasGlobalId) {\n points.fields.push({id: feature.id});\n }\n indexMap.pointFeature++;\n break;\n case 'LineString':\n case 'MultiLineString':\n handleLineString(geometry, lines, indexMap, coordLength, properties);\n lines.properties.push(keepStringProperties(properties, numericPropKeys));\n if (hasGlobalId) {\n lines.fields.push({id: feature.id});\n }\n indexMap.lineFeature++;\n break;\n case 'Polygon':\n case 'MultiPolygon':\n handlePolygon(geometry, polygons, indexMap, coordLength, properties);\n polygons.properties.push(keepStringProperties(properties, numericPropKeys));\n if (hasGlobalId) {\n polygons.fields.push({id: feature.id});\n }\n indexMap.polygonFeature++;\n break;\n default:\n throw new Error('Invalid geometry type');\n }\n\n indexMap.feature++;\n }\n\n // Wrap each array in an accessor object with value and size keys\n return makeAccessorObjects(points, lines, polygons, coordLength);\n}\n\n/**\n * Fills (Multi)Point coordinates into points object of arrays\n *\n * @param geometry\n * @param points\n * @param indexMap\n * @param coordLength\n * @param properties\n */\nfunction handlePoint(\n geometry: MvtBinaryGeometry,\n points: MvtPoints,\n indexMap: {\n pointPosition: number;\n pointFeature: number;\n linePosition?: number;\n linePath?: number;\n lineFeature?: number;\n polygonPosition?: number;\n polygonObject?: number;\n polygonRing?: number;\n polygonFeature?: number;\n feature: number;\n },\n coordLength: number,\n properties: {[x: string]: string | number | boolean | null}\n): void {\n points.positions.set(geometry.data, indexMap.pointPosition * coordLength);\n\n const nPositions = geometry.data.length / coordLength;\n fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);\n points.globalFeatureIds.fill(\n indexMap.feature,\n indexMap.pointPosition,\n indexMap.pointPosition + nPositions\n );\n points.featureIds.fill(\n indexMap.pointFeature,\n indexMap.pointPosition,\n indexMap.pointPosition + nPositions\n );\n\n indexMap.pointPosition += nPositions;\n}\n\n/**\n * Fills (Multi)LineString coordinates into lines object of arrays\n *\n * @param geometry\n * @param lines\n * @param indexMap\n * @param coordLength\n * @param properties\n */\nfunction handleLineString(\n geometry: MvtBinaryGeometry,\n lines: MvtLines,\n indexMap: {\n pointPosition?: number;\n pointFeature?: number;\n linePosition: number;\n linePath: number;\n lineFeature: number;\n polygonPosition?: number;\n polygonObject?: number;\n polygonRing?: number;\n polygonFeature?: number;\n feature: number;\n },\n coordLength: number,\n properties: {[x: string]: string | number | boolean | null}\n): void {\n lines.positions.set(geometry.data, indexMap.linePosition * coordLength);\n\n const nPositions = geometry.data.length / coordLength;\n fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);\n\n lines.globalFeatureIds.fill(\n indexMap.feature,\n indexMap.linePosition,\n indexMap.linePosition + nPositions\n );\n lines.featureIds.fill(\n indexMap.lineFeature,\n indexMap.linePosition,\n indexMap.linePosition + nPositions\n );\n\n for (let i = 0, il = geometry.lines.length; i < il; ++i) {\n // Extract range of data we are working with, defined by start\n // and end indices (these index into the geometry.data array)\n const start = geometry.lines[i];\n const end =\n i === il - 1\n ? geometry.data.length // last line, so read to end of data\n : geometry.lines[i + 1]; // start index for next line\n\n lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;\n indexMap.linePosition += (end - start) / coordLength;\n }\n}\n\n/**\n * Fills (Multi)Polygon coordinates into polygons object of arrays\n *\n * @param geometry\n * @param polygons\n * @param indexMap\n * @param coordLength\n * @param properties\n */\nfunction handlePolygon(\n geometry: MvtBinaryGeometry,\n polygons: MvtPolygons,\n indexMap: {\n pointPosition?: number;\n pointFeature?: number;\n linePosition?: number;\n linePath?: number;\n lineFeature?: number;\n polygonPosition: number;\n polygonObject: number;\n polygonRing: number;\n polygonFeature: number;\n feature: number;\n },\n coordLength: number,\n properties: {[x: string]: string | number | boolean | null}\n): void {\n polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);\n\n const nPositions = geometry.data.length / coordLength;\n fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);\n polygons.globalFeatureIds.fill(\n indexMap.feature,\n indexMap.polygonPosition,\n indexMap.polygonPosition + nPositions\n );\n polygons.featureIds.fill(\n indexMap.polygonFeature,\n indexMap.polygonPosition,\n indexMap.polygonPosition + nPositions\n );\n\n // Unlike Point & LineString geometry.lines is a 2D array\n for (let l = 0, ll = geometry.lines.length; l < ll; ++l) {\n const startPosition = indexMap.polygonPosition;\n polygons.polygonIndices[indexMap.polygonObject++] = startPosition;\n\n const areas = geometry.areas![l];\n const lines = geometry.lines[l];\n const nextLines = geometry.lines[l + 1];\n\n for (let i = 0, il = lines.length; i < il; ++i) {\n const start = lines[i];\n const end =\n i === il - 1\n ? // last line, so either read to:\n nextLines === undefined\n ? geometry.data.length // end of data (no next lines)\n : nextLines[0] // start of first line in nextLines\n : lines[i + 1]; // start index for next line\n\n polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;\n indexMap.polygonPosition += (end - start) / coordLength;\n }\n\n const endPosition = indexMap.polygonPosition;\n triangulatePolygon(polygons, areas, lines, {startPosition, endPosition, coordLength});\n }\n}\n\n/**\n * Triangulate polygon using earcut\n *\n * @param polygons\n * @param areas\n * @param lines\n * @param param3\n */\nfunction triangulatePolygon(\n polygons: MvtPolygons,\n areas: number,\n lines: number[],\n {\n startPosition,\n endPosition,\n coordLength\n }: {startPosition: number; endPosition: number; coordLength: number}\n): void {\n const start = startPosition * coordLength;\n const end = endPosition * coordLength;\n\n // Extract positions and holes for just this polygon\n const polygonPositions = polygons.positions.subarray(start, end);\n\n // Holes are referenced relative to outer polygon\n const offset = lines[0];\n const holes = lines.slice(1).map((n: number) => (n - offset) / coordLength);\n\n // Compute triangulation\n const indices = earcut(polygonPositions, holes, coordLength, areas);\n\n // Indices returned by triangulation are relative to start\n // of polygon, so we need to offset\n for (let t = 0, tl = indices.length; t < tl; ++t) {\n polygons.triangles.push(startPosition + indices[t]);\n }\n}\n\n/**\n * Wrap each array in an accessor object with value and size keys\n *\n * @param points\n * @param lines\n * @param polygons\n * @param coordLength\n * @returns object\n */\nfunction makeAccessorObjects(\n points: MvtPoints,\n lines: MvtLines,\n polygons: MvtPolygons,\n coordLength: number\n) {\n const returnObj = {\n points: {\n ...points,\n positions: {value: points.positions, size: coordLength},\n globalFeatureIds: {value: points.globalFeatureIds, size: 1},\n featureIds: {value: points.featureIds, size: 1}\n },\n lines: {\n ...lines,\n pathIndices: {value: lines.pathIndices, size: 1},\n positions: {value: lines.positions, size: coordLength},\n globalFeatureIds: {value: lines.globalFeatureIds, size: 1},\n featureIds: {value: lines.featureIds, size: 1}\n },\n polygons: {\n ...polygons,\n polygonIndices: {value: polygons.polygonIndices, size: 1},\n primitivePolygonIndices: {value: polygons.primitivePolygonIndices, size: 1},\n positions: {value: polygons.positions, size: coordLength},\n triangles: {value: new Uint32Array(polygons.triangles), size: 1},\n globalFeatureIds: {value: polygons.globalFeatureIds, size: 1},\n featureIds: {value: polygons.featureIds, size: 1}\n }\n };\n\n for (const geomType in returnObj) {\n for (const numericProp in returnObj[geomType].numericProps) {\n returnObj[geomType].numericProps[numericProp] = {\n value: returnObj[geomType].numericProps[numericProp],\n size: 1\n };\n }\n }\n return returnObj;\n}\n\n/**\n * Add numeric properties to object\n *\n * @param object\n * @param properties\n * @param index\n * @param length\n */\nfunction fillNumericProperties(\n object: MvtPoints,\n properties: {[x: string]: string | number | boolean | null},\n index: number,\n length: number\n): void {\n for (const numericPropName in object.numericProps) {\n if (numericPropName in properties) {\n object.numericProps[numericPropName].fill(properties[numericPropName], index, index + length);\n }\n }\n}\n\n/**\n * Keep string properties in object\n *\n * @param properties\n * @param numericKeys\n * @returns object\n */\nfunction keepStringProperties(\n properties: {[x: string]: string | number | boolean | null},\n numericKeys: string[]\n) {\n const props = {};\n for (const key in properties) {\n if (!numericKeys.includes(key)) {\n props[key] = properties[key];\n }\n }\n return props;\n}\n\nfunction isNumeric(x: unknown) {\n return Number.isFinite(x);\n}\n"],"file":"features-to-binary.js"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/binary-vector-tile/features-to-binary.ts"],"names":["featuresToBinary","features","firstPassData","options","propArrayTypes","extractNumericPropTypes","numericPropKeys","Object","keys","filter","k","Array","fillArrays","PositionDataType","Float32Array","TEST_EXPORTS","feature","properties","key","val","deduceArrayType","pointPositionsCount","pointFeaturesCount","linePositionsCount","linePathsCount","lineFeaturesCount","polygonPositionsCount","polygonObjectsCount","polygonRingsCount","polygonFeaturesCount","hasGlobalId","coordLength","GlobalFeatureIdsDataType","length","Uint32Array","Uint16Array","points","positions","globalFeatureIds","featureIds","numericProps","fields","lines","pathIndices","polygons","polygonIndices","primitivePolygonIndices","triangles","object","propName","TypedArray","indexMap","pointPosition","pointFeature","linePosition","linePath","lineFeature","polygonPosition","polygonObject","polygonRing","polygonFeature","geometry","type","handlePoint","push","keepStringProperties","id","handleLineString","handlePolygon","Error","makeAccessorObjects","set","data","nPositions","fillNumericProperties","fill","i","il","start","end","l","ll","startPosition","areas","nextLines","undefined","endPosition","triangulatePolygon","polygonPositions","subarray","offset","holes","slice","map","n","indices","t","tl","returnObj","value","size","geomType","numericProp","index","numericPropName","numericKeys","props","includes","x","constructor","Number","isFinite","Float64Array","Math","fround"],"mappings":";;;;;;;;AACA;;AAyBO,SAASA,gBAAT,CACLC,QADK,EAELC,aAFK,EAGLC,OAHK,EAIL;AACA,QAAMC,cAAc,GAAGC,uBAAuB,CAACJ,QAAD,CAA9C;AACA,QAAMK,eAAe,GAAGC,MAAM,CAACC,IAAP,CAAYJ,cAAZ,EAA4BK,MAA5B,CAAoCC,CAAD,IAAON,cAAc,CAACM,CAAD,CAAd,KAAsBC,KAAhE,CAAxB;AACA,SAAOC,UAAU,CAACX,QAAD,EAAWC,aAAX,EAA0B;AACzCI,IAAAA,eAAe,EAAEH,OAAO,GAAGA,OAAO,CAACG,eAAX,GAA6BA,eADZ;AAEzCF,IAAAA,cAFyC;AAGzCS,IAAAA,gBAAgB,EAAEV,OAAO,GAAGA,OAAO,CAACU,gBAAX,GAA8BC;AAHd,GAA1B,CAAjB;AAKD;;AAEM,MAAMC,YAAY,GAAG;AAC1BH,EAAAA;AAD0B,CAArB;;;AAUP,SAASP,uBAAT,CAAiCJ,QAAjC,EAEE;AACA,QAAMG,cAAc,GAAG,EAAvB;;AACA,OAAK,MAAMY,OAAX,IAAsBf,QAAtB,EAAgC;AAC9B,QAAIe,OAAO,CAACC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OF,SAAP;AACD;;AAUD,SAASxB,qBAAT,CACE1B,MADF,EAEE/B,UAFF,EAGEsF,KAHF,EAIEtE,MAJF,EAKQ;AACN,OAAK,MAAMuE,eAAX,IAA8BxD,MAAM,CAACR,YAArC,EAAmD;AACjD,QAAIgE,eAAe,IAAIvF,UAAvB,EAAmC;AACjC+B,MAAAA,MAAM,CAACR,YAAP,CAAoBgE,eAApB,EAAqC7B,IAArC,CAA0C1D,UAAU,CAACuF,eAAD,CAApD,EAAuED,KAAvE,EAA8EA,KAAK,GAAGtE,MAAtF;AACD;AACF;AACF;;AASD,SAASgC,oBAAT,CACEhD,UADF,EAEEwF,WAFF,EAGE;AACA,QAAMC,KAAK,GAAG,EAAd;;AACA,OAAK,MAAMxF,GAAX,IAAkBD,UAAlB,EAA8B;AAC5B,QAAI,CAACwF,WAAW,CAACE,QAAZ,CAAqBzF,GAArB,CAAL,EAAgC;AAC9BwF,MAAAA,KAAK,CAACxF,GAAD,CAAL,GAAaD,UAAU,CAACC,GAAD,CAAvB;AACD;AACF;;AACD,SAAOwF,KAAP;AACD;;AAED,SAAStF,eAAT,CAAyBwF,CAAzB,EAAiCC,WAAjC,EAAgG;AAC9F,MAAIA,WAAW,KAAKlG,KAAhB,IAAyB,CAACmG,MAAM,CAACC,QAAP,CAAgBH,CAAhB,CAA9B,EAAkD;AAChD,WAAOjG,KAAP;AACD;;AAGD,SAAOkG,WAAW,KAAKG,YAAhB,IAAgCC,IAAI,CAACC,MAAL,CAAYN,CAAZ,MAAmBA,CAAnD,GAAuDI,YAAvD,GAAsElG,YAA7E;AACD","sourcesContent":["/* eslint-disable indent */\nimport {earcut} from '@math.gl/polygon';\nimport {\n MvtBinaryCoordinates,\n MvtBinaryGeometry,\n MvtBinaryOptions,\n MvtPropArrayConstructor,\n MvtFirstPassedData,\n MvtLines,\n MvtPoints,\n MvtPolygons\n} from '../types';\n\n/**\n * Convert binary features to flat binary arrays. Similar to\n * `geojsonToBinary` helper function, except that it expects\n * a binary representation of the feature data, which enables\n * 2X-3X speed increase in parse speed, compared to using\n * geoJSON. See `binary-vector-tile/VectorTileFeature` for\n * data format detais\n *\n * @param features\n * @param firstPassData\n * @param options\n * @returns filled arrays\n */\nexport function featuresToBinary(\n features: MvtBinaryCoordinates[],\n firstPassData: MvtFirstPassedData,\n options?: MvtBinaryOptions\n) {\n const propArrayTypes = extractNumericPropTypes(features);\n const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);\n return fillArrays(features, firstPassData, {\n numericPropKeys: options ? options.numericPropKeys : numericPropKeys,\n propArrayTypes,\n PositionDataType: options ? options.PositionDataType : Float32Array\n });\n}\n\nexport const TEST_EXPORTS = {\n fillArrays\n};\n\n/**\n * Extracts properties that are always numeric\n *\n * @param features\n * @returns object with numeric types\n */\nfunction extractNumericPropTypes(features: MvtBinaryCoordinates[]): {\n [key: string]: MvtPropArrayConstructor;\n} {\n const propArrayTypes = {};\n for (const feature of features) {\n if (feature.properties) {\n for (const key in feature.properties) {\n // If property has not been seen before, or if property has been numeric\n // in all previous features, check if numeric in this feature\n // If not numeric, Array is stored to prevent rechecking in the future\n // Additionally, detects if 64 bit precision is required\n const val = feature.properties[key];\n propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);\n }\n }\n }\n\n return propArrayTypes;\n}\n\n/**\n * Fills coordinates into pre-allocated typed arrays\n *\n * @param features\n * @param firstPassData\n * @param options\n * @returns an accessor object with value and size keys\n */\n// eslint-disable-next-line complexity\nfunction fillArrays(\n features: MvtBinaryCoordinates[],\n firstPassData: MvtFirstPassedData,\n options: MvtBinaryOptions\n) {\n const {\n pointPositionsCount,\n pointFeaturesCount,\n linePositionsCount,\n linePathsCount,\n lineFeaturesCount,\n polygonPositionsCount,\n polygonObjectsCount,\n polygonRingsCount,\n polygonFeaturesCount\n } = firstPassData;\n const {numericPropKeys, propArrayTypes, PositionDataType = Float32Array} = options;\n const hasGlobalId = features[0] && 'id' in features[0];\n const coordLength = 2;\n const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;\n const points: MvtPoints = {\n positions: new PositionDataType(pointPositionsCount * coordLength),\n globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),\n featureIds:\n pointFeaturesCount > 65535\n ? new Uint32Array(pointPositionsCount)\n : new Uint16Array(pointPositionsCount),\n numericProps: {},\n properties: [],\n fields: []\n };\n const lines: MvtLines = {\n pathIndices:\n linePositionsCount > 65535\n ? new Uint32Array(linePathsCount + 1)\n : new Uint16Array(linePathsCount + 1),\n positions: new PositionDataType(linePositionsCount * coordLength),\n globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),\n featureIds:\n lineFeaturesCount > 65535\n ? new Uint32Array(linePositionsCount)\n : new Uint16Array(linePositionsCount),\n numericProps: {},\n properties: [],\n fields: []\n };\n const polygons: MvtPolygons = {\n polygonIndices:\n polygonPositionsCount > 65535\n ? new Uint32Array(polygonObjectsCount + 1)\n : new Uint16Array(polygonObjectsCount + 1),\n primitivePolygonIndices:\n polygonPositionsCount > 65535\n ? new Uint32Array(polygonRingsCount + 1)\n : new Uint16Array(polygonRingsCount + 1),\n positions: new PositionDataType(polygonPositionsCount * coordLength),\n triangles: [],\n globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),\n featureIds:\n polygonFeaturesCount > 65535\n ? new Uint32Array(polygonPositionsCount)\n : new Uint16Array(polygonPositionsCount),\n numericProps: {},\n properties: [],\n fields: []\n };\n\n // Instantiate numeric properties arrays; one value per vertex\n for (const object of [points, lines, polygons]) {\n for (const propName of numericPropKeys) {\n // If property has been numeric in all previous features in which the property existed, check\n // if numeric in this feature\n const TypedArray = propArrayTypes[propName];\n object.numericProps[propName] = new TypedArray(object.positions.length / coordLength);\n }\n }\n\n // Set last element of path/polygon indices as positions length\n lines.pathIndices[linePathsCount] = linePositionsCount;\n polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;\n polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;\n\n const indexMap = {\n pointPosition: 0,\n pointFeature: 0,\n linePosition: 0,\n linePath: 0,\n lineFeature: 0,\n polygonPosition: 0,\n polygonObject: 0,\n polygonRing: 0,\n polygonFeature: 0,\n feature: 0\n };\n\n for (const feature of features) {\n const geometry = feature.geometry;\n const properties = feature.properties || {};\n\n switch (geometry.type) {\n case 'Point':\n case 'MultiPoint':\n handlePoint(geometry, points, indexMap, coordLength, properties);\n points.properties.push(keepStringProperties(properties, numericPropKeys));\n if (hasGlobalId) {\n points.fields.push({id: feature.id});\n }\n indexMap.pointFeature++;\n break;\n case 'LineString':\n case 'MultiLineString':\n handleLineString(geometry, lines, indexMap, coordLength, properties);\n lines.properties.push(keepStringProperties(properties, numericPropKeys));\n if (hasGlobalId) {\n lines.fields.push({id: feature.id});\n }\n indexMap.lineFeature++;\n break;\n case 'Polygon':\n case 'MultiPolygon':\n handlePolygon(geometry, polygons, indexMap, coordLength, properties);\n polygons.properties.push(keepStringProperties(properties, numericPropKeys));\n if (hasGlobalId) {\n polygons.fields.push({id: feature.id});\n }\n indexMap.polygonFeature++;\n break;\n default:\n throw new Error('Invalid geometry type');\n }\n\n indexMap.feature++;\n }\n\n // Wrap each array in an accessor object with value and size keys\n return makeAccessorObjects(points, lines, polygons, coordLength);\n}\n\n/**\n * Fills (Multi)Point coordinates into points object of arrays\n *\n * @param geometry\n * @param points\n * @param indexMap\n * @param coordLength\n * @param properties\n */\nfunction handlePoint(\n geometry: MvtBinaryGeometry,\n points: MvtPoints,\n indexMap: {\n pointPosition: number;\n pointFeature: number;\n linePosition?: number;\n linePath?: number;\n lineFeature?: number;\n polygonPosition?: number;\n polygonObject?: number;\n polygonRing?: number;\n polygonFeature?: number;\n feature: number;\n },\n coordLength: number,\n properties: {[x: string]: string | number | boolean | null}\n): void {\n points.positions.set(geometry.data, indexMap.pointPosition * coordLength);\n\n const nPositions = geometry.data.length / coordLength;\n fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);\n points.globalFeatureIds.fill(\n indexMap.feature,\n indexMap.pointPosition,\n indexMap.pointPosition + nPositions\n );\n points.featureIds.fill(\n indexMap.pointFeature,\n indexMap.pointPosition,\n indexMap.pointPosition + nPositions\n );\n\n indexMap.pointPosition += nPositions;\n}\n\n/**\n * Fills (Multi)LineString coordinates into lines object of arrays\n *\n * @param geometry\n * @param lines\n * @param indexMap\n * @param coordLength\n * @param properties\n */\nfunction handleLineString(\n geometry: MvtBinaryGeometry,\n lines: MvtLines,\n indexMap: {\n pointPosition?: number;\n pointFeature?: number;\n linePosition: number;\n linePath: number;\n lineFeature: number;\n polygonPosition?: number;\n polygonObject?: number;\n polygonRing?: number;\n polygonFeature?: number;\n feature: number;\n },\n coordLength: number,\n properties: {[x: string]: string | number | boolean | null}\n): void {\n lines.positions.set(geometry.data, indexMap.linePosition * coordLength);\n\n const nPositions = geometry.data.length / coordLength;\n fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);\n\n lines.globalFeatureIds.fill(\n indexMap.feature,\n indexMap.linePosition,\n indexMap.linePosition + nPositions\n );\n lines.featureIds.fill(\n indexMap.lineFeature,\n indexMap.linePosition,\n indexMap.linePosition + nPositions\n );\n\n for (let i = 0, il = geometry.lines.length; i < il; ++i) {\n // Extract range of data we are working with, defined by start\n // and end indices (these index into the geometry.data array)\n const start = geometry.lines[i];\n const end =\n i === il - 1\n ? geometry.data.length // last line, so read to end of data\n : geometry.lines[i + 1]; // start index for next line\n\n lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;\n indexMap.linePosition += (end - start) / coordLength;\n }\n}\n\n/**\n * Fills (Multi)Polygon coordinates into polygons object of arrays\n *\n * @param geometry\n * @param polygons\n * @param indexMap\n * @param coordLength\n * @param properties\n */\nfunction handlePolygon(\n geometry: MvtBinaryGeometry,\n polygons: MvtPolygons,\n indexMap: {\n pointPosition?: number;\n pointFeature?: number;\n linePosition?: number;\n linePath?: number;\n lineFeature?: number;\n polygonPosition: number;\n polygonObject: number;\n polygonRing: number;\n polygonFeature: number;\n feature: number;\n },\n coordLength: number,\n properties: {[x: string]: string | number | boolean | null}\n): void {\n polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);\n\n const nPositions = geometry.data.length / coordLength;\n fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);\n polygons.globalFeatureIds.fill(\n indexMap.feature,\n indexMap.polygonPosition,\n indexMap.polygonPosition + nPositions\n );\n polygons.featureIds.fill(\n indexMap.polygonFeature,\n indexMap.polygonPosition,\n indexMap.polygonPosition + nPositions\n );\n\n // Unlike Point & LineString geometry.lines is a 2D array\n for (let l = 0, ll = geometry.lines.length; l < ll; ++l) {\n const startPosition = indexMap.polygonPosition;\n polygons.polygonIndices[indexMap.polygonObject++] = startPosition;\n\n const areas = geometry.areas![l];\n const lines = geometry.lines[l];\n const nextLines = geometry.lines[l + 1];\n\n for (let i = 0, il = lines.length; i < il; ++i) {\n const start = lines[i];\n const end =\n i === il - 1\n ? // last line, so either read to:\n nextLines === undefined\n ? geometry.data.length // end of data (no next lines)\n : nextLines[0] // start of first line in nextLines\n : lines[i + 1]; // start index for next line\n\n polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;\n indexMap.polygonPosition += (end - start) / coordLength;\n }\n\n const endPosition = indexMap.polygonPosition;\n triangulatePolygon(polygons, areas, lines, {startPosition, endPosition, coordLength});\n }\n}\n\n/**\n * Triangulate polygon using earcut\n *\n * @param polygons\n * @param areas\n * @param lines\n * @param param3\n */\nfunction triangulatePolygon(\n polygons: MvtPolygons,\n areas: number,\n lines: number[],\n {\n startPosition,\n endPosition,\n coordLength\n }: {startPosition: number; endPosition: number; coordLength: number}\n): void {\n const start = startPosition * coordLength;\n const end = endPosition * coordLength;\n\n // Extract positions and holes for just this polygon\n const polygonPositions = polygons.positions.subarray(start, end);\n\n // Holes are referenced relative to outer polygon\n const offset = lines[0];\n const holes = lines.slice(1).map((n: number) => (n - offset) / coordLength);\n\n // Compute triangulation\n const indices = earcut(polygonPositions, holes, coordLength, areas);\n\n // Indices returned by triangulation are relative to start\n // of polygon, so we need to offset\n for (let t = 0, tl = indices.length; t < tl; ++t) {\n polygons.triangles.push(startPosition + indices[t]);\n }\n}\n\n/**\n * Wrap each array in an accessor object with value and size keys\n *\n * @param points\n * @param lines\n * @param polygons\n * @param coordLength\n * @returns object\n */\nfunction makeAccessorObjects(\n points: MvtPoints,\n lines: MvtLines,\n polygons: MvtPolygons,\n coordLength: number\n) {\n const returnObj = {\n points: {\n ...points,\n positions: {value: points.positions, size: coordLength},\n globalFeatureIds: {value: points.globalFeatureIds, size: 1},\n featureIds: {value: points.featureIds, size: 1}\n },\n lines: {\n ...lines,\n pathIndices: {value: lines.pathIndices, size: 1},\n positions: {value: lines.positions, size: coordLength},\n globalFeatureIds: {value: lines.globalFeatureIds, size: 1},\n featureIds: {value: lines.featureIds, size: 1}\n },\n polygons: {\n ...polygons,\n polygonIndices: {value: polygons.polygonIndices, size: 1},\n primitivePolygonIndices: {value: polygons.primitivePolygonIndices, size: 1},\n positions: {value: polygons.positions, size: coordLength},\n triangles: {value: new Uint32Array(polygons.triangles), size: 1},\n globalFeatureIds: {value: polygons.globalFeatureIds, size: 1},\n featureIds: {value: polygons.featureIds, size: 1}\n }\n };\n\n for (const geomType in returnObj) {\n for (const numericProp in returnObj[geomType].numericProps) {\n returnObj[geomType].numericProps[numericProp] = {\n value: returnObj[geomType].numericProps[numericProp],\n size: 1\n };\n }\n }\n return returnObj;\n}\n\n/**\n * Add numeric properties to object\n *\n * @param object\n * @param properties\n * @param index\n * @param length\n */\nfunction fillNumericProperties(\n object: MvtPoints,\n properties: {[x: string]: string | number | boolean | null},\n index: number,\n length: number\n): void {\n for (const numericPropName in object.numericProps) {\n if (numericPropName in properties) {\n object.numericProps[numericPropName].fill(properties[numericPropName], index, index + length);\n }\n }\n}\n\n/**\n * Keep string properties in object\n *\n * @param properties\n * @param numericKeys\n * @returns object\n */\nfunction keepStringProperties(\n properties: {[x: string]: string | number | boolean | null},\n numericKeys: string[]\n) {\n const props = {};\n for (const key in properties) {\n if (!numericKeys.includes(key)) {\n props[key] = properties[key];\n }\n }\n return props;\n}\n\nfunction deduceArrayType(x: any, constructor: MvtPropArrayConstructor): MvtPropArrayConstructor {\n if (constructor === Array || !Number.isFinite(x)) {\n return Array;\n }\n\n // If this or previous value required 64bits use Float64Array\n return constructor === Float64Array || Math.fround(x) !== x ? Float64Array : Float32Array;\n}\n"],"file":"features-to-binary.js"}
|
package/dist/es5/mvt-loader.js
CHANGED
|
@@ -9,7 +9,7 @@ exports.MVTLoader = exports.MVTWorkerLoader = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _parseMvt = _interopRequireDefault(require("./lib/parse-mvt"));
|
|
11
11
|
|
|
12
|
-
const VERSION = typeof "3.1.0-beta.
|
|
12
|
+
const VERSION = typeof "3.1.0-beta.7" !== 'undefined' ? "3.1.0-beta.7" : 'latest';
|
|
13
13
|
const MVTWorkerLoader = {
|
|
14
14
|
name: 'Mapbox Vector Tile',
|
|
15
15
|
id: 'mvt',
|
|
@@ -1,32 +1,30 @@
|
|
|
1
1
|
import { earcut } from '@math.gl/polygon';
|
|
2
2
|
export function featuresToBinary(features, firstPassData, options) {
|
|
3
|
+
const propArrayTypes = extractNumericPropTypes(features);
|
|
4
|
+
const numericPropKeys = Object.keys(propArrayTypes).filter(k => propArrayTypes[k] !== Array);
|
|
3
5
|
return fillArrays(features, firstPassData, {
|
|
4
|
-
numericPropKeys: options ? options.numericPropKeys :
|
|
6
|
+
numericPropKeys: options ? options.numericPropKeys : numericPropKeys,
|
|
7
|
+
propArrayTypes,
|
|
5
8
|
PositionDataType: options ? options.PositionDataType : Float32Array
|
|
6
9
|
});
|
|
7
10
|
}
|
|
8
11
|
export const TEST_EXPORTS = {
|
|
9
|
-
extractNumericPropKeys,
|
|
10
12
|
fillArrays
|
|
11
13
|
};
|
|
12
14
|
|
|
13
|
-
function
|
|
14
|
-
const
|
|
15
|
+
function extractNumericPropTypes(features) {
|
|
16
|
+
const propArrayTypes = {};
|
|
15
17
|
|
|
16
18
|
for (const feature of features) {
|
|
17
19
|
if (feature.properties) {
|
|
18
20
|
for (const key in feature.properties) {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
if (numericSoFar || numericSoFar === undefined) {
|
|
22
|
-
const val = feature.properties[key];
|
|
23
|
-
numericPropKeys[key] = isNumeric(val);
|
|
24
|
-
}
|
|
21
|
+
const val = feature.properties[key];
|
|
22
|
+
propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);
|
|
25
23
|
}
|
|
26
24
|
}
|
|
27
25
|
}
|
|
28
26
|
|
|
29
|
-
return
|
|
27
|
+
return propArrayTypes;
|
|
30
28
|
}
|
|
31
29
|
|
|
32
30
|
function fillArrays(features, firstPassData, options) {
|
|
@@ -43,6 +41,7 @@ function fillArrays(features, firstPassData, options) {
|
|
|
43
41
|
} = firstPassData;
|
|
44
42
|
const {
|
|
45
43
|
numericPropKeys,
|
|
44
|
+
propArrayTypes,
|
|
46
45
|
PositionDataType = Float32Array
|
|
47
46
|
} = options;
|
|
48
47
|
const hasGlobalId = features[0] && 'id' in features[0];
|
|
@@ -79,7 +78,8 @@ function fillArrays(features, firstPassData, options) {
|
|
|
79
78
|
|
|
80
79
|
for (const object of [points, lines, polygons]) {
|
|
81
80
|
for (const propName of numericPropKeys) {
|
|
82
|
-
|
|
81
|
+
const TypedArray = propArrayTypes[propName];
|
|
82
|
+
object.numericProps[propName] = new TypedArray(object.positions.length / coordLength);
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
|
|
@@ -321,7 +321,11 @@ function keepStringProperties(properties, numericKeys) {
|
|
|
321
321
|
return props;
|
|
322
322
|
}
|
|
323
323
|
|
|
324
|
-
function
|
|
325
|
-
|
|
324
|
+
function deduceArrayType(x, constructor) {
|
|
325
|
+
if (constructor === Array || !Number.isFinite(x)) {
|
|
326
|
+
return Array;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
return constructor === Float64Array || Math.fround(x) !== x ? Float64Array : Float32Array;
|
|
326
330
|
}
|
|
327
331
|
//# sourceMappingURL=features-to-binary.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/binary-vector-tile/features-to-binary.ts"],"names":["earcut","featuresToBinary","features","firstPassData","options","fillArrays","numericPropKeys","extractNumericPropKeys","PositionDataType","Float32Array","TEST_EXPORTS","feature","properties","key","numericSoFar","undefined","val","isNumeric","Object","keys","filter","k","pointPositionsCount","pointFeaturesCount","linePositionsCount","linePathsCount","lineFeaturesCount","polygonPositionsCount","polygonObjectsCount","polygonRingsCount","polygonFeaturesCount","hasGlobalId","coordLength","GlobalFeatureIdsDataType","length","Uint32Array","Uint16Array","points","positions","globalFeatureIds","featureIds","numericProps","fields","lines","pathIndices","polygons","polygonIndices","primitivePolygonIndices","triangles","object","propName","indexMap","pointPosition","pointFeature","linePosition","linePath","lineFeature","polygonPosition","polygonObject","polygonRing","polygonFeature","geometry","type","handlePoint","push","keepStringProperties","id","handleLineString","handlePolygon","Error","makeAccessorObjects","set","data","nPositions","fillNumericProperties","fill","i","il","start","end","l","ll","startPosition","areas","nextLines","endPosition","triangulatePolygon","polygonPositions","subarray","offset","holes","slice","map","n","indices","t","tl","returnObj","value","size","geomType","numericProp","index","numericPropName","numericKeys","props","includes","x","Number","isFinite"],"mappings":"AACA,SAAQA,MAAR,QAAqB,kBAArB;AAwBA,OAAO,SAASC,gBAAT,CACLC,QADK,EAELC,aAFK,EAGLC,OAHK,EAIL;AACA,SAAOC,UAAU,CAACH,QAAD,EAAWC,aAAX,EAA0B;AACzCG,IAAAA,eAAe,EAAEF,OAAO,GAAGA,OAAO,CAACE,eAAX,GAA6BC,sBAAsB,CAACL,QAAD,CADlC;AAEzCM,IAAAA,gBAAgB,EAAEJ,OAAO,GAAGA,OAAO,CAACI,gBAAX,GAA8BC;AAFd,GAA1B,CAAjB;AAID;AAED,OAAO,MAAMC,YAAY,GAAG;AAC1BH,EAAAA,sBAD0B;AAE1B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J,SAAS,CAACG,QAAD,CAAT,CAAoB3D,YAA9C,EAA4D;AAC1DwD,MAAAA,SAAS,CAACG,QAAD,CAAT,CAAoB3D,YAApB,CAAiC4D,WAAjC,IAAgD;AAC9CH,QAAAA,KAAK,EAAED,SAAS,CAACG,QAAD,CAAT,CAAoB3D,YAApB,CAAiC4D,WAAjC,CADuC;AAE9CF,QAAAA,IAAI,EAAE;AAFwC,OAAhD;AAID;AACF;;AACD,SAAOF,SAAP;AACD;;AAUD,SAASvB,qBAAT,CACEzB,MADF,EAEErC,UAFF,EAGE0F,KAHF,EAIEpE,MAJF,EAKQ;AACN,OAAK,MAAMqE,eAAX,IAA8BtD,MAAM,CAACR,YAArC,EAAmD;AACjD,QAAI8D,eAAe,IAAI3F,UAAvB,EAAmC;AACjCqC,MAAAA,MAAM,CAACR,YAAP,CAAoB8D,eAApB,EAAqC5B,IAArC,CAA0C/D,UAAU,CAAC2F,eAAD,CAApD,EAAuED,KAAvE,EAA8EA,KAAK,GAAGpE,MAAtF;AACD;AACF;AACF;;AASD,SAAS+B,oBAAT,CACErD,UADF,EAEE4F,WAFF,EAGE;AACA,QAAMC,KAAK,GAAG,EAAd;;AACA,OAAK,MAAM5F,GAAX,IAAkBD,UAAlB,EAA8B;AAC5B,QAAI,CAAC4F,WAAW,CAACE,QAAZ,CAAqB7F,GAArB,CAAL,EAAgC;AAC9B4F,MAAAA,KAAK,CAAC5F,GAAD,CAAL,GAAaD,UAAU,CAACC,GAAD,CAAvB;AACD;AACF;;AACD,SAAO4F,KAAP;AACD;;AAED,SAASxF,SAAT,CAAmB0F,CAAnB,EAA+B;AAC7B,SAAOC,MAAM,CAACC,QAAP,CAAgBF,CAAhB,CAAP;AACD","sourcesContent":["/* eslint-disable indent */\nimport {earcut} from '@math.gl/polygon';\nimport {\n MvtBinaryCoordinates,\n MvtBinaryGeometry,\n MvtBinaryOptions,\n MvtFirstPassedData,\n MvtLines,\n MvtPoints,\n MvtPolygons\n} from '../types';\n\n/**\n * Convert binary features to flat binary arrays. Similar to\n * `geojsonToBinary` helper function, except that it expects\n * a binary representation of the feature data, which enables\n * 2X-3X speed increase in parse speed, compared to using\n * geoJSON. See `binary-vector-tile/VectorTileFeature` for\n * data format detais\n *\n * @param features\n * @param firstPassData\n * @param options\n * @returns filled arrays\n */\nexport function featuresToBinary(\n features: MvtBinaryCoordinates[],\n firstPassData: MvtFirstPassedData,\n options?: MvtBinaryOptions\n) {\n return fillArrays(features, firstPassData, {\n numericPropKeys: options ? options.numericPropKeys : extractNumericPropKeys(features),\n PositionDataType: options ? options.PositionDataType : Float32Array\n });\n}\n\nexport const TEST_EXPORTS = {\n extractNumericPropKeys,\n fillArrays\n};\n\n/**\n * Extracts properties that are always numeric\n *\n * @param features\n * @returns object with numeric keys\n */\nfunction extractNumericPropKeys(features: MvtBinaryCoordinates[]): string[] {\n const numericPropKeys = {};\n for (const feature of features) {\n if (feature.properties) {\n for (const key in feature.properties) {\n // If property has not been seen before, or if property has been numeric\n // in all previous features, check if numeric in this feature\n // If not numeric, false is stored to prevent rechecking in the future\n const numericSoFar = numericPropKeys[key];\n if (numericSoFar || numericSoFar === undefined) {\n const val = feature.properties[key];\n numericPropKeys[key] = isNumeric(val);\n }\n }\n }\n }\n\n return Object.keys(numericPropKeys).filter((k) => numericPropKeys[k]);\n}\n\n/**\n * Fills coordinates into pre-allocated typed arrays\n *\n * @param features\n * @param firstPassData\n * @param options\n * @returns an accessor object with value and size keys\n */\n// eslint-disable-next-line complexity\nfunction fillArrays(\n features: MvtBinaryCoordinates[],\n firstPassData: MvtFirstPassedData,\n options: MvtBinaryOptions\n) {\n const {\n pointPositionsCount,\n pointFeaturesCount,\n linePositionsCount,\n linePathsCount,\n lineFeaturesCount,\n polygonPositionsCount,\n polygonObjectsCount,\n polygonRingsCount,\n polygonFeaturesCount\n } = firstPassData;\n const {numericPropKeys, PositionDataType = Float32Array} = options;\n const hasGlobalId = features[0] && 'id' in features[0];\n const coordLength = 2;\n const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;\n const points: MvtPoints = {\n positions: new PositionDataType(pointPositionsCount * coordLength),\n globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),\n featureIds:\n pointFeaturesCount > 65535\n ? new Uint32Array(pointPositionsCount)\n : new Uint16Array(pointPositionsCount),\n numericProps: {},\n properties: [],\n fields: []\n };\n const lines: MvtLines = {\n pathIndices:\n linePositionsCount > 65535\n ? new Uint32Array(linePathsCount + 1)\n : new Uint16Array(linePathsCount + 1),\n positions: new PositionDataType(linePositionsCount * coordLength),\n globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),\n featureIds:\n lineFeaturesCount > 65535\n ? new Uint32Array(linePositionsCount)\n : new Uint16Array(linePositionsCount),\n numericProps: {},\n properties: [],\n fields: []\n };\n const polygons: MvtPolygons = {\n polygonIndices:\n polygonPositionsCount > 65535\n ? new Uint32Array(polygonObjectsCount + 1)\n : new Uint16Array(polygonObjectsCount + 1),\n primitivePolygonIndices:\n polygonPositionsCount > 65535\n ? new Uint32Array(polygonRingsCount + 1)\n : new Uint16Array(polygonRingsCount + 1),\n positions: new PositionDataType(polygonPositionsCount * coordLength),\n triangles: [],\n globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),\n featureIds:\n polygonFeaturesCount > 65535\n ? new Uint32Array(polygonPositionsCount)\n : new Uint16Array(polygonPositionsCount),\n numericProps: {},\n properties: [],\n fields: []\n };\n\n // Instantiate numeric properties arrays; one value per vertex\n for (const object of [points, lines, polygons]) {\n for (const propName of numericPropKeys) {\n // If property has been numeric in all previous features in which the property existed, check\n // if numeric in this feature\n object.numericProps[propName] = new Float32Array(object.positions.length / coordLength);\n }\n }\n\n // Set last element of path/polygon indices as positions length\n lines.pathIndices[linePathsCount] = linePositionsCount;\n polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;\n polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;\n\n const indexMap = {\n pointPosition: 0,\n pointFeature: 0,\n linePosition: 0,\n linePath: 0,\n lineFeature: 0,\n polygonPosition: 0,\n polygonObject: 0,\n polygonRing: 0,\n polygonFeature: 0,\n feature: 0\n };\n\n for (const feature of features) {\n const geometry = feature.geometry;\n const properties = feature.properties || {};\n\n switch (geometry.type) {\n case 'Point':\n case 'MultiPoint':\n handlePoint(geometry, points, indexMap, coordLength, properties);\n points.properties.push(keepStringProperties(properties, numericPropKeys));\n if (hasGlobalId) {\n points.fields.push({id: feature.id});\n }\n indexMap.pointFeature++;\n break;\n case 'LineString':\n case 'MultiLineString':\n handleLineString(geometry, lines, indexMap, coordLength, properties);\n lines.properties.push(keepStringProperties(properties, numericPropKeys));\n if (hasGlobalId) {\n lines.fields.push({id: feature.id});\n }\n indexMap.lineFeature++;\n break;\n case 'Polygon':\n case 'MultiPolygon':\n handlePolygon(geometry, polygons, indexMap, coordLength, properties);\n polygons.properties.push(keepStringProperties(properties, numericPropKeys));\n if (hasGlobalId) {\n polygons.fields.push({id: feature.id});\n }\n indexMap.polygonFeature++;\n break;\n default:\n throw new Error('Invalid geometry type');\n }\n\n indexMap.feature++;\n }\n\n // Wrap each array in an accessor object with value and size keys\n return makeAccessorObjects(points, lines, polygons, coordLength);\n}\n\n/**\n * Fills (Multi)Point coordinates into points object of arrays\n *\n * @param geometry\n * @param points\n * @param indexMap\n * @param coordLength\n * @param properties\n */\nfunction handlePoint(\n geometry: MvtBinaryGeometry,\n points: MvtPoints,\n indexMap: {\n pointPosition: number;\n pointFeature: number;\n linePosition?: number;\n linePath?: number;\n lineFeature?: number;\n polygonPosition?: number;\n polygonObject?: number;\n polygonRing?: number;\n polygonFeature?: number;\n feature: number;\n },\n coordLength: number,\n properties: {[x: string]: string | number | boolean | null}\n): void {\n points.positions.set(geometry.data, indexMap.pointPosition * coordLength);\n\n const nPositions = geometry.data.length / coordLength;\n fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);\n points.globalFeatureIds.fill(\n indexMap.feature,\n indexMap.pointPosition,\n indexMap.pointPosition + nPositions\n );\n points.featureIds.fill(\n indexMap.pointFeature,\n indexMap.pointPosition,\n indexMap.pointPosition + nPositions\n );\n\n indexMap.pointPosition += nPositions;\n}\n\n/**\n * Fills (Multi)LineString coordinates into lines object of arrays\n *\n * @param geometry\n * @param lines\n * @param indexMap\n * @param coordLength\n * @param properties\n */\nfunction handleLineString(\n geometry: MvtBinaryGeometry,\n lines: MvtLines,\n indexMap: {\n pointPosition?: number;\n pointFeature?: number;\n linePosition: number;\n linePath: number;\n lineFeature: number;\n polygonPosition?: number;\n polygonObject?: number;\n polygonRing?: number;\n polygonFeature?: number;\n feature: number;\n },\n coordLength: number,\n properties: {[x: string]: string | number | boolean | null}\n): void {\n lines.positions.set(geometry.data, indexMap.linePosition * coordLength);\n\n const nPositions = geometry.data.length / coordLength;\n fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);\n\n lines.globalFeatureIds.fill(\n indexMap.feature,\n indexMap.linePosition,\n indexMap.linePosition + nPositions\n );\n lines.featureIds.fill(\n indexMap.lineFeature,\n indexMap.linePosition,\n indexMap.linePosition + nPositions\n );\n\n for (let i = 0, il = geometry.lines.length; i < il; ++i) {\n // Extract range of data we are working with, defined by start\n // and end indices (these index into the geometry.data array)\n const start = geometry.lines[i];\n const end =\n i === il - 1\n ? geometry.data.length // last line, so read to end of data\n : geometry.lines[i + 1]; // start index for next line\n\n lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;\n indexMap.linePosition += (end - start) / coordLength;\n }\n}\n\n/**\n * Fills (Multi)Polygon coordinates into polygons object of arrays\n *\n * @param geometry\n * @param polygons\n * @param indexMap\n * @param coordLength\n * @param properties\n */\nfunction handlePolygon(\n geometry: MvtBinaryGeometry,\n polygons: MvtPolygons,\n indexMap: {\n pointPosition?: number;\n pointFeature?: number;\n linePosition?: number;\n linePath?: number;\n lineFeature?: number;\n polygonPosition: number;\n polygonObject: number;\n polygonRing: number;\n polygonFeature: number;\n feature: number;\n },\n coordLength: number,\n properties: {[x: string]: string | number | boolean | null}\n): void {\n polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);\n\n const nPositions = geometry.data.length / coordLength;\n fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);\n polygons.globalFeatureIds.fill(\n indexMap.feature,\n indexMap.polygonPosition,\n indexMap.polygonPosition + nPositions\n );\n polygons.featureIds.fill(\n indexMap.polygonFeature,\n indexMap.polygonPosition,\n indexMap.polygonPosition + nPositions\n );\n\n // Unlike Point & LineString geometry.lines is a 2D array\n for (let l = 0, ll = geometry.lines.length; l < ll; ++l) {\n const startPosition = indexMap.polygonPosition;\n polygons.polygonIndices[indexMap.polygonObject++] = startPosition;\n\n const areas = geometry.areas![l];\n const lines = geometry.lines[l];\n const nextLines = geometry.lines[l + 1];\n\n for (let i = 0, il = lines.length; i < il; ++i) {\n const start = lines[i];\n const end =\n i === il - 1\n ? // last line, so either read to:\n nextLines === undefined\n ? geometry.data.length // end of data (no next lines)\n : nextLines[0] // start of first line in nextLines\n : lines[i + 1]; // start index for next line\n\n polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;\n indexMap.polygonPosition += (end - start) / coordLength;\n }\n\n const endPosition = indexMap.polygonPosition;\n triangulatePolygon(polygons, areas, lines, {startPosition, endPosition, coordLength});\n }\n}\n\n/**\n * Triangulate polygon using earcut\n *\n * @param polygons\n * @param areas\n * @param lines\n * @param param3\n */\nfunction triangulatePolygon(\n polygons: MvtPolygons,\n areas: number,\n lines: number[],\n {\n startPosition,\n endPosition,\n coordLength\n }: {startPosition: number; endPosition: number; coordLength: number}\n): void {\n const start = startPosition * coordLength;\n const end = endPosition * coordLength;\n\n // Extract positions and holes for just this polygon\n const polygonPositions = polygons.positions.subarray(start, end);\n\n // Holes are referenced relative to outer polygon\n const offset = lines[0];\n const holes = lines.slice(1).map((n: number) => (n - offset) / coordLength);\n\n // Compute triangulation\n const indices = earcut(polygonPositions, holes, coordLength, areas);\n\n // Indices returned by triangulation are relative to start\n // of polygon, so we need to offset\n for (let t = 0, tl = indices.length; t < tl; ++t) {\n polygons.triangles.push(startPosition + indices[t]);\n }\n}\n\n/**\n * Wrap each array in an accessor object with value and size keys\n *\n * @param points\n * @param lines\n * @param polygons\n * @param coordLength\n * @returns object\n */\nfunction makeAccessorObjects(\n points: MvtPoints,\n lines: MvtLines,\n polygons: MvtPolygons,\n coordLength: number\n) {\n const returnObj = {\n points: {\n ...points,\n positions: {value: points.positions, size: coordLength},\n globalFeatureIds: {value: points.globalFeatureIds, size: 1},\n featureIds: {value: points.featureIds, size: 1}\n },\n lines: {\n ...lines,\n pathIndices: {value: lines.pathIndices, size: 1},\n positions: {value: lines.positions, size: coordLength},\n globalFeatureIds: {value: lines.globalFeatureIds, size: 1},\n featureIds: {value: lines.featureIds, size: 1}\n },\n polygons: {\n ...polygons,\n polygonIndices: {value: polygons.polygonIndices, size: 1},\n primitivePolygonIndices: {value: polygons.primitivePolygonIndices, size: 1},\n positions: {value: polygons.positions, size: coordLength},\n triangles: {value: new Uint32Array(polygons.triangles), size: 1},\n globalFeatureIds: {value: polygons.globalFeatureIds, size: 1},\n featureIds: {value: polygons.featureIds, size: 1}\n }\n };\n\n for (const geomType in returnObj) {\n for (const numericProp in returnObj[geomType].numericProps) {\n returnObj[geomType].numericProps[numericProp] = {\n value: returnObj[geomType].numericProps[numericProp],\n size: 1\n };\n }\n }\n return returnObj;\n}\n\n/**\n * Add numeric properties to object\n *\n * @param object\n * @param properties\n * @param index\n * @param length\n */\nfunction fillNumericProperties(\n object: MvtPoints,\n properties: {[x: string]: string | number | boolean | null},\n index: number,\n length: number\n): void {\n for (const numericPropName in object.numericProps) {\n if (numericPropName in properties) {\n object.numericProps[numericPropName].fill(properties[numericPropName], index, index + length);\n }\n }\n}\n\n/**\n * Keep string properties in object\n *\n * @param properties\n * @param numericKeys\n * @returns object\n */\nfunction keepStringProperties(\n properties: {[x: string]: string | number | boolean | null},\n numericKeys: string[]\n) {\n const props = {};\n for (const key in properties) {\n if (!numericKeys.includes(key)) {\n props[key] = properties[key];\n }\n }\n return props;\n}\n\nfunction isNumeric(x: unknown) {\n return Number.isFinite(x);\n}\n"],"file":"features-to-binary.js"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/binary-vector-tile/features-to-binary.ts"],"names":["earcut","featuresToBinary","features","firstPassData","options","propArrayTypes","extractNumericPropTypes","numericPropKeys","Object","keys","filter","k","Array","fillArrays","PositionDataType","Float32Array","TEST_EXPORTS","feature","properties","key","val","deduceArrayType","pointPositionsCount","pointFeaturesCount","linePositionsCount","linePathsCount","lineFeaturesCount","polygonPositionsCount","polygonObjectsCount","polygonRingsCount","polygonFeaturesCount","hasGlobalId","coordLength","GlobalFeatureIdsDataType","length","Uint32Array","Uint16Array","points","positions","globalFeatureIds","featureIds","numericProps","fields","lines","pathIndices","polygons","polygonIndices","primitivePolygonIndices","triangles","object","propName","TypedArray","indexMap","pointPosition","pointFeature","linePosition","linePath","lineFeature","polygonPosition","polygonObject","polygonRing","polygonFeature","geometry","type","handlePoint","push","keepStringProperties","id","handleLineString","handlePolygon","Error","makeAccessorObjects","set","data","nPositions","fillNumericProperties","fill","i","il","start","end","l","ll","startPosition","areas","nextLines","undefined","endPosition","triangulatePolygon","polygonPositions","subarray","offset","holes","slice","map","n","indices","t","tl","returnObj","value","size","geomType","numericProp","index","numericPropName","numericKeys","props","includes","x","constructor","Number","isFinite","Float64Array","Math","fround"],"mappings":"AACA,SAAQA,MAAR,QAAqB,kBAArB;AAyBA,OAAO,SAASC,gBAAT,CACLC,QADK,EAELC,aAFK,EAGLC,OAHK,EAIL;AACA,QAAMC,cAAc,GAAGC,uBAAuB,CAACJ,QAAD,CAA9C;AACA,QAAMK,eAAe,GAAGC,MAAM,CAACC,IAAP,CAAYJ,cAAZ,EAA4BK,MAA5B,CAAoCC,CAAD,IAAON,cAAc,CAACM,CAAD,CAAd,KAAsBC,KAAhE,CAAxB;AACA,SAAOC,UAAU,CAACX,QAAD,EAAWC,aAAX,EAA0B;A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AkD;AAChD,WAAOjG,KAAP;AACD;;AAGD,SAAOkG,WAAW,KAAKG,YAAhB,IAAgCC,IAAI,CAACC,MAAL,CAAYN,CAAZ,MAAmBA,CAAnD,GAAuDI,YAAvD,GAAsElG,YAA7E;AACD","sourcesContent":["/* eslint-disable indent */\nimport {earcut} from '@math.gl/polygon';\nimport {\n MvtBinaryCoordinates,\n MvtBinaryGeometry,\n MvtBinaryOptions,\n MvtPropArrayConstructor,\n MvtFirstPassedData,\n MvtLines,\n MvtPoints,\n MvtPolygons\n} from '../types';\n\n/**\n * Convert binary features to flat binary arrays. Similar to\n * `geojsonToBinary` helper function, except that it expects\n * a binary representation of the feature data, which enables\n * 2X-3X speed increase in parse speed, compared to using\n * geoJSON. See `binary-vector-tile/VectorTileFeature` for\n * data format detais\n *\n * @param features\n * @param firstPassData\n * @param options\n * @returns filled arrays\n */\nexport function featuresToBinary(\n features: MvtBinaryCoordinates[],\n firstPassData: MvtFirstPassedData,\n options?: MvtBinaryOptions\n) {\n const propArrayTypes = extractNumericPropTypes(features);\n const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);\n return fillArrays(features, firstPassData, {\n numericPropKeys: options ? options.numericPropKeys : numericPropKeys,\n propArrayTypes,\n PositionDataType: options ? options.PositionDataType : Float32Array\n });\n}\n\nexport const TEST_EXPORTS = {\n fillArrays\n};\n\n/**\n * Extracts properties that are always numeric\n *\n * @param features\n * @returns object with numeric types\n */\nfunction extractNumericPropTypes(features: MvtBinaryCoordinates[]): {\n [key: string]: MvtPropArrayConstructor;\n} {\n const propArrayTypes = {};\n for (const feature of features) {\n if (feature.properties) {\n for (const key in feature.properties) {\n // If property has not been seen before, or if property has been numeric\n // in all previous features, check if numeric in this feature\n // If not numeric, Array is stored to prevent rechecking in the future\n // Additionally, detects if 64 bit precision is required\n const val = feature.properties[key];\n propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);\n }\n }\n }\n\n return propArrayTypes;\n}\n\n/**\n * Fills coordinates into pre-allocated typed arrays\n *\n * @param features\n * @param firstPassData\n * @param options\n * @returns an accessor object with value and size keys\n */\n// eslint-disable-next-line complexity\nfunction fillArrays(\n features: MvtBinaryCoordinates[],\n firstPassData: MvtFirstPassedData,\n options: MvtBinaryOptions\n) {\n const {\n pointPositionsCount,\n pointFeaturesCount,\n linePositionsCount,\n linePathsCount,\n lineFeaturesCount,\n polygonPositionsCount,\n polygonObjectsCount,\n polygonRingsCount,\n polygonFeaturesCount\n } = firstPassData;\n const {numericPropKeys, propArrayTypes, PositionDataType = Float32Array} = options;\n const hasGlobalId = features[0] && 'id' in features[0];\n const coordLength = 2;\n const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;\n const points: MvtPoints = {\n positions: new PositionDataType(pointPositionsCount * coordLength),\n globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),\n featureIds:\n pointFeaturesCount > 65535\n ? new Uint32Array(pointPositionsCount)\n : new Uint16Array(pointPositionsCount),\n numericProps: {},\n properties: [],\n fields: []\n };\n const lines: MvtLines = {\n pathIndices:\n linePositionsCount > 65535\n ? new Uint32Array(linePathsCount + 1)\n : new Uint16Array(linePathsCount + 1),\n positions: new PositionDataType(linePositionsCount * coordLength),\n globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),\n featureIds:\n lineFeaturesCount > 65535\n ? new Uint32Array(linePositionsCount)\n : new Uint16Array(linePositionsCount),\n numericProps: {},\n properties: [],\n fields: []\n };\n const polygons: MvtPolygons = {\n polygonIndices:\n polygonPositionsCount > 65535\n ? new Uint32Array(polygonObjectsCount + 1)\n : new Uint16Array(polygonObjectsCount + 1),\n primitivePolygonIndices:\n polygonPositionsCount > 65535\n ? new Uint32Array(polygonRingsCount + 1)\n : new Uint16Array(polygonRingsCount + 1),\n positions: new PositionDataType(polygonPositionsCount * coordLength),\n triangles: [],\n globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),\n featureIds:\n polygonFeaturesCount > 65535\n ? new Uint32Array(polygonPositionsCount)\n : new Uint16Array(polygonPositionsCount),\n numericProps: {},\n properties: [],\n fields: []\n };\n\n // Instantiate numeric properties arrays; one value per vertex\n for (const object of [points, lines, polygons]) {\n for (const propName of numericPropKeys) {\n // If property has been numeric in all previous features in which the property existed, check\n // if numeric in this feature\n const TypedArray = propArrayTypes[propName];\n object.numericProps[propName] = new TypedArray(object.positions.length / coordLength);\n }\n }\n\n // Set last element of path/polygon indices as positions length\n lines.pathIndices[linePathsCount] = linePositionsCount;\n polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;\n polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;\n\n const indexMap = {\n pointPosition: 0,\n pointFeature: 0,\n linePosition: 0,\n linePath: 0,\n lineFeature: 0,\n polygonPosition: 0,\n polygonObject: 0,\n polygonRing: 0,\n polygonFeature: 0,\n feature: 0\n };\n\n for (const feature of features) {\n const geometry = feature.geometry;\n const properties = feature.properties || {};\n\n switch (geometry.type) {\n case 'Point':\n case 'MultiPoint':\n handlePoint(geometry, points, indexMap, coordLength, properties);\n points.properties.push(keepStringProperties(properties, numericPropKeys));\n if (hasGlobalId) {\n points.fields.push({id: feature.id});\n }\n indexMap.pointFeature++;\n break;\n case 'LineString':\n case 'MultiLineString':\n handleLineString(geometry, lines, indexMap, coordLength, properties);\n lines.properties.push(keepStringProperties(properties, numericPropKeys));\n if (hasGlobalId) {\n lines.fields.push({id: feature.id});\n }\n indexMap.lineFeature++;\n break;\n case 'Polygon':\n case 'MultiPolygon':\n handlePolygon(geometry, polygons, indexMap, coordLength, properties);\n polygons.properties.push(keepStringProperties(properties, numericPropKeys));\n if (hasGlobalId) {\n polygons.fields.push({id: feature.id});\n }\n indexMap.polygonFeature++;\n break;\n default:\n throw new Error('Invalid geometry type');\n }\n\n indexMap.feature++;\n }\n\n // Wrap each array in an accessor object with value and size keys\n return makeAccessorObjects(points, lines, polygons, coordLength);\n}\n\n/**\n * Fills (Multi)Point coordinates into points object of arrays\n *\n * @param geometry\n * @param points\n * @param indexMap\n * @param coordLength\n * @param properties\n */\nfunction handlePoint(\n geometry: MvtBinaryGeometry,\n points: MvtPoints,\n indexMap: {\n pointPosition: number;\n pointFeature: number;\n linePosition?: number;\n linePath?: number;\n lineFeature?: number;\n polygonPosition?: number;\n polygonObject?: number;\n polygonRing?: number;\n polygonFeature?: number;\n feature: number;\n },\n coordLength: number,\n properties: {[x: string]: string | number | boolean | null}\n): void {\n points.positions.set(geometry.data, indexMap.pointPosition * coordLength);\n\n const nPositions = geometry.data.length / coordLength;\n fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);\n points.globalFeatureIds.fill(\n indexMap.feature,\n indexMap.pointPosition,\n indexMap.pointPosition + nPositions\n );\n points.featureIds.fill(\n indexMap.pointFeature,\n indexMap.pointPosition,\n indexMap.pointPosition + nPositions\n );\n\n indexMap.pointPosition += nPositions;\n}\n\n/**\n * Fills (Multi)LineString coordinates into lines object of arrays\n *\n * @param geometry\n * @param lines\n * @param indexMap\n * @param coordLength\n * @param properties\n */\nfunction handleLineString(\n geometry: MvtBinaryGeometry,\n lines: MvtLines,\n indexMap: {\n pointPosition?: number;\n pointFeature?: number;\n linePosition: number;\n linePath: number;\n lineFeature: number;\n polygonPosition?: number;\n polygonObject?: number;\n polygonRing?: number;\n polygonFeature?: number;\n feature: number;\n },\n coordLength: number,\n properties: {[x: string]: string | number | boolean | null}\n): void {\n lines.positions.set(geometry.data, indexMap.linePosition * coordLength);\n\n const nPositions = geometry.data.length / coordLength;\n fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);\n\n lines.globalFeatureIds.fill(\n indexMap.feature,\n indexMap.linePosition,\n indexMap.linePosition + nPositions\n );\n lines.featureIds.fill(\n indexMap.lineFeature,\n indexMap.linePosition,\n indexMap.linePosition + nPositions\n );\n\n for (let i = 0, il = geometry.lines.length; i < il; ++i) {\n // Extract range of data we are working with, defined by start\n // and end indices (these index into the geometry.data array)\n const start = geometry.lines[i];\n const end =\n i === il - 1\n ? geometry.data.length // last line, so read to end of data\n : geometry.lines[i + 1]; // start index for next line\n\n lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;\n indexMap.linePosition += (end - start) / coordLength;\n }\n}\n\n/**\n * Fills (Multi)Polygon coordinates into polygons object of arrays\n *\n * @param geometry\n * @param polygons\n * @param indexMap\n * @param coordLength\n * @param properties\n */\nfunction handlePolygon(\n geometry: MvtBinaryGeometry,\n polygons: MvtPolygons,\n indexMap: {\n pointPosition?: number;\n pointFeature?: number;\n linePosition?: number;\n linePath?: number;\n lineFeature?: number;\n polygonPosition: number;\n polygonObject: number;\n polygonRing: number;\n polygonFeature: number;\n feature: number;\n },\n coordLength: number,\n properties: {[x: string]: string | number | boolean | null}\n): void {\n polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);\n\n const nPositions = geometry.data.length / coordLength;\n fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);\n polygons.globalFeatureIds.fill(\n indexMap.feature,\n indexMap.polygonPosition,\n indexMap.polygonPosition + nPositions\n );\n polygons.featureIds.fill(\n indexMap.polygonFeature,\n indexMap.polygonPosition,\n indexMap.polygonPosition + nPositions\n );\n\n // Unlike Point & LineString geometry.lines is a 2D array\n for (let l = 0, ll = geometry.lines.length; l < ll; ++l) {\n const startPosition = indexMap.polygonPosition;\n polygons.polygonIndices[indexMap.polygonObject++] = startPosition;\n\n const areas = geometry.areas![l];\n const lines = geometry.lines[l];\n const nextLines = geometry.lines[l + 1];\n\n for (let i = 0, il = lines.length; i < il; ++i) {\n const start = lines[i];\n const end =\n i === il - 1\n ? // last line, so either read to:\n nextLines === undefined\n ? geometry.data.length // end of data (no next lines)\n : nextLines[0] // start of first line in nextLines\n : lines[i + 1]; // start index for next line\n\n polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;\n indexMap.polygonPosition += (end - start) / coordLength;\n }\n\n const endPosition = indexMap.polygonPosition;\n triangulatePolygon(polygons, areas, lines, {startPosition, endPosition, coordLength});\n }\n}\n\n/**\n * Triangulate polygon using earcut\n *\n * @param polygons\n * @param areas\n * @param lines\n * @param param3\n */\nfunction triangulatePolygon(\n polygons: MvtPolygons,\n areas: number,\n lines: number[],\n {\n startPosition,\n endPosition,\n coordLength\n }: {startPosition: number; endPosition: number; coordLength: number}\n): void {\n const start = startPosition * coordLength;\n const end = endPosition * coordLength;\n\n // Extract positions and holes for just this polygon\n const polygonPositions = polygons.positions.subarray(start, end);\n\n // Holes are referenced relative to outer polygon\n const offset = lines[0];\n const holes = lines.slice(1).map((n: number) => (n - offset) / coordLength);\n\n // Compute triangulation\n const indices = earcut(polygonPositions, holes, coordLength, areas);\n\n // Indices returned by triangulation are relative to start\n // of polygon, so we need to offset\n for (let t = 0, tl = indices.length; t < tl; ++t) {\n polygons.triangles.push(startPosition + indices[t]);\n }\n}\n\n/**\n * Wrap each array in an accessor object with value and size keys\n *\n * @param points\n * @param lines\n * @param polygons\n * @param coordLength\n * @returns object\n */\nfunction makeAccessorObjects(\n points: MvtPoints,\n lines: MvtLines,\n polygons: MvtPolygons,\n coordLength: number\n) {\n const returnObj = {\n points: {\n ...points,\n positions: {value: points.positions, size: coordLength},\n globalFeatureIds: {value: points.globalFeatureIds, size: 1},\n featureIds: {value: points.featureIds, size: 1}\n },\n lines: {\n ...lines,\n pathIndices: {value: lines.pathIndices, size: 1},\n positions: {value: lines.positions, size: coordLength},\n globalFeatureIds: {value: lines.globalFeatureIds, size: 1},\n featureIds: {value: lines.featureIds, size: 1}\n },\n polygons: {\n ...polygons,\n polygonIndices: {value: polygons.polygonIndices, size: 1},\n primitivePolygonIndices: {value: polygons.primitivePolygonIndices, size: 1},\n positions: {value: polygons.positions, size: coordLength},\n triangles: {value: new Uint32Array(polygons.triangles), size: 1},\n globalFeatureIds: {value: polygons.globalFeatureIds, size: 1},\n featureIds: {value: polygons.featureIds, size: 1}\n }\n };\n\n for (const geomType in returnObj) {\n for (const numericProp in returnObj[geomType].numericProps) {\n returnObj[geomType].numericProps[numericProp] = {\n value: returnObj[geomType].numericProps[numericProp],\n size: 1\n };\n }\n }\n return returnObj;\n}\n\n/**\n * Add numeric properties to object\n *\n * @param object\n * @param properties\n * @param index\n * @param length\n */\nfunction fillNumericProperties(\n object: MvtPoints,\n properties: {[x: string]: string | number | boolean | null},\n index: number,\n length: number\n): void {\n for (const numericPropName in object.numericProps) {\n if (numericPropName in properties) {\n object.numericProps[numericPropName].fill(properties[numericPropName], index, index + length);\n }\n }\n}\n\n/**\n * Keep string properties in object\n *\n * @param properties\n * @param numericKeys\n * @returns object\n */\nfunction keepStringProperties(\n properties: {[x: string]: string | number | boolean | null},\n numericKeys: string[]\n) {\n const props = {};\n for (const key in properties) {\n if (!numericKeys.includes(key)) {\n props[key] = properties[key];\n }\n }\n return props;\n}\n\nfunction deduceArrayType(x: any, constructor: MvtPropArrayConstructor): MvtPropArrayConstructor {\n if (constructor === Array || !Number.isFinite(x)) {\n return Array;\n }\n\n // If this or previous value required 64bits use Float64Array\n return constructor === Float64Array || Math.fround(x) !== x ? Float64Array : Float32Array;\n}\n"],"file":"features-to-binary.js"}
|
package/dist/esm/mvt-loader.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import parseMVT from './lib/parse-mvt';
|
|
2
|
-
const VERSION = typeof "3.1.0-beta.
|
|
2
|
+
const VERSION = typeof "3.1.0-beta.7" !== 'undefined' ? "3.1.0-beta.7" : 'latest';
|
|
3
3
|
export const MVTWorkerLoader = {
|
|
4
4
|
name: 'Mapbox Vector Tile',
|
|
5
5
|
id: 'mvt',
|
|
@@ -88,16 +88,8 @@ export declare function featuresToBinary(features: MvtBinaryCoordinates[], first
|
|
|
88
88
|
};
|
|
89
89
|
};
|
|
90
90
|
export declare const TEST_EXPORTS: {
|
|
91
|
-
extractNumericPropKeys: typeof extractNumericPropKeys;
|
|
92
91
|
fillArrays: typeof fillArrays;
|
|
93
92
|
};
|
|
94
|
-
/**
|
|
95
|
-
* Extracts properties that are always numeric
|
|
96
|
-
*
|
|
97
|
-
* @param features
|
|
98
|
-
* @returns object with numeric keys
|
|
99
|
-
*/
|
|
100
|
-
declare function extractNumericPropKeys(features: MvtBinaryCoordinates[]): string[];
|
|
101
93
|
/**
|
|
102
94
|
* Fills coordinates into pre-allocated typed arrays
|
|
103
95
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features-to-binary.d.ts","sourceRoot":"","sources":["../../../src/lib/binary-vector-tile/features-to-binary.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,oBAAoB,EAEpB,gBAAgB,
|
|
1
|
+
{"version":3,"file":"features-to-binary.d.ts","sourceRoot":"","sources":["../../../src/lib/binary-vector-tile/features-to-binary.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,oBAAoB,EAEpB,gBAAgB,EAEhB,kBAAkB,EAInB,MAAM,UAAU,CAAC;AAElB;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,oBAAoB,EAAE,EAChC,aAAa,EAAE,kBAAkB,EACjC,OAAO,CAAC,EAAE,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAS3B;AAED,eAAO,MAAM,YAAY;;CAExB,CAAC;AA4BF;;;;;;;GAOG;AAEH,iBAAS,UAAU,CACjB,QAAQ,EAAE,oBAAoB,EAAE,EAChC,aAAa,EAAE,kBAAkB,EACjC,OAAO,EAAE,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqI1B"}
|
|
@@ -17,39 +17,39 @@ const polygon_1 = require("@math.gl/polygon");
|
|
|
17
17
|
* @returns filled arrays
|
|
18
18
|
*/
|
|
19
19
|
function featuresToBinary(features, firstPassData, options) {
|
|
20
|
+
const propArrayTypes = extractNumericPropTypes(features);
|
|
21
|
+
const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
|
|
20
22
|
return fillArrays(features, firstPassData, {
|
|
21
|
-
numericPropKeys: options ? options.numericPropKeys :
|
|
23
|
+
numericPropKeys: options ? options.numericPropKeys : numericPropKeys,
|
|
24
|
+
propArrayTypes,
|
|
22
25
|
PositionDataType: options ? options.PositionDataType : Float32Array
|
|
23
26
|
});
|
|
24
27
|
}
|
|
25
28
|
exports.featuresToBinary = featuresToBinary;
|
|
26
29
|
exports.TEST_EXPORTS = {
|
|
27
|
-
extractNumericPropKeys,
|
|
28
30
|
fillArrays
|
|
29
31
|
};
|
|
30
32
|
/**
|
|
31
33
|
* Extracts properties that are always numeric
|
|
32
34
|
*
|
|
33
35
|
* @param features
|
|
34
|
-
* @returns object with numeric
|
|
36
|
+
* @returns object with numeric types
|
|
35
37
|
*/
|
|
36
|
-
function
|
|
37
|
-
const
|
|
38
|
+
function extractNumericPropTypes(features) {
|
|
39
|
+
const propArrayTypes = {};
|
|
38
40
|
for (const feature of features) {
|
|
39
41
|
if (feature.properties) {
|
|
40
42
|
for (const key in feature.properties) {
|
|
41
43
|
// If property has not been seen before, or if property has been numeric
|
|
42
44
|
// in all previous features, check if numeric in this feature
|
|
43
|
-
// If not numeric,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
numericPropKeys[key] = isNumeric(val);
|
|
48
|
-
}
|
|
45
|
+
// If not numeric, Array is stored to prevent rechecking in the future
|
|
46
|
+
// Additionally, detects if 64 bit precision is required
|
|
47
|
+
const val = feature.properties[key];
|
|
48
|
+
propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
return
|
|
52
|
+
return propArrayTypes;
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
55
|
* Fills coordinates into pre-allocated typed arrays
|
|
@@ -62,7 +62,7 @@ function extractNumericPropKeys(features) {
|
|
|
62
62
|
// eslint-disable-next-line complexity
|
|
63
63
|
function fillArrays(features, firstPassData, options) {
|
|
64
64
|
const { pointPositionsCount, pointFeaturesCount, linePositionsCount, linePathsCount, lineFeaturesCount, polygonPositionsCount, polygonObjectsCount, polygonRingsCount, polygonFeaturesCount } = firstPassData;
|
|
65
|
-
const { numericPropKeys, PositionDataType = Float32Array } = options;
|
|
65
|
+
const { numericPropKeys, propArrayTypes, PositionDataType = Float32Array } = options;
|
|
66
66
|
const hasGlobalId = features[0] && 'id' in features[0];
|
|
67
67
|
const coordLength = 2;
|
|
68
68
|
const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
|
|
@@ -111,7 +111,8 @@ function fillArrays(features, firstPassData, options) {
|
|
|
111
111
|
for (const propName of numericPropKeys) {
|
|
112
112
|
// If property has been numeric in all previous features in which the property existed, check
|
|
113
113
|
// if numeric in this feature
|
|
114
|
-
|
|
114
|
+
const TypedArray = propArrayTypes[propName];
|
|
115
|
+
object.numericProps[propName] = new TypedArray(object.positions.length / coordLength);
|
|
115
116
|
}
|
|
116
117
|
}
|
|
117
118
|
// Set last element of path/polygon indices as positions length
|
|
@@ -348,6 +349,10 @@ function keepStringProperties(properties, numericKeys) {
|
|
|
348
349
|
}
|
|
349
350
|
return props;
|
|
350
351
|
}
|
|
351
|
-
function
|
|
352
|
-
|
|
352
|
+
function deduceArrayType(x, constructor) {
|
|
353
|
+
if (constructor === Array || !Number.isFinite(x)) {
|
|
354
|
+
return Array;
|
|
355
|
+
}
|
|
356
|
+
// If this or previous value required 64bits use Float64Array
|
|
357
|
+
return constructor === Float64Array || Math.fround(x) !== x ? Float64Array : Float32Array;
|
|
353
358
|
}
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -40,8 +40,12 @@ export declare type MvtMapboxCoordinates = {
|
|
|
40
40
|
};
|
|
41
41
|
id?: number;
|
|
42
42
|
};
|
|
43
|
+
export declare type MvtPropArrayConstructor = Float32ArrayConstructor | Float64ArrayConstructor | ArrayConstructor;
|
|
43
44
|
export declare type MvtBinaryOptions = {
|
|
44
45
|
numericPropKeys: string[];
|
|
46
|
+
propArrayTypes: {
|
|
47
|
+
[key: string]: MvtPropArrayConstructor;
|
|
48
|
+
};
|
|
45
49
|
PositionDataType: Float32ArrayConstructor;
|
|
46
50
|
};
|
|
47
51
|
export declare type MvtFirstPassedData = {
|
package/dist/lib/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,oBAAY,UAAU,GAAG;IACvB,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC/B,SAAS,EAAE;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAC,CAAC;IAC7C,aAAa,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,oBAAY,iBAAiB,GAAG;IAC9B,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,KAAK,EAAE,GAAG,EAAE,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,oBAAY,iBAAiB,GAAG;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,GAAG,EAAE,CAAC;CACrB,CAAC;AAEF,oBAAY,oBAAoB,GAAG;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,UAAU,EAAE;QAAC,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAA;KAAC,CAAC;IAC5D,EAA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
|
1778
1778
|
function featuresToBinary(features, firstPassData, options) {
|
|
1779
|
+
const propArrayTypes = extractNumericPropTypes(features);
|
|
1780
|
+
const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
|
|
1779
1781
|
return fillArrays(features, firstPassData, {
|
|
1780
|
-
numericPropKeys: options ? options.numericPropKeys :
|
|
1782
|
+
numericPropKeys: options ? options.numericPropKeys : numericPropKeys,
|
|
1783
|
+
propArrayTypes,
|
|
1781
1784
|
PositionDataType: options ? options.PositionDataType : Float32Array
|
|
1782
1785
|
});
|
|
1783
1786
|
}
|
|
1784
|
-
function
|
|
1785
|
-
const
|
|
1787
|
+
function extractNumericPropTypes(features) {
|
|
1788
|
+
const propArrayTypes = {};
|
|
1786
1789
|
for (const feature of features) {
|
|
1787
1790
|
if (feature.properties) {
|
|
1788
1791
|
for (const key in feature.properties) {
|
|
1789
|
-
const
|
|
1790
|
-
|
|
1791
|
-
const val = feature.properties[key];
|
|
1792
|
-
numericPropKeys[key] = isNumeric(val);
|
|
1793
|
-
}
|
|
1792
|
+
const val = feature.properties[key];
|
|
1793
|
+
propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);
|
|
1794
1794
|
}
|
|
1795
1795
|
}
|
|
1796
1796
|
}
|
|
1797
|
-
return
|
|
1797
|
+
return propArrayTypes;
|
|
1798
1798
|
}
|
|
1799
1799
|
function fillArrays(features, firstPassData, options) {
|
|
1800
1800
|
const {
|
|
@@ -1808,7 +1808,7 @@
|
|
|
1808
1808
|
polygonRingsCount,
|
|
1809
1809
|
polygonFeaturesCount
|
|
1810
1810
|
} = firstPassData;
|
|
1811
|
-
const { numericPropKeys, PositionDataType = Float32Array } = options;
|
|
1811
|
+
const { numericPropKeys, propArrayTypes, PositionDataType = Float32Array } = options;
|
|
1812
1812
|
const hasGlobalId = features[0] && "id" in features[0];
|
|
1813
1813
|
const coordLength = 2;
|
|
1814
1814
|
const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
|
|
@@ -1842,7 +1842,8 @@
|
|
|
1842
1842
|
};
|
|
1843
1843
|
for (const object of [points, lines, polygons]) {
|
|
1844
1844
|
for (const propName of numericPropKeys) {
|
|
1845
|
-
|
|
1845
|
+
const TypedArray = propArrayTypes[propName];
|
|
1846
|
+
object.numericProps[propName] = new TypedArray(object.positions.length / coordLength);
|
|
1846
1847
|
}
|
|
1847
1848
|
}
|
|
1848
1849
|
lines.pathIndices[linePathsCount] = linePositionsCount;
|
|
@@ -2007,8 +2008,11 @@
|
|
|
2007
2008
|
}
|
|
2008
2009
|
return props;
|
|
2009
2010
|
}
|
|
2010
|
-
function
|
|
2011
|
-
|
|
2011
|
+
function deduceArrayType(x2, constructor) {
|
|
2012
|
+
if (constructor === Array || !Number.isFinite(x2)) {
|
|
2013
|
+
return Array;
|
|
2014
|
+
}
|
|
2015
|
+
return constructor === Float64Array || Math.fround(x2) !== x2 ? Float64Array : Float32Array;
|
|
2012
2016
|
}
|
|
2013
2017
|
|
|
2014
2018
|
// src/lib/parse-mvt.ts
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/mvt",
|
|
3
3
|
"description": "Loader for Mapbox Vector Tiles",
|
|
4
|
-
"version": "3.1.0-beta.
|
|
4
|
+
"version": "3.1.0-beta.7",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -32,13 +32,13 @@
|
|
|
32
32
|
"build-worker": "esbuild src/workers/mvt-worker.ts --bundle --outfile=dist/mvt-worker.js"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@loaders.gl/gis": "3.1.0-beta.
|
|
36
|
-
"@loaders.gl/loader-utils": "3.1.0-beta.
|
|
35
|
+
"@loaders.gl/gis": "3.1.0-beta.7",
|
|
36
|
+
"@loaders.gl/loader-utils": "3.1.0-beta.7",
|
|
37
37
|
"@math.gl/polygon": "^3.5.1",
|
|
38
38
|
"pbf": "^3.2.1"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/pbf": "^3.0.2"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "f3b4d81ac02758398c4e4eef5e556b206ef2dfbe"
|
|
44
44
|
}
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
MvtBinaryCoordinates,
|
|
5
5
|
MvtBinaryGeometry,
|
|
6
6
|
MvtBinaryOptions,
|
|
7
|
+
MvtPropArrayConstructor,
|
|
7
8
|
MvtFirstPassedData,
|
|
8
9
|
MvtLines,
|
|
9
10
|
MvtPoints,
|
|
@@ -28,14 +29,16 @@ export function featuresToBinary(
|
|
|
28
29
|
firstPassData: MvtFirstPassedData,
|
|
29
30
|
options?: MvtBinaryOptions
|
|
30
31
|
) {
|
|
32
|
+
const propArrayTypes = extractNumericPropTypes(features);
|
|
33
|
+
const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
|
|
31
34
|
return fillArrays(features, firstPassData, {
|
|
32
|
-
numericPropKeys: options ? options.numericPropKeys :
|
|
35
|
+
numericPropKeys: options ? options.numericPropKeys : numericPropKeys,
|
|
36
|
+
propArrayTypes,
|
|
33
37
|
PositionDataType: options ? options.PositionDataType : Float32Array
|
|
34
38
|
});
|
|
35
39
|
}
|
|
36
40
|
|
|
37
41
|
export const TEST_EXPORTS = {
|
|
38
|
-
extractNumericPropKeys,
|
|
39
42
|
fillArrays
|
|
40
43
|
};
|
|
41
44
|
|
|
@@ -43,26 +46,26 @@ export const TEST_EXPORTS = {
|
|
|
43
46
|
* Extracts properties that are always numeric
|
|
44
47
|
*
|
|
45
48
|
* @param features
|
|
46
|
-
* @returns object with numeric
|
|
49
|
+
* @returns object with numeric types
|
|
47
50
|
*/
|
|
48
|
-
function
|
|
49
|
-
|
|
51
|
+
function extractNumericPropTypes(features: MvtBinaryCoordinates[]): {
|
|
52
|
+
[key: string]: MvtPropArrayConstructor;
|
|
53
|
+
} {
|
|
54
|
+
const propArrayTypes = {};
|
|
50
55
|
for (const feature of features) {
|
|
51
56
|
if (feature.properties) {
|
|
52
57
|
for (const key in feature.properties) {
|
|
53
58
|
// If property has not been seen before, or if property has been numeric
|
|
54
59
|
// in all previous features, check if numeric in this feature
|
|
55
|
-
// If not numeric,
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
numericPropKeys[key] = isNumeric(val);
|
|
60
|
-
}
|
|
60
|
+
// If not numeric, Array is stored to prevent rechecking in the future
|
|
61
|
+
// Additionally, detects if 64 bit precision is required
|
|
62
|
+
const val = feature.properties[key];
|
|
63
|
+
propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);
|
|
61
64
|
}
|
|
62
65
|
}
|
|
63
66
|
}
|
|
64
67
|
|
|
65
|
-
return
|
|
68
|
+
return propArrayTypes;
|
|
66
69
|
}
|
|
67
70
|
|
|
68
71
|
/**
|
|
@@ -90,7 +93,7 @@ function fillArrays(
|
|
|
90
93
|
polygonRingsCount,
|
|
91
94
|
polygonFeaturesCount
|
|
92
95
|
} = firstPassData;
|
|
93
|
-
const {numericPropKeys, PositionDataType = Float32Array} = options;
|
|
96
|
+
const {numericPropKeys, propArrayTypes, PositionDataType = Float32Array} = options;
|
|
94
97
|
const hasGlobalId = features[0] && 'id' in features[0];
|
|
95
98
|
const coordLength = 2;
|
|
96
99
|
const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
|
|
@@ -146,7 +149,8 @@ function fillArrays(
|
|
|
146
149
|
for (const propName of numericPropKeys) {
|
|
147
150
|
// If property has been numeric in all previous features in which the property existed, check
|
|
148
151
|
// if numeric in this feature
|
|
149
|
-
|
|
152
|
+
const TypedArray = propArrayTypes[propName];
|
|
153
|
+
object.numericProps[propName] = new TypedArray(object.positions.length / coordLength);
|
|
150
154
|
}
|
|
151
155
|
}
|
|
152
156
|
|
|
@@ -513,6 +517,11 @@ function keepStringProperties(
|
|
|
513
517
|
return props;
|
|
514
518
|
}
|
|
515
519
|
|
|
516
|
-
function
|
|
517
|
-
|
|
520
|
+
function deduceArrayType(x: any, constructor: MvtPropArrayConstructor): MvtPropArrayConstructor {
|
|
521
|
+
if (constructor === Array || !Number.isFinite(x)) {
|
|
522
|
+
return Array;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
// If this or previous value required 64bits use Float64Array
|
|
526
|
+
return constructor === Float64Array || Math.fround(x) !== x ? Float64Array : Float32Array;
|
|
518
527
|
}
|
package/src/lib/types.ts
CHANGED
|
@@ -37,8 +37,14 @@ export type MvtMapboxCoordinates = {
|
|
|
37
37
|
id?: number;
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
+
export type MvtPropArrayConstructor =
|
|
41
|
+
| Float32ArrayConstructor
|
|
42
|
+
| Float64ArrayConstructor
|
|
43
|
+
| ArrayConstructor;
|
|
44
|
+
|
|
40
45
|
export type MvtBinaryOptions = {
|
|
41
46
|
numericPropKeys: string[];
|
|
47
|
+
propArrayTypes: {[key: string]: MvtPropArrayConstructor};
|
|
42
48
|
PositionDataType: Float32ArrayConstructor;
|
|
43
49
|
};
|
|
44
50
|
|