@loaders.gl/mvt 3.1.0-beta.3 → 3.1.1

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.
Files changed (63) hide show
  1. package/dist/bundle.js +114 -102
  2. package/dist/es5/bundle.js +1 -1
  3. package/dist/es5/bundle.js.map +1 -1
  4. package/dist/es5/helpers/binary-util-functions.js +25 -22
  5. package/dist/es5/helpers/binary-util-functions.js.map +1 -1
  6. package/dist/es5/helpers/mapbox-util-functions.js +11 -11
  7. package/dist/es5/helpers/mapbox-util-functions.js.map +1 -1
  8. package/dist/es5/index.js +2 -2
  9. package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js +137 -108
  10. package/dist/es5/lib/binary-vector-tile/vector-tile-feature.js.map +1 -1
  11. package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js +23 -15
  12. package/dist/es5/lib/binary-vector-tile/vector-tile-layer.js.map +1 -1
  13. package/dist/es5/lib/binary-vector-tile/vector-tile.js +8 -8
  14. package/dist/es5/lib/binary-vector-tile/vector-tile.js.map +1 -1
  15. package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js +157 -147
  16. package/dist/es5/lib/mapbox-vector-tile/vector-tile-feature.js.map +1 -1
  17. package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js +23 -15
  18. package/dist/es5/lib/mapbox-vector-tile/vector-tile-layer.js.map +1 -1
  19. package/dist/es5/lib/mapbox-vector-tile/vector-tile.js +8 -8
  20. package/dist/es5/lib/mapbox-vector-tile/vector-tile.js.map +1 -1
  21. package/dist/es5/lib/parse-mvt.js +38 -35
  22. package/dist/es5/lib/parse-mvt.js.map +1 -1
  23. package/dist/es5/mvt-loader.js +38 -5
  24. package/dist/es5/mvt-loader.js.map +1 -1
  25. package/dist/esm/helpers/binary-util-functions.js +8 -5
  26. package/dist/esm/helpers/binary-util-functions.js.map +1 -1
  27. package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js +31 -30
  28. package/dist/esm/lib/binary-vector-tile/vector-tile-feature.js.map +1 -1
  29. package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js +2 -2
  30. package/dist/esm/lib/binary-vector-tile/vector-tile-layer.js.map +1 -1
  31. package/dist/esm/lib/parse-mvt.js +6 -5
  32. package/dist/esm/lib/parse-mvt.js.map +1 -1
  33. package/dist/esm/mvt-loader.js +1 -1
  34. package/dist/esm/mvt-loader.js.map +1 -1
  35. package/dist/helpers/binary-util-functions.d.ts +2 -6
  36. package/dist/helpers/binary-util-functions.d.ts.map +1 -1
  37. package/dist/helpers/binary-util-functions.js +7 -5
  38. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts +12 -7
  39. package/dist/lib/binary-vector-tile/vector-tile-feature.d.ts.map +1 -1
  40. package/dist/lib/binary-vector-tile/vector-tile-feature.js +32 -39
  41. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts +3 -3
  42. package/dist/lib/binary-vector-tile/vector-tile-layer.d.ts.map +1 -1
  43. package/dist/lib/binary-vector-tile/vector-tile-layer.js +3 -3
  44. package/dist/lib/parse-mvt.d.ts +8 -76
  45. package/dist/lib/parse-mvt.d.ts.map +1 -1
  46. package/dist/lib/parse-mvt.js +6 -5
  47. package/dist/lib/types.d.ts +0 -64
  48. package/dist/lib/types.d.ts.map +1 -1
  49. package/dist/mvt-worker.js +102 -97
  50. package/package.json +5 -4
  51. package/src/helpers/binary-util-functions.ts +9 -7
  52. package/src/lib/binary-vector-tile/vector-tile-feature.ts +36 -44
  53. package/src/lib/binary-vector-tile/vector-tile-layer.ts +4 -4
  54. package/src/lib/parse-mvt.ts +10 -8
  55. package/src/lib/types.ts +0 -69
  56. package/dist/es5/lib/binary-vector-tile/features-to-binary.js +0 -338
  57. package/dist/es5/lib/binary-vector-tile/features-to-binary.js.map +0 -1
  58. package/dist/esm/lib/binary-vector-tile/features-to-binary.js +0 -327
  59. package/dist/esm/lib/binary-vector-tile/features-to-binary.js.map +0 -1
  60. package/dist/lib/binary-vector-tile/features-to-binary.d.ts +0 -185
  61. package/dist/lib/binary-vector-tile/features-to-binary.d.ts.map +0 -1
  62. package/dist/lib/binary-vector-tile/features-to-binary.js +0 -353
  63. package/src/lib/binary-vector-tile/features-to-binary.ts +0 -518
@@ -1 +0,0 @@
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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AAChC,SAAK,MAAMI,WAAX,IAA0BJ,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,327 +0,0 @@
1
- import { earcut } from '@math.gl/polygon';
2
- export function featuresToBinary(features, firstPassData, options) {
3
- return fillArrays(features, firstPassData, {
4
- numericPropKeys: options ? options.numericPropKeys : extractNumericPropKeys(features),
5
- PositionDataType: options ? options.PositionDataType : Float32Array
6
- });
7
- }
8
- export const TEST_EXPORTS = {
9
- extractNumericPropKeys,
10
- fillArrays
11
- };
12
-
13
- function extractNumericPropKeys(features) {
14
- const numericPropKeys = {};
15
-
16
- for (const feature of features) {
17
- if (feature.properties) {
18
- for (const key in feature.properties) {
19
- const numericSoFar = numericPropKeys[key];
20
-
21
- if (numericSoFar || numericSoFar === undefined) {
22
- const val = feature.properties[key];
23
- numericPropKeys[key] = isNumeric(val);
24
- }
25
- }
26
- }
27
- }
28
-
29
- return Object.keys(numericPropKeys).filter(k => numericPropKeys[k]);
30
- }
31
-
32
- function fillArrays(features, firstPassData, options) {
33
- const {
34
- pointPositionsCount,
35
- pointFeaturesCount,
36
- linePositionsCount,
37
- linePathsCount,
38
- lineFeaturesCount,
39
- polygonPositionsCount,
40
- polygonObjectsCount,
41
- polygonRingsCount,
42
- polygonFeaturesCount
43
- } = firstPassData;
44
- const {
45
- numericPropKeys,
46
- PositionDataType = Float32Array
47
- } = options;
48
- const hasGlobalId = features[0] && 'id' in features[0];
49
- const coordLength = 2;
50
- const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
51
- const points = {
52
- positions: new PositionDataType(pointPositionsCount * coordLength),
53
- globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
54
- featureIds: pointFeaturesCount > 65535 ? new Uint32Array(pointPositionsCount) : new Uint16Array(pointPositionsCount),
55
- numericProps: {},
56
- properties: [],
57
- fields: []
58
- };
59
- const lines = {
60
- pathIndices: linePositionsCount > 65535 ? new Uint32Array(linePathsCount + 1) : new Uint16Array(linePathsCount + 1),
61
- positions: new PositionDataType(linePositionsCount * coordLength),
62
- globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
63
- featureIds: lineFeaturesCount > 65535 ? new Uint32Array(linePositionsCount) : new Uint16Array(linePositionsCount),
64
- numericProps: {},
65
- properties: [],
66
- fields: []
67
- };
68
- const polygons = {
69
- polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
70
- primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
71
- positions: new PositionDataType(polygonPositionsCount * coordLength),
72
- triangles: [],
73
- globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),
74
- featureIds: polygonFeaturesCount > 65535 ? new Uint32Array(polygonPositionsCount) : new Uint16Array(polygonPositionsCount),
75
- numericProps: {},
76
- properties: [],
77
- fields: []
78
- };
79
-
80
- for (const object of [points, lines, polygons]) {
81
- for (const propName of numericPropKeys) {
82
- object.numericProps[propName] = new Float32Array(object.positions.length / coordLength);
83
- }
84
- }
85
-
86
- lines.pathIndices[linePathsCount] = linePositionsCount;
87
- polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;
88
- polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;
89
- const indexMap = {
90
- pointPosition: 0,
91
- pointFeature: 0,
92
- linePosition: 0,
93
- linePath: 0,
94
- lineFeature: 0,
95
- polygonPosition: 0,
96
- polygonObject: 0,
97
- polygonRing: 0,
98
- polygonFeature: 0,
99
- feature: 0
100
- };
101
-
102
- for (const feature of features) {
103
- const geometry = feature.geometry;
104
- const properties = feature.properties || {};
105
-
106
- switch (geometry.type) {
107
- case 'Point':
108
- case 'MultiPoint':
109
- handlePoint(geometry, points, indexMap, coordLength, properties);
110
- points.properties.push(keepStringProperties(properties, numericPropKeys));
111
-
112
- if (hasGlobalId) {
113
- points.fields.push({
114
- id: feature.id
115
- });
116
- }
117
-
118
- indexMap.pointFeature++;
119
- break;
120
-
121
- case 'LineString':
122
- case 'MultiLineString':
123
- handleLineString(geometry, lines, indexMap, coordLength, properties);
124
- lines.properties.push(keepStringProperties(properties, numericPropKeys));
125
-
126
- if (hasGlobalId) {
127
- lines.fields.push({
128
- id: feature.id
129
- });
130
- }
131
-
132
- indexMap.lineFeature++;
133
- break;
134
-
135
- case 'Polygon':
136
- case 'MultiPolygon':
137
- handlePolygon(geometry, polygons, indexMap, coordLength, properties);
138
- polygons.properties.push(keepStringProperties(properties, numericPropKeys));
139
-
140
- if (hasGlobalId) {
141
- polygons.fields.push({
142
- id: feature.id
143
- });
144
- }
145
-
146
- indexMap.polygonFeature++;
147
- break;
148
-
149
- default:
150
- throw new Error('Invalid geometry type');
151
- }
152
-
153
- indexMap.feature++;
154
- }
155
-
156
- return makeAccessorObjects(points, lines, polygons, coordLength);
157
- }
158
-
159
- function handlePoint(geometry, points, indexMap, coordLength, properties) {
160
- points.positions.set(geometry.data, indexMap.pointPosition * coordLength);
161
- const nPositions = geometry.data.length / coordLength;
162
- fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);
163
- points.globalFeatureIds.fill(indexMap.feature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
164
- points.featureIds.fill(indexMap.pointFeature, indexMap.pointPosition, indexMap.pointPosition + nPositions);
165
- indexMap.pointPosition += nPositions;
166
- }
167
-
168
- function handleLineString(geometry, lines, indexMap, coordLength, properties) {
169
- lines.positions.set(geometry.data, indexMap.linePosition * coordLength);
170
- const nPositions = geometry.data.length / coordLength;
171
- fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
172
- lines.globalFeatureIds.fill(indexMap.feature, indexMap.linePosition, indexMap.linePosition + nPositions);
173
- lines.featureIds.fill(indexMap.lineFeature, indexMap.linePosition, indexMap.linePosition + nPositions);
174
-
175
- for (let i = 0, il = geometry.lines.length; i < il; ++i) {
176
- const start = geometry.lines[i];
177
- const end = i === il - 1 ? geometry.data.length : geometry.lines[i + 1];
178
- lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
179
- indexMap.linePosition += (end - start) / coordLength;
180
- }
181
- }
182
-
183
- function handlePolygon(geometry, polygons, indexMap, coordLength, properties) {
184
- polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);
185
- const nPositions = geometry.data.length / coordLength;
186
- fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
187
- polygons.globalFeatureIds.fill(indexMap.feature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
188
- polygons.featureIds.fill(indexMap.polygonFeature, indexMap.polygonPosition, indexMap.polygonPosition + nPositions);
189
-
190
- for (let l = 0, ll = geometry.lines.length; l < ll; ++l) {
191
- const startPosition = indexMap.polygonPosition;
192
- polygons.polygonIndices[indexMap.polygonObject++] = startPosition;
193
- const areas = geometry.areas[l];
194
- const lines = geometry.lines[l];
195
- const nextLines = geometry.lines[l + 1];
196
-
197
- for (let i = 0, il = lines.length; i < il; ++i) {
198
- const start = lines[i];
199
- const end = i === il - 1 ? nextLines === undefined ? geometry.data.length : nextLines[0] : lines[i + 1];
200
- polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
201
- indexMap.polygonPosition += (end - start) / coordLength;
202
- }
203
-
204
- const endPosition = indexMap.polygonPosition;
205
- triangulatePolygon(polygons, areas, lines, {
206
- startPosition,
207
- endPosition,
208
- coordLength
209
- });
210
- }
211
- }
212
-
213
- function triangulatePolygon(polygons, areas, lines, {
214
- startPosition,
215
- endPosition,
216
- coordLength
217
- }) {
218
- const start = startPosition * coordLength;
219
- const end = endPosition * coordLength;
220
- const polygonPositions = polygons.positions.subarray(start, end);
221
- const offset = lines[0];
222
- const holes = lines.slice(1).map(n => (n - offset) / coordLength);
223
- const indices = earcut(polygonPositions, holes, coordLength, areas);
224
-
225
- for (let t = 0, tl = indices.length; t < tl; ++t) {
226
- polygons.triangles.push(startPosition + indices[t]);
227
- }
228
- }
229
-
230
- function makeAccessorObjects(points, lines, polygons, coordLength) {
231
- const returnObj = {
232
- points: { ...points,
233
- positions: {
234
- value: points.positions,
235
- size: coordLength
236
- },
237
- globalFeatureIds: {
238
- value: points.globalFeatureIds,
239
- size: 1
240
- },
241
- featureIds: {
242
- value: points.featureIds,
243
- size: 1
244
- }
245
- },
246
- lines: { ...lines,
247
- pathIndices: {
248
- value: lines.pathIndices,
249
- size: 1
250
- },
251
- positions: {
252
- value: lines.positions,
253
- size: coordLength
254
- },
255
- globalFeatureIds: {
256
- value: lines.globalFeatureIds,
257
- size: 1
258
- },
259
- featureIds: {
260
- value: lines.featureIds,
261
- size: 1
262
- }
263
- },
264
- polygons: { ...polygons,
265
- polygonIndices: {
266
- value: polygons.polygonIndices,
267
- size: 1
268
- },
269
- primitivePolygonIndices: {
270
- value: polygons.primitivePolygonIndices,
271
- size: 1
272
- },
273
- positions: {
274
- value: polygons.positions,
275
- size: coordLength
276
- },
277
- triangles: {
278
- value: new Uint32Array(polygons.triangles),
279
- size: 1
280
- },
281
- globalFeatureIds: {
282
- value: polygons.globalFeatureIds,
283
- size: 1
284
- },
285
- featureIds: {
286
- value: polygons.featureIds,
287
- size: 1
288
- }
289
- }
290
- };
291
-
292
- for (const geomType in returnObj) {
293
- for (const numericProp in returnObj[geomType].numericProps) {
294
- returnObj[geomType].numericProps[numericProp] = {
295
- value: returnObj[geomType].numericProps[numericProp],
296
- size: 1
297
- };
298
- }
299
- }
300
-
301
- return returnObj;
302
- }
303
-
304
- function fillNumericProperties(object, properties, index, length) {
305
- for (const numericPropName in object.numericProps) {
306
- if (numericPropName in properties) {
307
- object.numericProps[numericPropName].fill(properties[numericPropName], index, index + length);
308
- }
309
- }
310
- }
311
-
312
- function keepStringProperties(properties, numericKeys) {
313
- const props = {};
314
-
315
- for (const key in properties) {
316
- if (!numericKeys.includes(key)) {
317
- props[key] = properties[key];
318
- }
319
- }
320
-
321
- return props;
322
- }
323
-
324
- function isNumeric(x) {
325
- return Number.isFinite(x);
326
- }
327
- //# sourceMappingURL=features-to-binary.js.map
@@ -1 +0,0 @@
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,sBA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AAX,IAA0BJ,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,185 +0,0 @@
1
- import { MvtBinaryCoordinates, MvtBinaryOptions, MvtFirstPassedData } from '../types';
2
- /**
3
- * Convert binary features to flat binary arrays. Similar to
4
- * `geojsonToBinary` helper function, except that it expects
5
- * a binary representation of the feature data, which enables
6
- * 2X-3X speed increase in parse speed, compared to using
7
- * geoJSON. See `binary-vector-tile/VectorTileFeature` for
8
- * data format detais
9
- *
10
- * @param features
11
- * @param firstPassData
12
- * @param options
13
- * @returns filled arrays
14
- */
15
- export declare function featuresToBinary(features: MvtBinaryCoordinates[], firstPassData: MvtFirstPassedData, options?: MvtBinaryOptions): {
16
- points: {
17
- positions: {
18
- value: Float32Array;
19
- size: number;
20
- };
21
- globalFeatureIds: {
22
- value: Uint16Array | Uint32Array;
23
- size: number;
24
- };
25
- featureIds: {
26
- value: Uint16Array | Uint32Array;
27
- size: number;
28
- };
29
- numericProps: object;
30
- properties: {}[];
31
- fields: {
32
- id?: number | undefined;
33
- }[];
34
- };
35
- lines: {
36
- pathIndices: {
37
- value: Uint16Array | Uint32Array;
38
- size: number;
39
- };
40
- positions: {
41
- value: Float32Array;
42
- size: number;
43
- };
44
- globalFeatureIds: {
45
- value: Uint16Array | Uint32Array;
46
- size: number;
47
- };
48
- featureIds: {
49
- value: Uint16Array | Uint32Array;
50
- size: number;
51
- };
52
- numericProps: object;
53
- properties: {}[];
54
- fields: {
55
- id?: number | undefined;
56
- }[];
57
- };
58
- polygons: {
59
- polygonIndices: {
60
- value: Uint16Array | Uint32Array;
61
- size: number;
62
- };
63
- primitivePolygonIndices: {
64
- value: Uint16Array | Uint32Array;
65
- size: number;
66
- };
67
- positions: {
68
- value: Float32Array;
69
- size: number;
70
- };
71
- triangles: {
72
- value: Uint32Array;
73
- size: number;
74
- };
75
- globalFeatureIds: {
76
- value: Uint16Array | Uint32Array;
77
- size: number;
78
- };
79
- featureIds: {
80
- value: Uint16Array | Uint32Array;
81
- size: number;
82
- };
83
- numericProps: object;
84
- properties: {}[];
85
- fields: {
86
- id?: number | undefined;
87
- }[];
88
- };
89
- };
90
- export declare const TEST_EXPORTS: {
91
- extractNumericPropKeys: typeof extractNumericPropKeys;
92
- fillArrays: typeof fillArrays;
93
- };
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
- /**
102
- * Fills coordinates into pre-allocated typed arrays
103
- *
104
- * @param features
105
- * @param firstPassData
106
- * @param options
107
- * @returns an accessor object with value and size keys
108
- */
109
- declare function fillArrays(features: MvtBinaryCoordinates[], firstPassData: MvtFirstPassedData, options: MvtBinaryOptions): {
110
- points: {
111
- positions: {
112
- value: Float32Array;
113
- size: number;
114
- };
115
- globalFeatureIds: {
116
- value: Uint16Array | Uint32Array;
117
- size: number;
118
- };
119
- featureIds: {
120
- value: Uint16Array | Uint32Array;
121
- size: number;
122
- };
123
- numericProps: object;
124
- properties: {}[];
125
- fields: {
126
- id?: number | undefined;
127
- }[];
128
- };
129
- lines: {
130
- pathIndices: {
131
- value: Uint16Array | Uint32Array;
132
- size: number;
133
- };
134
- positions: {
135
- value: Float32Array;
136
- size: number;
137
- };
138
- globalFeatureIds: {
139
- value: Uint16Array | Uint32Array;
140
- size: number;
141
- };
142
- featureIds: {
143
- value: Uint16Array | Uint32Array;
144
- size: number;
145
- };
146
- numericProps: object;
147
- properties: {}[];
148
- fields: {
149
- id?: number | undefined;
150
- }[];
151
- };
152
- polygons: {
153
- polygonIndices: {
154
- value: Uint16Array | Uint32Array;
155
- size: number;
156
- };
157
- primitivePolygonIndices: {
158
- value: Uint16Array | Uint32Array;
159
- size: number;
160
- };
161
- positions: {
162
- value: Float32Array;
163
- size: number;
164
- };
165
- triangles: {
166
- value: Uint32Array;
167
- size: number;
168
- };
169
- globalFeatureIds: {
170
- value: Uint16Array | Uint32Array;
171
- size: number;
172
- };
173
- featureIds: {
174
- value: Uint16Array | Uint32Array;
175
- size: number;
176
- };
177
- numericProps: object;
178
- properties: {}[];
179
- fields: {
180
- id?: number | undefined;
181
- }[];
182
- };
183
- };
184
- export {};
185
- //# sourceMappingURL=features-to-binary.d.ts.map
@@ -1 +0,0 @@
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,EAChB,kBAAkB,EAInB,MAAM,UAAU,CAAC;AAElB;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,oBAAoB,EAAE,EAChC,aAAa,EAAE,kBAAkB,EACjC,OAAO,CAAC,EAAE,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAM3B;AAED,eAAO,MAAM,YAAY;;;CAGxB,CAAC;AAEF;;;;;GAKG;AACH,iBAAS,sBAAsB,CAAC,QAAQ,EAAE,oBAAoB,EAAE,GAAG,MAAM,EAAE,CAkB1E;AAED;;;;;;;GAOG;AAEH,iBAAS,UAAU,CACjB,QAAQ,EAAE,oBAAoB,EAAE,EAChC,aAAa,EAAE,kBAAkB,EACjC,OAAO,EAAE,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoI1B"}