@loaders.gl/gis 3.3.0-alpha.5 → 3.3.0-alpha.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.
Files changed (37) hide show
  1. package/dist/es5/bundle.js +0 -1
  2. package/dist/es5/bundle.js.map +1 -1
  3. package/dist/es5/index.js +12 -17
  4. package/dist/es5/index.js.map +1 -1
  5. package/dist/es5/lib/binary-to-geojson.js +5 -62
  6. package/dist/es5/lib/binary-to-geojson.js.map +1 -1
  7. package/dist/es5/lib/extract-geometry-info.js +8 -43
  8. package/dist/es5/lib/extract-geometry-info.js.map +1 -1
  9. package/dist/es5/lib/flat-geojson-to-binary-types.js.map +1 -1
  10. package/dist/es5/lib/flat-geojson-to-binary.js +30 -59
  11. package/dist/es5/lib/flat-geojson-to-binary.js.map +1 -1
  12. package/dist/es5/lib/geojson-to-binary.js +0 -4
  13. package/dist/es5/lib/geojson-to-binary.js.map +1 -1
  14. package/dist/es5/lib/geojson-to-flat-geojson.js +4 -30
  15. package/dist/es5/lib/geojson-to-flat-geojson.js.map +1 -1
  16. package/dist/es5/lib/transform.js +1 -15
  17. package/dist/es5/lib/transform.js.map +1 -1
  18. package/dist/esm/bundle.js +1 -1
  19. package/dist/esm/bundle.js.map +1 -1
  20. package/dist/esm/index.js +2 -0
  21. package/dist/esm/index.js.map +1 -1
  22. package/dist/esm/lib/binary-to-geojson.js +17 -49
  23. package/dist/esm/lib/binary-to-geojson.js.map +1 -1
  24. package/dist/esm/lib/extract-geometry-info.js +1 -19
  25. package/dist/esm/lib/extract-geometry-info.js.map +1 -1
  26. package/dist/esm/lib/flat-geojson-to-binary-types.js.map +1 -1
  27. package/dist/esm/lib/flat-geojson-to-binary.js +21 -30
  28. package/dist/esm/lib/flat-geojson-to-binary.js.map +1 -1
  29. package/dist/esm/lib/geojson-to-binary.js +5 -3
  30. package/dist/esm/lib/geojson-to-binary.js.map +1 -1
  31. package/dist/esm/lib/geojson-to-flat-geojson.js +7 -19
  32. package/dist/esm/lib/geojson-to-flat-geojson.js.map +1 -1
  33. package/dist/esm/lib/transform.js +1 -8
  34. package/dist/esm/lib/transform.js.map +1 -1
  35. package/dist/lib/flat-geojson-to-binary.js +1 -0
  36. package/package.json +4 -4
  37. package/src/lib/flat-geojson-to-binary.ts +1 -0
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"flat-geojson-to-binary-types.js"}
1
+ {"version":3,"file":"flat-geojson-to-binary-types.js","names":[],"sources":["../../../src/lib/flat-geojson-to-binary-types.ts"],"sourcesContent":["import type {TypedArray} from '@loaders.gl/schema';\n\n/**\n * Permissable constructor for numeric props\n */\nexport type PropArrayConstructor =\n | Float32ArrayConstructor\n | Float64ArrayConstructor\n | ArrayConstructor;\n\n/**\n * Collection type for holding intermediate binary data before conversion to `BinaryPointGeometry`\n */\nexport type Points = {\n type: 'Point';\n positions: Float32Array | Float64Array;\n globalFeatureIds: Uint16Array | Uint32Array;\n featureIds: Uint16Array | Uint32Array;\n numericProps: {[key: string]: TypedArray};\n properties: {}[];\n fields: {\n id?: string | number;\n }[];\n};\n\n/**\n * Collection type for holding intermediate binary data before conversion to `BinaryLineStringGeometry`\n */\nexport type Lines = {\n type: 'LineString';\n positions: Float32Array | Float64Array;\n pathIndices: Uint16Array | Uint32Array;\n globalFeatureIds: Uint16Array | Uint32Array;\n featureIds: Uint16Array | Uint32Array;\n numericProps: {[key: string]: TypedArray};\n properties: {}[];\n fields: {\n id?: string | number;\n }[];\n};\n\n/**\n * Collection type for holding intermediate binary data before conversion to `BinaryPolygonGeometry`\n */\nexport type Polygons = {\n type: 'Polygon';\n positions: Float32Array | Float64Array;\n polygonIndices: Uint16Array | Uint32Array;\n primitivePolygonIndices: Uint16Array | Uint32Array;\n triangles: number[];\n globalFeatureIds: Uint16Array | Uint32Array;\n featureIds: Uint16Array | Uint32Array;\n numericProps: {[key: string]: TypedArray};\n properties: {}[];\n fields: {\n id?: string | number;\n }[];\n};\n"],"mappings":""}
@@ -1,3 +1,4 @@
1
+
1
2
  import { earcut } from '@math.gl/polygon';
2
3
  export function flatGeojsonToBinary(features, geometryInfo, options) {
3
4
  const propArrayTypes = extractNumericPropTypes(features);
@@ -10,13 +11,13 @@ export function flatGeojsonToBinary(features, geometryInfo, options) {
10
11
  PositionDataType: options ? options.PositionDataType : Float32Array
11
12
  });
12
13
  }
14
+
13
15
  export const TEST_EXPORTS = {
14
16
  extractNumericPropTypes
15
17
  };
16
18
 
17
19
  function extractNumericPropTypes(features) {
18
20
  const propArrayTypes = {};
19
-
20
21
  for (const feature of features) {
21
22
  if (feature.properties) {
22
23
  for (const key in feature.properties) {
@@ -25,7 +26,6 @@ function extractNumericPropTypes(features) {
25
26
  }
26
27
  }
27
28
  }
28
-
29
29
  return propArrayTypes;
30
30
  }
31
31
 
@@ -103,55 +103,43 @@ function fillArrays(features, geometryInfo, options) {
103
103
  polygonFeature: 0,
104
104
  feature: 0
105
105
  };
106
-
107
106
  for (const feature of features) {
108
107
  const geometry = feature.geometry;
109
108
  const properties = feature.properties || {};
110
-
111
109
  switch (geometry.type) {
112
110
  case 'Point':
113
111
  handlePoint(geometry, points, indexMap, coordLength, properties);
114
112
  points.properties.push(keepStringProperties(properties, numericPropKeys));
115
-
116
113
  if (hasGlobalId) {
117
114
  points.fields.push({
118
115
  id: feature.id
119
116
  });
120
117
  }
121
-
122
118
  indexMap.pointFeature++;
123
119
  break;
124
-
125
120
  case 'LineString':
126
121
  handleLineString(geometry, lines, indexMap, coordLength, properties);
127
122
  lines.properties.push(keepStringProperties(properties, numericPropKeys));
128
-
129
123
  if (hasGlobalId) {
130
124
  lines.fields.push({
131
125
  id: feature.id
132
126
  });
133
127
  }
134
-
135
128
  indexMap.lineFeature++;
136
129
  break;
137
-
138
130
  case 'Polygon':
139
131
  handlePolygon(geometry, polygons, indexMap, coordLength, properties);
140
132
  polygons.properties.push(keepStringProperties(properties, numericPropKeys));
141
-
142
133
  if (hasGlobalId) {
143
134
  polygons.fields.push({
144
135
  id: feature.id
145
136
  });
146
137
  }
147
-
148
138
  indexMap.polygonFeature++;
149
139
  break;
150
-
151
140
  default:
152
141
  throw new Error('Invalid geometry type');
153
142
  }
154
-
155
143
  indexMap.feature++;
156
144
  }
157
145
 
@@ -173,10 +161,10 @@ function handleLineString(geometry, lines, indexMap, coordLength, properties) {
173
161
  fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
174
162
  lines.globalFeatureIds.fill(indexMap.feature, indexMap.linePosition, indexMap.linePosition + nPositions);
175
163
  lines.featureIds.fill(indexMap.lineFeature, indexMap.linePosition, indexMap.linePosition + nPositions);
176
-
177
164
  for (let i = 0, il = geometry.indices.length; i < il; ++i) {
178
165
  const start = geometry.indices[i];
179
166
  const end = i === il - 1 ? geometry.data.length : geometry.indices[i + 1];
167
+
180
168
  lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;
181
169
  indexMap.linePosition += (end - start) / coordLength;
182
170
  }
@@ -195,14 +183,14 @@ function handlePolygon(geometry, polygons, indexMap, coordLength, properties) {
195
183
  const areas = geometry.areas[l];
196
184
  const indices = geometry.indices[l];
197
185
  const nextIndices = geometry.indices[l + 1];
198
-
199
186
  for (let i = 0, il = indices.length; i < il; ++i) {
200
187
  const start = indices[i];
201
- const end = i === il - 1 ? nextIndices === undefined ? geometry.data.length : nextIndices[0] : indices[i + 1];
188
+ const end = i === il - 1 ?
189
+ nextIndices === undefined ? geometry.data.length : nextIndices[0] : indices[i + 1];
190
+
202
191
  polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
203
192
  indexMap.polygonPosition += (end - start) / coordLength;
204
193
  }
205
-
206
194
  const endPosition = indexMap.polygonPosition;
207
195
  triangulatePolygon(polygons, areas, indices, {
208
196
  startPosition,
@@ -212,16 +200,20 @@ function handlePolygon(geometry, polygons, indexMap, coordLength, properties) {
212
200
  }
213
201
  }
214
202
 
215
- function triangulatePolygon(polygons, areas, indices, {
216
- startPosition,
217
- endPosition,
218
- coordLength
219
- }) {
203
+ function triangulatePolygon(polygons, areas, indices, _ref) {
204
+ let {
205
+ startPosition,
206
+ endPosition,
207
+ coordLength
208
+ } = _ref;
220
209
  const start = startPosition * coordLength;
221
210
  const end = endPosition * coordLength;
211
+
222
212
  const polygonPositions = polygons.positions.subarray(start, end);
213
+
223
214
  const offset = indices[0];
224
215
  const holes = indices.slice(1).map(n => (n - offset) / coordLength);
216
+
225
217
  const triangles = earcut(polygonPositions, holes, coordLength, areas);
226
218
 
227
219
  for (let t = 0, tl = triangles.length; t < tl; ++t) {
@@ -231,20 +223,19 @@ function triangulatePolygon(polygons, areas, indices, {
231
223
 
232
224
  function wrapProps(obj, size) {
233
225
  const returnObj = {};
234
-
235
226
  for (const key in obj) {
236
227
  returnObj[key] = {
237
228
  value: obj[key],
238
229
  size
239
230
  };
240
231
  }
241
-
242
232
  return returnObj;
243
233
  }
244
234
 
245
235
  function makeAccessorObjects(points, lines, polygons, coordLength) {
246
236
  return {
247
- points: { ...points,
237
+ points: {
238
+ ...points,
248
239
  positions: {
249
240
  value: points.positions,
250
241
  size: coordLength
@@ -259,7 +250,8 @@ function makeAccessorObjects(points, lines, polygons, coordLength) {
259
250
  },
260
251
  numericProps: wrapProps(points.numericProps, 1)
261
252
  },
262
- lines: { ...lines,
253
+ lines: {
254
+ ...lines,
263
255
  positions: {
264
256
  value: lines.positions,
265
257
  size: coordLength
@@ -278,7 +270,8 @@ function makeAccessorObjects(points, lines, polygons, coordLength) {
278
270
  },
279
271
  numericProps: wrapProps(lines.numericProps, 1)
280
272
  },
281
- polygons: { ...polygons,
273
+ polygons: {
274
+ ...polygons,
282
275
  positions: {
283
276
  value: polygons.positions,
284
277
  size: coordLength
@@ -319,13 +312,11 @@ function fillNumericProperties(object, properties, index, length) {
319
312
 
320
313
  function keepStringProperties(properties, numericKeys) {
321
314
  const props = {};
322
-
323
315
  for (const key in properties) {
324
316
  if (!numericKeys.includes(key)) {
325
317
  props[key] = properties[key];
326
318
  }
327
319
  }
328
-
329
320
  return props;
330
321
  }
331
322
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/flat-geojson-to-binary.ts"],"names":["earcut","flatGeojsonToBinary","features","geometryInfo","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","coordLength","hasGlobalId","GlobalFeatureIdsDataType","length","Uint32Array","Uint16Array","points","type","positions","globalFeatureIds","featureIds","numericProps","fields","lines","pathIndices","polygons","polygonIndices","primitivePolygonIndices","triangles","object","propName","T","indexMap","pointPosition","pointFeature","linePosition","linePath","lineFeature","polygonPosition","polygonObject","polygonRing","polygonFeature","geometry","handlePoint","push","keepStringProperties","id","handleLineString","handlePolygon","Error","makeAccessorObjects","set","data","nPositions","fillNumericProperties","fill","i","il","indices","start","end","l","ll","startPosition","areas","nextIndices","undefined","endPosition","triangulatePolygon","polygonPositions","subarray","offset","holes","slice","map","n","t","tl","wrapProps","obj","size","returnObj","value","index","numericPropName","numericKeys","props","includes","x","constructor","Number","isFinite","Float64Array","Math","fround"],"mappings":"AACA,SAAQA,MAAR,QAAqB,kBAArB;AA0BA,OAAO,SAASC,mBAAT,CACLC,QADK,EAELC,YAFK,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,CACfX,QADe,EAEf;AACEG,IAAAA,cADF;AAEE,OAAGF;AAFL,GAFe,EAMf;AACEI,IAAAA,eAAe,EAAGH,OAAO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AACD,SAAOwF,KAAP;AACD;;AAUD,SAAStF,eAAT,CAAyBwF,CAAzB,EAAiCC,WAAjC,EAA0F;AACxF,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 type {\n BinaryAttribute,\n BinaryFeatures,\n FlatFeature,\n FlatPoint,\n FlatLineString,\n FlatPolygon,\n GeojsonGeometryInfo,\n TypedArray\n} from '@loaders.gl/schema';\nimport {PropArrayConstructor, Lines, Points, Polygons} from './flat-geojson-to-binary-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 geometryInfo\n * @param options\n * @returns filled arrays\n */\nexport function flatGeojsonToBinary(\n features: FlatFeature[],\n geometryInfo: GeojsonGeometryInfo,\n options?: FlatGeojsonToBinaryOptions\n) {\n const propArrayTypes = extractNumericPropTypes(features);\n const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);\n return fillArrays(\n features,\n {\n propArrayTypes,\n ...geometryInfo\n },\n {\n numericPropKeys: (options && options.numericPropKeys) || numericPropKeys,\n PositionDataType: options ? options.PositionDataType : Float32Array\n }\n );\n}\n\n/**\n * Options for `flatGeojsonToBinary`\n */\nexport type FlatGeojsonToBinaryOptions = {\n numericPropKeys?: string[];\n PositionDataType?: Float32ArrayConstructor | Float64ArrayConstructor;\n};\n\nexport const TEST_EXPORTS = {\n extractNumericPropTypes\n};\n\n/**\n * Extracts properties that are always numeric\n *\n * @param features\n * @returns object with numeric types\n */\nfunction extractNumericPropTypes(features: FlatFeature[]): {\n [key: string]: PropArrayConstructor;\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 geometryInfo\n * @param options\n * @returns an accessor object with value and size keys\n */\n// eslint-disable-next-line complexity\nfunction fillArrays(\n features: FlatFeature[],\n geometryInfo: GeojsonGeometryInfo & {\n propArrayTypes: {[key: string]: PropArrayConstructor};\n },\n options: FlatGeojsonToBinaryOptions\n) {\n const {\n pointPositionsCount,\n pointFeaturesCount,\n linePositionsCount,\n linePathsCount,\n lineFeaturesCount,\n polygonPositionsCount,\n polygonObjectsCount,\n polygonRingsCount,\n polygonFeaturesCount,\n propArrayTypes,\n coordLength\n } = geometryInfo;\n const {numericPropKeys = [], PositionDataType = Float32Array} = options;\n const hasGlobalId = features[0] && 'id' in features[0];\n const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;\n const points: Points = {\n type: 'Point',\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: Lines = {\n type: 'LineString',\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: Polygons = {\n type: 'Polygon',\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 T = propArrayTypes[propName];\n object.numericProps[propName] = new T(object.positions.length / coordLength) as TypedArray;\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 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 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 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: FlatPoint,\n points: Points,\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: FlatLineString,\n lines: Lines,\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.indices.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.indices[i];\n const end =\n i === il - 1\n ? geometry.data.length // last line, so read to end of data\n : geometry.indices[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: FlatPolygon,\n polygons: Polygons,\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.indices is a 2D array\n for (let l = 0, ll = geometry.indices.length; l < ll; ++l) {\n const startPosition = indexMap.polygonPosition;\n polygons.polygonIndices[indexMap.polygonObject++] = startPosition;\n\n const areas = geometry.areas[l];\n const indices = geometry.indices[l];\n const nextIndices = geometry.indices[l + 1];\n\n for (let i = 0, il = indices.length; i < il; ++i) {\n const start = indices[i];\n const end =\n i === il - 1\n ? // last line, so either read to:\n nextIndices === undefined\n ? geometry.data.length // end of data (no next indices)\n : nextIndices[0] // start of first line in nextIndices\n : indices[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, indices, {startPosition, endPosition, coordLength});\n }\n}\n\n/**\n * Triangulate polygon using earcut\n *\n * @param polygons\n * @param areas\n * @param indices\n * @param param3\n */\nfunction triangulatePolygon(\n polygons: Polygons,\n areas: number[],\n indices: 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 = indices[0];\n const holes = indices.slice(1).map((n: number) => (n - offset) / coordLength);\n\n // Compute triangulation\n const triangles = 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 = triangles.length; t < tl; ++t) {\n polygons.triangles.push(startPosition + triangles[t]);\n }\n}\n\n/**\n * Wraps an object containing array into accessors\n *\n * @param obj\n * @param size\n */\nfunction wrapProps(\n obj: {[key: string]: TypedArray},\n size: number\n): {[key: string]: BinaryAttribute} {\n const returnObj = {};\n for (const key in obj) {\n returnObj[key] = {value: obj[key], size};\n }\n return returnObj;\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: Points,\n lines: Lines,\n polygons: Polygons,\n coordLength: number\n): BinaryFeatures {\n return {\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 numericProps: wrapProps(points.numericProps, 1)\n },\n lines: {\n ...lines,\n positions: {value: lines.positions, size: coordLength},\n pathIndices: {value: lines.pathIndices, size: 1},\n globalFeatureIds: {value: lines.globalFeatureIds, size: 1},\n featureIds: {value: lines.featureIds, size: 1},\n numericProps: wrapProps(lines.numericProps, 1)\n },\n polygons: {\n ...polygons,\n positions: {value: polygons.positions, size: coordLength},\n polygonIndices: {value: polygons.polygonIndices, size: 1},\n primitivePolygonIndices: {value: polygons.primitivePolygonIndices, size: 1},\n triangles: {value: new Uint32Array(polygons.triangles), size: 1},\n globalFeatureIds: {value: polygons.globalFeatureIds, size: 1},\n featureIds: {value: polygons.featureIds, size: 1},\n numericProps: wrapProps(polygons.numericProps, 1)\n }\n };\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: Points | Lines | Polygons,\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 const value = properties[numericPropName] as number;\n object.numericProps[numericPropName].fill(value, 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\n/**\n *\n * Deduce correct array constructor to use for a given value\n *\n * @param x value to test\n * @param constructor previous constructor deduced\n * @returns PropArrayConstructor\n */\nfunction deduceArrayType(x: any, constructor: PropArrayConstructor): PropArrayConstructor {\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":"flat-geojson-to-binary.js"}
1
+ {"version":3,"file":"flat-geojson-to-binary.js","names":["earcut","flatGeojsonToBinary","features","geometryInfo","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","coordLength","hasGlobalId","GlobalFeatureIdsDataType","length","Uint32Array","Uint16Array","points","type","positions","globalFeatureIds","featureIds","numericProps","fields","lines","pathIndices","polygons","polygonIndices","primitivePolygonIndices","triangles","object","propName","T","indexMap","pointPosition","pointFeature","linePosition","linePath","lineFeature","polygonPosition","polygonObject","polygonRing","polygonFeature","geometry","handlePoint","push","keepStringProperties","id","handleLineString","handlePolygon","Error","makeAccessorObjects","set","data","nPositions","fillNumericProperties","fill","i","il","indices","start","end","l","ll","startPosition","areas","nextIndices","undefined","endPosition","triangulatePolygon","polygonPositions","subarray","offset","holes","slice","map","n","t","tl","wrapProps","obj","size","returnObj","value","index","numericPropName","numericKeys","props","includes","x","constructor","Number","isFinite","Float64Array","Math","fround"],"sources":["../../../src/lib/flat-geojson-to-binary.ts"],"sourcesContent":["/* eslint-disable indent */\nimport {earcut} from '@math.gl/polygon';\nimport type {\n BinaryAttribute,\n BinaryFeatures,\n FlatFeature,\n FlatPoint,\n FlatLineString,\n FlatPolygon,\n GeojsonGeometryInfo,\n TypedArray\n} from '@loaders.gl/schema';\nimport {PropArrayConstructor, Lines, Points, Polygons} from './flat-geojson-to-binary-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 geometryInfo\n * @param options\n * @returns filled arrays\n */\nexport function flatGeojsonToBinary(\n features: FlatFeature[],\n geometryInfo: GeojsonGeometryInfo,\n options?: FlatGeojsonToBinaryOptions\n) {\n const propArrayTypes = extractNumericPropTypes(features);\n const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);\n return fillArrays(\n features,\n {\n propArrayTypes,\n ...geometryInfo\n },\n {\n numericPropKeys: (options && options.numericPropKeys) || numericPropKeys,\n PositionDataType: options ? options.PositionDataType : Float32Array\n }\n );\n}\n\n/**\n * Options for `flatGeojsonToBinary`\n */\nexport type FlatGeojsonToBinaryOptions = {\n numericPropKeys?: string[];\n PositionDataType?: Float32ArrayConstructor | Float64ArrayConstructor;\n};\n\nexport const TEST_EXPORTS = {\n extractNumericPropTypes\n};\n\n/**\n * Extracts properties that are always numeric\n *\n * @param features\n * @returns object with numeric types\n */\nfunction extractNumericPropTypes(features: FlatFeature[]): {\n [key: string]: PropArrayConstructor;\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 geometryInfo\n * @param options\n * @returns an accessor object with value and size keys\n */\n// eslint-disable-next-line complexity\nfunction fillArrays(\n features: FlatFeature[],\n geometryInfo: GeojsonGeometryInfo & {\n propArrayTypes: {[key: string]: PropArrayConstructor};\n },\n options: FlatGeojsonToBinaryOptions\n) {\n const {\n pointPositionsCount,\n pointFeaturesCount,\n linePositionsCount,\n linePathsCount,\n lineFeaturesCount,\n polygonPositionsCount,\n polygonObjectsCount,\n polygonRingsCount,\n polygonFeaturesCount,\n propArrayTypes,\n coordLength\n } = geometryInfo;\n const {numericPropKeys = [], PositionDataType = Float32Array} = options;\n const hasGlobalId = features[0] && 'id' in features[0];\n const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;\n const points: Points = {\n type: 'Point',\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: Lines = {\n type: 'LineString',\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: Polygons = {\n type: 'Polygon',\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 T = propArrayTypes[propName];\n object.numericProps[propName] = new T(object.positions.length / coordLength) as TypedArray;\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 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 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 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: FlatPoint,\n points: Points,\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: FlatLineString,\n lines: Lines,\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.indices.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.indices[i];\n const end =\n i === il - 1\n ? geometry.data.length // last line, so read to end of data\n : geometry.indices[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: FlatPolygon,\n polygons: Polygons,\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.indices is a 2D array\n for (let l = 0, ll = geometry.indices.length; l < ll; ++l) {\n const startPosition = indexMap.polygonPosition;\n polygons.polygonIndices[indexMap.polygonObject++] = startPosition;\n\n const areas = geometry.areas[l];\n const indices = geometry.indices[l];\n const nextIndices = geometry.indices[l + 1];\n\n for (let i = 0, il = indices.length; i < il; ++i) {\n const start = indices[i];\n const end =\n i === il - 1\n ? // last line, so either read to:\n nextIndices === undefined\n ? geometry.data.length // end of data (no next indices)\n : nextIndices[0] // start of first line in nextIndices\n : indices[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, indices, {startPosition, endPosition, coordLength});\n }\n}\n\n/**\n * Triangulate polygon using earcut\n *\n * @param polygons\n * @param areas\n * @param indices\n * @param param3\n */\nfunction triangulatePolygon(\n polygons: Polygons,\n areas: number[],\n indices: 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 = indices[0];\n const holes = indices.slice(1).map((n: number) => (n - offset) / coordLength);\n\n // Compute triangulation\n // @ts-expect-error TODO can earcut handle binary arrays? Add tests?\n const triangles = 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 = triangles.length; t < tl; ++t) {\n polygons.triangles.push(startPosition + triangles[t]);\n }\n}\n\n/**\n * Wraps an object containing array into accessors\n *\n * @param obj\n * @param size\n */\nfunction wrapProps(\n obj: {[key: string]: TypedArray},\n size: number\n): {[key: string]: BinaryAttribute} {\n const returnObj = {};\n for (const key in obj) {\n returnObj[key] = {value: obj[key], size};\n }\n return returnObj;\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: Points,\n lines: Lines,\n polygons: Polygons,\n coordLength: number\n): BinaryFeatures {\n return {\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 numericProps: wrapProps(points.numericProps, 1)\n },\n lines: {\n ...lines,\n positions: {value: lines.positions, size: coordLength},\n pathIndices: {value: lines.pathIndices, size: 1},\n globalFeatureIds: {value: lines.globalFeatureIds, size: 1},\n featureIds: {value: lines.featureIds, size: 1},\n numericProps: wrapProps(lines.numericProps, 1)\n },\n polygons: {\n ...polygons,\n positions: {value: polygons.positions, size: coordLength},\n polygonIndices: {value: polygons.polygonIndices, size: 1},\n primitivePolygonIndices: {value: polygons.primitivePolygonIndices, size: 1},\n triangles: {value: new Uint32Array(polygons.triangles), size: 1},\n globalFeatureIds: {value: polygons.globalFeatureIds, size: 1},\n featureIds: {value: polygons.featureIds, size: 1},\n numericProps: wrapProps(polygons.numericProps, 1)\n }\n };\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: Points | Lines | Polygons,\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 const value = properties[numericPropName] as number;\n object.numericProps[numericPropName].fill(value, 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\n/**\n *\n * Deduce correct array constructor to use for a given value\n *\n * @param x value to test\n * @param constructor previous constructor deduced\n * @returns PropArrayConstructor\n */\nfunction deduceArrayType(x: any, constructor: PropArrayConstructor): PropArrayConstructor {\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"],"mappings":";AACA,SAAQA,MAAM,QAAO,kBAAkB;AA0BvC,OAAO,SAASC,mBAAmB,CACjCC,QAAuB,EACvBC,YAAiC,EACjCC,OAAoC,EACpC;EACA,MAAMC,cAAc,GAAGC,uBAAuB,CAACJ,QAAQ,CAAC;EACxD,MAAMK,eAAe,GAAGC,MAAM,CAACC,IAAI,CAACJ,cAAc,CAAC,CAACK,MAAM,CAAEC,CAAC,IAAKN,cAAc,CAACM,CAAC,CAAC,KAAKC,KAAK,CAAC;EAC9F,OAAOC,UAAU,CACfX,QAAQ,EACR;IACEG,cAAc;IACd,GAAGF;EACL,CAAC,EACD;IACEI,eAAe,EAAGH,OAAO,IAAIA,OAAO,CAACG,eAAe,IAAKA,eAAe;IACxEO,gBAAgB,EAAEV,OAAO,GAAGA,OAAO,CAACU,gBAAgB,GAAGC;EACzD,CAAC,CACF;AACH;;AAUA,OAAO,MAAMC,YAAY,GAAG;EAC1BV;AACF,CAAC;;AAQD,SAASA,uBAAuB,CAACJ,QAAuB,EAEtD;EACA,MAAMG,cAAc,GAAG,CAAC,CAAC;EACz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G,WAAW,KAAKG,YAAY,IAAIC,IAAI,CAACC,MAAM,CAACN,CAAC,CAAC,KAAKA,CAAC,GAAGI,YAAY,GAAGlG,YAAY;AAC3F"}
@@ -1,9 +1,11 @@
1
1
  import { extractGeometryInfo } from './extract-geometry-info';
2
2
  import { geojsonToFlatGeojson } from './geojson-to-flat-geojson';
3
3
  import { flatGeojsonToBinary } from './flat-geojson-to-binary';
4
- export function geojsonToBinary(features, options = {
5
- fixRingWinding: true
6
- }) {
4
+
5
+ export function geojsonToBinary(features) {
6
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
7
+ fixRingWinding: true
8
+ };
7
9
  const geometryInfo = extractGeometryInfo(features);
8
10
  const coordLength = geometryInfo.coordLength;
9
11
  const {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/geojson-to-binary.ts"],"names":["extractGeometryInfo","geojsonToFlatGeojson","flatGeojsonToBinary","geojsonToBinary","features","options","fixRingWinding","geometryInfo","coordLength","flatFeatures","numericPropKeys","PositionDataType","Float32Array"],"mappings":"AAGA,SAAQA,mBAAR,QAAkC,yBAAlC;AACA,SAAQC,oBAAR,QAAmC,2BAAnC;AACA,SAAQC,mBAAR,QAAkC,0BAAlC;AAkBA,OAAO,SAASC,eAAT,CACLC,QADK,EAELC,OAA+B,GAAG;AAACC,EAAAA,cAAc,EAAE;AAAjB,CAF7B,EAGW;AAChB,QAAMC,YAAY,GAAGP,mBAAmB,CAACI,QAAD,CAAxC;AACA,QAAMI,WAAW,GAAGD,YAAY,CAACC,WAAjC;AACA,QAAM;AAACF,IAAAA;AAAD,MAAmBD,OAAzB;AACA,QAAMI,YAAY,GAAGR,oBAAoB,CAACG,QAAD,EAAW;AAACI,IAAAA,WAAD;AAAcF,IAAAA;AAAd,GAAX,CAAzC;AACA,SAAOJ,mBAAmB,CAACO,YAAD,EAAeF,YAAf,EAA6B;AACrDG,IAAAA,eAAe,EAAEL,OAAO,CAACK,eAD4B;AAErDC,IAAAA,gBAAgB,EAAEN,OAAO,CAACM,gBAAR,IAA4BC;AAFO,GAA7B,CAA1B;AAID","sourcesContent":["import type {Feature} from '@loaders.gl/schema';\nimport type {BinaryFeatures} from '@loaders.gl/schema';\n\nimport {extractGeometryInfo} from './extract-geometry-info';\nimport {geojsonToFlatGeojson} from './geojson-to-flat-geojson';\nimport {flatGeojsonToBinary} from './flat-geojson-to-binary';\n\n/**\n * Options for `geojsonToBinary`\n */\nexport type GeojsonToBinaryOptions = {\n fixRingWinding: boolean;\n numericPropKeys?: string[];\n PositionDataType?: Float32ArrayConstructor | Float64ArrayConstructor;\n};\n\n/**\n * Convert GeoJSON features to flat binary arrays\n *\n * @param features\n * @param options\n * @returns features in binary format, grouped by geometry type\n */\nexport function geojsonToBinary(\n features: Feature[],\n options: GeojsonToBinaryOptions = {fixRingWinding: true}\n): BinaryFeatures {\n const geometryInfo = extractGeometryInfo(features);\n const coordLength = geometryInfo.coordLength;\n const {fixRingWinding} = options;\n const flatFeatures = geojsonToFlatGeojson(features, {coordLength, fixRingWinding});\n return flatGeojsonToBinary(flatFeatures, geometryInfo, {\n numericPropKeys: options.numericPropKeys,\n PositionDataType: options.PositionDataType || Float32Array\n });\n}\n"],"file":"geojson-to-binary.js"}
1
+ {"version":3,"file":"geojson-to-binary.js","names":["extractGeometryInfo","geojsonToFlatGeojson","flatGeojsonToBinary","geojsonToBinary","features","options","fixRingWinding","geometryInfo","coordLength","flatFeatures","numericPropKeys","PositionDataType","Float32Array"],"sources":["../../../src/lib/geojson-to-binary.ts"],"sourcesContent":["import type {Feature} from '@loaders.gl/schema';\nimport type {BinaryFeatures} from '@loaders.gl/schema';\n\nimport {extractGeometryInfo} from './extract-geometry-info';\nimport {geojsonToFlatGeojson} from './geojson-to-flat-geojson';\nimport {flatGeojsonToBinary} from './flat-geojson-to-binary';\n\n/**\n * Options for `geojsonToBinary`\n */\nexport type GeojsonToBinaryOptions = {\n fixRingWinding: boolean;\n numericPropKeys?: string[];\n PositionDataType?: Float32ArrayConstructor | Float64ArrayConstructor;\n};\n\n/**\n * Convert GeoJSON features to flat binary arrays\n *\n * @param features\n * @param options\n * @returns features in binary format, grouped by geometry type\n */\nexport function geojsonToBinary(\n features: Feature[],\n options: GeojsonToBinaryOptions = {fixRingWinding: true}\n): BinaryFeatures {\n const geometryInfo = extractGeometryInfo(features);\n const coordLength = geometryInfo.coordLength;\n const {fixRingWinding} = options;\n const flatFeatures = geojsonToFlatGeojson(features, {coordLength, fixRingWinding});\n return flatGeojsonToBinary(flatFeatures, geometryInfo, {\n numericPropKeys: options.numericPropKeys,\n PositionDataType: options.PositionDataType || Float32Array\n });\n}\n"],"mappings":"AAGA,SAAQA,mBAAmB,QAAO,yBAAyB;AAC3D,SAAQC,oBAAoB,QAAO,2BAA2B;AAC9D,SAAQC,mBAAmB,QAAO,0BAA0B;;AAkB5D,OAAO,SAASC,eAAe,CAC7BC,QAAmB,EAEH;EAAA,IADhBC,OAA+B,uEAAG;IAACC,cAAc,EAAE;EAAI,CAAC;EAExD,MAAMC,YAAY,GAAGP,mBAAmB,CAACI,QAAQ,CAAC;EAClD,MAAMI,WAAW,GAAGD,YAAY,CAACC,WAAW;EAC5C,MAAM;IAACF;EAAc,CAAC,GAAGD,OAAO;EAChC,MAAMI,YAAY,GAAGR,oBAAoB,CAACG,QAAQ,EAAE;IAACI,WAAW;IAAEF;EAAc,CAAC,CAAC;EAClF,OAAOJ,mBAAmB,CAACO,YAAY,EAAEF,YAAY,EAAE;IACrDG,eAAe,EAAEL,OAAO,CAACK,eAAe;IACxCC,gBAAgB,EAAEN,OAAO,CAACM,gBAAgB,IAAIC;EAChD,CAAC,CAAC;AACJ"}
@@ -1,8 +1,9 @@
1
1
  import { getPolygonSignedArea } from '@math.gl/polygon';
2
- export function geojsonToFlatGeojson(features, options = {
3
- coordLength: 2,
4
- fixRingWinding: true
5
- }) {
2
+ export function geojsonToFlatGeojson(features) {
3
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
4
+ coordLength: 2,
5
+ fixRingWinding: true
6
+ };
6
7
  return features.map(feature => flattenFeature(feature, options));
7
8
  }
8
9
 
@@ -17,7 +18,6 @@ function flattenPoint(coordinates, data, indices, options) {
17
18
 
18
19
  function flattenLineString(coordinates, data, indices, options) {
19
20
  indices.push(data.length);
20
-
21
21
  for (const c of coordinates) {
22
22
  data.push(...c);
23
23
 
@@ -31,7 +31,6 @@ function flattenPolygon(coordinates, data, indices, areas, options) {
31
31
  let count = 0;
32
32
  const ringAreas = [];
33
33
  const polygons = [];
34
-
35
34
  for (const lineString of coordinates) {
36
35
  const lineString2d = lineString.map(p => p.slice(0, 2));
37
36
  let area = getPolygonSignedArea(lineString2d.flat());
@@ -41,12 +40,10 @@ function flattenPolygon(coordinates, data, indices, areas, options) {
41
40
  lineString.reverse();
42
41
  area = -area;
43
42
  }
44
-
45
43
  ringAreas.push(area);
46
44
  flattenLineString(lineString, data, polygons, options);
47
45
  count++;
48
46
  }
49
-
50
47
  if (count > 0) {
51
48
  areas.push(ringAreas);
52
49
  indices.push(polygons);
@@ -57,54 +54,45 @@ function flattenFeature(feature, options) {
57
54
  const {
58
55
  geometry
59
56
  } = feature;
60
-
61
57
  if (geometry.type === 'GeometryCollection') {
62
58
  throw new Error('GeometryCollection type not supported');
63
59
  }
64
-
65
60
  const data = [];
66
61
  const indices = [];
67
62
  let areas;
68
63
  let type;
69
-
70
64
  switch (geometry.type) {
71
65
  case 'Point':
72
66
  type = 'Point';
73
67
  flattenPoint(geometry.coordinates, data, indices, options);
74
68
  break;
75
-
76
69
  case 'MultiPoint':
77
70
  type = 'Point';
78
71
  geometry.coordinates.map(c => flattenPoint(c, data, indices, options));
79
72
  break;
80
-
81
73
  case 'LineString':
82
74
  type = 'LineString';
83
75
  flattenLineString(geometry.coordinates, data, indices, options);
84
76
  break;
85
-
86
77
  case 'MultiLineString':
87
78
  type = 'LineString';
88
79
  geometry.coordinates.map(c => flattenLineString(c, data, indices, options));
89
80
  break;
90
-
91
81
  case 'Polygon':
92
82
  type = 'Polygon';
93
83
  areas = [];
94
84
  flattenPolygon(geometry.coordinates, data, indices, areas, options);
95
85
  break;
96
-
97
86
  case 'MultiPolygon':
98
87
  type = 'Polygon';
99
88
  areas = [];
100
89
  geometry.coordinates.map(c => flattenPolygon(c, data, indices, areas, options));
101
90
  break;
102
-
103
91
  default:
104
92
  throw new Error("Unknown type: ".concat(type));
105
93
  }
106
-
107
- return { ...feature,
94
+ return {
95
+ ...feature,
108
96
  geometry: {
109
97
  type,
110
98
  indices,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/geojson-to-flat-geojson.ts"],"names":["getPolygonSignedArea","geojsonToFlatGeojson","features","options","coordLength","fixRingWinding","map","feature","flattenFeature","flattenPoint","coordinates","data","indices","push","length","i","flattenLineString","c","flattenPolygon","areas","count","ringAreas","polygons","lineString","lineString2d","p","slice","area","flat","ccw","reverse","geometry","type","Error"],"mappings":"AAAA,SAAQA,oBAAR,QAAmC,kBAAnC;AA0BA,OAAO,SAASC,oBAAT,CACLC,QADK,EAELC,OAAoC,GAAG;AAACC,EAAAA,WAAW,EAAE,CAAd;AAAiBC,EAAAA,cAAc,EAAE;AAAjC,CAFlC,EAGU;AACf,SAAOH,QAAQ,CAACI,GAAT,CAAcC,OAAD,IAAaC,cAAc,CAACD,OAAD,EAAUJ,OAAV,CAAxC,CAAP;AACD;;AAUD,SAASM,YAAT,CACEC,WADF,EAEEC,IAFF,EAGEC,OAHF,EAIET,OAJF,EAKE;AACAS,EAAAA,OAAO,CAACC,IAAR,CAAaF,IAAI,CAACG,MAAlB;AACAH,EAAAA,IAAI,CAACE,IAAL,CAAU,GAAGH,WAAb;;AAGA,OAAK,IAAIK,CAAC,GAAGL,WAAW,CAACI,MAAzB,EAAiCC,CAAC,GAAGZ,OAAO,CAACC,WAA7C,EAA0DW,CAAC,EAA3D,EAA+D;AAC7DJ,IAAAA,IAAI,CAACE,IAAL,CAAU,CAAV;AACD;AACF;;AAUD,SAASG,iBAAT,C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,MAAAA,IAAI,GAAG,SAAP;AACAb,MAAAA,KAAK,GAAG,EAAR;AACAD,MAAAA,cAAc,CAACa,QAAQ,CAACrB,WAAV,EAAuBC,IAAvB,EAA6BC,OAA7B,EAAsCO,KAAtC,EAA6ChB,OAA7C,CAAd;AACA;;AACF,SAAK,cAAL;AACE6B,MAAAA,IAAI,GAAG,SAAP;AACAb,MAAAA,KAAK,GAAG,EAAR;AACAY,MAAAA,QAAQ,CAACrB,WAAT,CAAqBJ,GAArB,CAA0BW,CAAD,IAAOC,cAAc,CAACD,CAAD,EAAIN,IAAJ,EAAUC,OAAV,EAAmBO,KAAnB,EAA0BhB,OAA1B,CAA9C;AACA;;AACF;AACE,YAAM,IAAI8B,KAAJ,yBAA2BD,IAA3B,EAAN;AA5BJ;;AA+BA,SAAO,EAAC,GAAGzB,OAAJ;AAAawB,IAAAA,QAAQ,EAAE;AAACC,MAAAA,IAAD;AAAOpB,MAAAA,OAAP;AAAgBD,MAAAA,IAAhB;AAAsBQ,MAAAA;AAAtB;AAAvB,GAAP;AACD","sourcesContent":["import {getPolygonSignedArea} from '@math.gl/polygon';\n\nimport {Feature, Position, FlatFeature} from '@loaders.gl/schema';\n\n/**\n * Options for `geojsonToFlatGeojson`\n */\nexport type GeojsonToFlatGeojsonOptions = {\n coordLength: number;\n fixRingWinding: boolean;\n};\n\n// Coordinates defining a Point\ntype PointCoordinates = Position;\n// Coordinates defining a LineString\ntype LineStringCoordinates = Position[];\n// Coordinates defining a Polygon\ntype PolygonCoordinates = Position[][];\n\n/**\n * Convert GeoJSON features to Flat GeoJSON features\n *\n * @param features\n * @param options\n * @returns an Array of Flat GeoJSON features\n */\nexport function geojsonToFlatGeojson(\n features: Feature[],\n options: GeojsonToFlatGeojsonOptions = {coordLength: 2, fixRingWinding: true}\n): FlatFeature[] {\n return features.map((feature) => flattenFeature(feature, options));\n}\n\n/**\n * Helper function to copy Point values from `coordinates` into `data` & `indices`\n *\n * @param coordinates\n * @param data\n * @param indices\n * @param options\n */\nfunction flattenPoint(\n coordinates: PointCoordinates,\n data: number[],\n indices: number[],\n options: GeojsonToFlatGeojsonOptions\n) {\n indices.push(data.length);\n data.push(...coordinates);\n\n // Pad up to coordLength\n for (let i = coordinates.length; i < options.coordLength; i++) {\n data.push(0);\n }\n}\n\n/**\n * Helper function to copy LineString values from `coordinates` into `data` & `indices`\n *\n * @param coordinates\n * @param data\n * @param indices\n * @param options\n */\nfunction flattenLineString(\n coordinates: LineStringCoordinates,\n data: number[],\n indices: number[],\n options: GeojsonToFlatGeojsonOptions\n) {\n indices.push(data.length);\n for (const c of coordinates) {\n data.push(...c);\n\n // Pad up to coordLength\n for (let i = c.length; i < options.coordLength; i++) {\n data.push(0);\n }\n }\n}\n\n/**\n * Helper function to copy Polygon values from `coordinates` into `data` & `indices` & `areas`\n *\n * @param coordinates\n * @param data\n * @param indices\n * @param areas\n * @param options\n */\nfunction flattenPolygon(\n coordinates: PolygonCoordinates,\n data: number[],\n indices: number[][],\n areas: number[][],\n options: GeojsonToFlatGeojsonOptions\n) {\n let count = 0;\n const ringAreas: number[] = [];\n const polygons: number[] = [];\n for (const lineString of coordinates) {\n const lineString2d = lineString.map((p) => p.slice(0, 2));\n let area = getPolygonSignedArea(lineString2d.flat());\n const ccw = area < 0;\n\n // Exterior ring must be CCW and interior rings CW\n if (options.fixRingWinding && ((count === 0 && !ccw) || (count > 0 && ccw))) {\n lineString.reverse();\n area = -area;\n }\n ringAreas.push(area);\n flattenLineString(lineString, data, polygons, options);\n count++;\n }\n\n if (count > 0) {\n areas.push(ringAreas);\n indices.push(polygons);\n }\n}\n\n/**\n * Flatten single GeoJSON feature into Flat GeoJSON\n *\n * @param feature\n * @param options\n * @returns A Flat GeoJSON feature\n */\nfunction flattenFeature(feature: Feature, options: GeojsonToFlatGeojsonOptions): FlatFeature {\n const {geometry} = feature;\n if (geometry.type === 'GeometryCollection') {\n throw new Error('GeometryCollection type not supported');\n }\n const data = [];\n const indices = [];\n let areas;\n let type;\n\n switch (geometry.type) {\n case 'Point':\n type = 'Point';\n flattenPoint(geometry.coordinates, data, indices, options);\n break;\n case 'MultiPoint':\n type = 'Point';\n geometry.coordinates.map((c) => flattenPoint(c, data, indices, options));\n break;\n case 'LineString':\n type = 'LineString';\n flattenLineString(geometry.coordinates, data, indices, options);\n break;\n case 'MultiLineString':\n type = 'LineString';\n geometry.coordinates.map((c) => flattenLineString(c, data, indices, options));\n break;\n case 'Polygon':\n type = 'Polygon';\n areas = [];\n flattenPolygon(geometry.coordinates, data, indices, areas, options);\n break;\n case 'MultiPolygon':\n type = 'Polygon';\n areas = [];\n geometry.coordinates.map((c) => flattenPolygon(c, data, indices, areas, options));\n break;\n default:\n throw new Error(`Unknown type: ${type}`);\n }\n\n return {...feature, geometry: {type, indices, data, areas}};\n}\n"],"file":"geojson-to-flat-geojson.js"}
1
+ {"version":3,"file":"geojson-to-flat-geojson.js","names":["getPolygonSignedArea","geojsonToFlatGeojson","features","options","coordLength","fixRingWinding","map","feature","flattenFeature","flattenPoint","coordinates","data","indices","push","length","i","flattenLineString","c","flattenPolygon","areas","count","ringAreas","polygons","lineString","lineString2d","p","slice","area","flat","ccw","reverse","geometry","type","Error"],"sources":["../../../src/lib/geojson-to-flat-geojson.ts"],"sourcesContent":["import {getPolygonSignedArea} from '@math.gl/polygon';\n\nimport {Feature, Position, FlatFeature} from '@loaders.gl/schema';\n\n/**\n * Options for `geojsonToFlatGeojson`\n */\nexport type GeojsonToFlatGeojsonOptions = {\n coordLength: number;\n fixRingWinding: boolean;\n};\n\n// Coordinates defining a Point\ntype PointCoordinates = Position;\n// Coordinates defining a LineString\ntype LineStringCoordinates = Position[];\n// Coordinates defining a Polygon\ntype PolygonCoordinates = Position[][];\n\n/**\n * Convert GeoJSON features to Flat GeoJSON features\n *\n * @param features\n * @param options\n * @returns an Array of Flat GeoJSON features\n */\nexport function geojsonToFlatGeojson(\n features: Feature[],\n options: GeojsonToFlatGeojsonOptions = {coordLength: 2, fixRingWinding: true}\n): FlatFeature[] {\n return features.map((feature) => flattenFeature(feature, options));\n}\n\n/**\n * Helper function to copy Point values from `coordinates` into `data` & `indices`\n *\n * @param coordinates\n * @param data\n * @param indices\n * @param options\n */\nfunction flattenPoint(\n coordinates: PointCoordinates,\n data: number[],\n indices: number[],\n options: GeojsonToFlatGeojsonOptions\n) {\n indices.push(data.length);\n data.push(...coordinates);\n\n // Pad up to coordLength\n for (let i = coordinates.length; i < options.coordLength; i++) {\n data.push(0);\n }\n}\n\n/**\n * Helper function to copy LineString values from `coordinates` into `data` & `indices`\n *\n * @param coordinates\n * @param data\n * @param indices\n * @param options\n */\nfunction flattenLineString(\n coordinates: LineStringCoordinates,\n data: number[],\n indices: number[],\n options: GeojsonToFlatGeojsonOptions\n) {\n indices.push(data.length);\n for (const c of coordinates) {\n data.push(...c);\n\n // Pad up to coordLength\n for (let i = c.length; i < options.coordLength; i++) {\n data.push(0);\n }\n }\n}\n\n/**\n * Helper function to copy Polygon values from `coordinates` into `data` & `indices` & `areas`\n *\n * @param coordinates\n * @param data\n * @param indices\n * @param areas\n * @param options\n */\nfunction flattenPolygon(\n coordinates: PolygonCoordinates,\n data: number[],\n indices: number[][],\n areas: number[][],\n options: GeojsonToFlatGeojsonOptions\n) {\n let count = 0;\n const ringAreas: number[] = [];\n const polygons: number[] = [];\n for (const lineString of coordinates) {\n const lineString2d = lineString.map((p) => p.slice(0, 2));\n let area = getPolygonSignedArea(lineString2d.flat());\n const ccw = area < 0;\n\n // Exterior ring must be CCW and interior rings CW\n if (options.fixRingWinding && ((count === 0 && !ccw) || (count > 0 && ccw))) {\n lineString.reverse();\n area = -area;\n }\n ringAreas.push(area);\n flattenLineString(lineString, data, polygons, options);\n count++;\n }\n\n if (count > 0) {\n areas.push(ringAreas);\n indices.push(polygons);\n }\n}\n\n/**\n * Flatten single GeoJSON feature into Flat GeoJSON\n *\n * @param feature\n * @param options\n * @returns A Flat GeoJSON feature\n */\nfunction flattenFeature(feature: Feature, options: GeojsonToFlatGeojsonOptions): FlatFeature {\n const {geometry} = feature;\n if (geometry.type === 'GeometryCollection') {\n throw new Error('GeometryCollection type not supported');\n }\n const data = [];\n const indices = [];\n let areas;\n let type;\n\n switch (geometry.type) {\n case 'Point':\n type = 'Point';\n flattenPoint(geometry.coordinates, data, indices, options);\n break;\n case 'MultiPoint':\n type = 'Point';\n geometry.coordinates.map((c) => flattenPoint(c, data, indices, options));\n break;\n case 'LineString':\n type = 'LineString';\n flattenLineString(geometry.coordinates, data, indices, options);\n break;\n case 'MultiLineString':\n type = 'LineString';\n geometry.coordinates.map((c) => flattenLineString(c, data, indices, options));\n break;\n case 'Polygon':\n type = 'Polygon';\n areas = [];\n flattenPolygon(geometry.coordinates, data, indices, areas, options);\n break;\n case 'MultiPolygon':\n type = 'Polygon';\n areas = [];\n geometry.coordinates.map((c) => flattenPolygon(c, data, indices, areas, options));\n break;\n default:\n throw new Error(`Unknown type: ${type}`);\n }\n\n return {...feature, geometry: {type, indices, data, areas}};\n}\n"],"mappings":"AAAA,SAAQA,oBAAoB,QAAO,kBAAkB;AA0BrD,OAAO,SAASC,oBAAoB,CAClCC,QAAmB,EAEJ;EAAA,IADfC,OAAoC,uEAAG;IAACC,WAAW,EAAE,CAAC;IAAEC,cAAc,EAAE;EAAI,CAAC;EAE7E,OAAOH,QAAQ,CAACI,GAAG,CAAEC,OAAO,IAAKC,cAAc,CAACD,OAAO,EAAEJ,OAAO,CAAC,CAAC;AACpE;;AAUA,SAASM,YAAY,CACnBC,WAA6B,EAC7BC,IAAc,EACdC,OAAiB,EACjBT,OAAoC,EACpC;EACAS,OAAO,CAACC,IAAI,CAACF,IAAI,CAACG,MAAM,CAAC;EACzBH,IAAI,CAACE,IAAI,CAAC,GAAGH,WAAW,CAAC;;EAGzB,KAAK,IAAIK,CAAC,GAAGL,WAAW,CAACI,MAAM,EAAEC,CAAC,GAAGZ,OAAO,CAACC,WAAW,EAAEW,CAAC,EAAE,EAAE;IAC7DJ,IAAI,CAACE,IAAI,CAAC,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,WAAW,EAAEC,IAAI,EAAEC,OAAO,EAAEO,KAAK,EAAEhB,OAAO,CAAC;MACnE;IACF,KAAK,cAAc;MACjB6B,IAAI,GAAG,SAAS;MAChBb,KAAK,GAAG,EAAE;MACVY,QAAQ,CAACrB,WAAW,CAACJ,GAAG,CAAEW,CAAC,IAAKC,cAAc,CAACD,CAAC,EAAEN,IAAI,EAAEC,OAAO,EAAEO,KAAK,EAAEhB,OAAO,CAAC,CAAC;MACjF;IACF;MACE,MAAM,IAAI8B,KAAK,yBAAkBD,IAAI,EAAG;EAAC;EAG7C,OAAO;IAAC,GAAGzB,OAAO;IAAEwB,QAAQ,EAAE;MAACC,IAAI;MAAEpB,OAAO;MAAED,IAAI;MAAEQ;IAAK;EAAC,CAAC;AAC7D"}
@@ -1,16 +1,14 @@
1
+
1
2
  export function transformBinaryCoords(binaryFeatures, transformCoordinate) {
2
3
  if (binaryFeatures.points) {
3
4
  transformBinaryGeometryPositions(binaryFeatures.points, transformCoordinate);
4
5
  }
5
-
6
6
  if (binaryFeatures.lines) {
7
7
  transformBinaryGeometryPositions(binaryFeatures.lines, transformCoordinate);
8
8
  }
9
-
10
9
  if (binaryFeatures.polygons) {
11
10
  transformBinaryGeometryPositions(binaryFeatures.polygons, transformCoordinate);
12
11
  }
13
-
14
12
  return binaryFeatures;
15
13
  }
16
14
 
@@ -18,7 +16,6 @@ function transformBinaryGeometryPositions(binaryGeometry, fn) {
18
16
  const {
19
17
  positions
20
18
  } = binaryGeometry;
21
-
22
19
  for (let i = 0; i < positions.value.length; i += positions.size) {
23
20
  const coord = Array.from(positions.value.subarray(i, i + positions.size));
24
21
  const transformedCoord = fn(coord);
@@ -30,20 +27,16 @@ export function transformGeoJsonCoords(features, fn) {
30
27
  for (const feature of features) {
31
28
  feature.geometry.coordinates = coordMap(feature.geometry.coordinates, fn);
32
29
  }
33
-
34
30
  return features;
35
31
  }
36
-
37
32
  function coordMap(array, fn) {
38
33
  if (isCoord(array)) {
39
34
  return fn(array);
40
35
  }
41
-
42
36
  return array.map(item => {
43
37
  return coordMap(item, fn);
44
38
  });
45
39
  }
46
-
47
40
  function isCoord(array) {
48
41
  return Number.isFinite(array[0]) && Number.isFinite(array[1]);
49
42
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/transform.ts"],"names":["transformBinaryCoords","binaryFeatures","transformCoordinate","points","transformBinaryGeometryPositions","lines","polygons","binaryGeometry","fn","positions","i","value","length","size","coord","Array","from","subarray","transformedCoord","set","transformGeoJsonCoords","features","feature","geometry","coordinates","coordMap","array","isCoord","map","item","Number","isFinite"],"mappings":"AAUA,OAAO,SAASA,qBAAT,CACLC,cADK,EAELC,mBAFK,EAGW;AAChB,MAAID,cAAc,CAACE,MAAnB,EAA2B;AACzBC,IAAAA,gCAAgC,CAACH,cAAc,CAACE,MAAhB,EAAwBD,mBAAxB,CAAhC;AACD;;AACD,MAAID,cAAc,CAACI,KAAnB,EAA0B;AACxBD,IAAAA,gCAAgC,CAACH,cAAc,CAACI,KAAhB,EAAuBH,mBAAvB,CAAhC;AACD;;AACD,MAAID,cAAc,CAACK,QAAnB,EAA6B;AAC3BF,IAAAA,gCAAgC,CAACH,cAAc,CAACK,QAAhB,EAA0BJ,mBAA1B,CAAhC;AACD;;AACD,SAAOD,cAAP;AACD;;AAGD,SAASG,gCAAT,CAA0CG,cAA1C,EAA0EC,EAA1E,EAAmG;AACjG,QAAM;AAACC,IAAAA;AAAD,MAAcF,cAApB;;AACA,OAAK,IAAIG,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGD,SAAS,CAACE,KAAV,CAAgBC,MAApC,EAA4CF,CAAC,IAAID,SAAS,CAACI,IAA3D,EAAiE;AAE/D,UAAMC,KAAoB,GAAGC,KAAK,CAACC,IAAN,CAAWP,SAAS,CAACE,KAAV,CAAgBM,QAAhB,CAAyBP,CAAzB,EAA4BA,CAAC,GAAGD,SAAS,CAACI,IAA1C,CAAX,CAA7B;AACA,UAAMK,gBAAgB,GAAGV,EAAE,CAACM,KAAD,CAA3B;AAEAL,IAAAA,SAAS,CAACE,KAAV,CAAgBQ,GAAhB,CAAoBD,gBAApB,EAAsCR,CAAtC;AACD;AACF;;AASD,OAAO,SAASU,sBAAT,CACLC,QADK,EAELb,EAFK,EAGK;AACV,OAAK,MAAMc,OAAX,IAAsBD,QAAtB,EAAgC;AAE9BC,IAAAA,OAAO,CAACC,QAAR,CAAiBC,WAAjB,GAA+BC,QAAQ,CAACH,OAAO,CAACC,QAAR,CAAiBC,WAAlB,EAA+BhB,EAA/B,CAAvC;AACD;;AACD,SAAOa,QAAP;AACD;;AAED,SAASI,QAAT,CAAkBC,KAAlB,EAAyBlB,EAAzB,EAA6B;AAC3B,MAAImB,OAAO,CAACD,KAAD,CAAX,EAAoB;AAClB,WAAOlB,EAAE,CAACkB,KAAD,CAAT;AACD;;AAED,SAAOA,KAAK,CAACE,GAAN,CAAWC,IAAD,IAAU;AACzB,WAAOJ,QAAQ,CAACI,IAAD,EAAOrB,EAAP,CAAf;AACD,GAFM,CAAP;AAGD;;AAED,SAASmB,OAAT,CAAiBD,KAAjB,EAAwB;AACtB,SAAOI,MAAM,CAACC,QAAP,CAAgBL,KAAK,CAAC,CAAD,CAArB,KAA6BI,MAAM,CAACC,QAAP,CAAgBL,KAAK,CAAC,CAAD,CAArB,CAApC;AACD","sourcesContent":["import type {BinaryFeatures, BinaryGeometry} from '@loaders.gl/schema';\n\ntype TransformCoordinate = (coord: number[]) => number[];\n\n/**\n * Apply transformation to every coordinate of binary features\n * @param binaryFeatures binary features\n * @param transformCoordinate Function to call on each coordinate\n * @return Transformed binary features\n */\nexport function transformBinaryCoords(\n binaryFeatures: BinaryFeatures,\n transformCoordinate: TransformCoordinate\n): BinaryFeatures {\n if (binaryFeatures.points) {\n transformBinaryGeometryPositions(binaryFeatures.points, transformCoordinate);\n }\n if (binaryFeatures.lines) {\n transformBinaryGeometryPositions(binaryFeatures.lines, transformCoordinate);\n }\n if (binaryFeatures.polygons) {\n transformBinaryGeometryPositions(binaryFeatures.polygons, transformCoordinate);\n }\n return binaryFeatures;\n}\n\n/** Transform one binary geometry */\nfunction transformBinaryGeometryPositions(binaryGeometry: BinaryGeometry, fn: TransformCoordinate) {\n const {positions} = binaryGeometry;\n for (let i = 0; i < positions.value.length; i += positions.size) {\n // @ts-ignore inclusion of bigint causes problems\n const coord: Array<number> = Array.from(positions.value.subarray(i, i + positions.size));\n const transformedCoord = fn(coord);\n // @ts-ignore typescript typing for .set seems to require bigint?\n positions.value.set(transformedCoord, i);\n }\n}\n\n/**\n * Apply transformation to every coordinate of GeoJSON features\n *\n * @param features Array of GeoJSON features\n * @param fn Function to call on each coordinate\n * @return Transformed GeoJSON features\n */\nexport function transformGeoJsonCoords(\n features: object[],\n fn: (coord: number[]) => number[]\n): object[] {\n for (const feature of features) {\n // @ts-ignore\n feature.geometry.coordinates = coordMap(feature.geometry.coordinates, fn);\n }\n return features;\n}\n\nfunction coordMap(array, fn) {\n if (isCoord(array)) {\n return fn(array);\n }\n\n return array.map((item) => {\n return coordMap(item, fn);\n });\n}\n\nfunction isCoord(array) {\n return Number.isFinite(array[0]) && Number.isFinite(array[1]);\n}\n"],"file":"transform.js"}
1
+ {"version":3,"file":"transform.js","names":["transformBinaryCoords","binaryFeatures","transformCoordinate","points","transformBinaryGeometryPositions","lines","polygons","binaryGeometry","fn","positions","i","value","length","size","coord","Array","from","subarray","transformedCoord","set","transformGeoJsonCoords","features","feature","geometry","coordinates","coordMap","array","isCoord","map","item","Number","isFinite"],"sources":["../../../src/lib/transform.ts"],"sourcesContent":["import type {BinaryFeatures, BinaryGeometry} from '@loaders.gl/schema';\n\ntype TransformCoordinate = (coord: number[]) => number[];\n\n/**\n * Apply transformation to every coordinate of binary features\n * @param binaryFeatures binary features\n * @param transformCoordinate Function to call on each coordinate\n * @return Transformed binary features\n */\nexport function transformBinaryCoords(\n binaryFeatures: BinaryFeatures,\n transformCoordinate: TransformCoordinate\n): BinaryFeatures {\n if (binaryFeatures.points) {\n transformBinaryGeometryPositions(binaryFeatures.points, transformCoordinate);\n }\n if (binaryFeatures.lines) {\n transformBinaryGeometryPositions(binaryFeatures.lines, transformCoordinate);\n }\n if (binaryFeatures.polygons) {\n transformBinaryGeometryPositions(binaryFeatures.polygons, transformCoordinate);\n }\n return binaryFeatures;\n}\n\n/** Transform one binary geometry */\nfunction transformBinaryGeometryPositions(binaryGeometry: BinaryGeometry, fn: TransformCoordinate) {\n const {positions} = binaryGeometry;\n for (let i = 0; i < positions.value.length; i += positions.size) {\n // @ts-ignore inclusion of bigint causes problems\n const coord: Array<number> = Array.from(positions.value.subarray(i, i + positions.size));\n const transformedCoord = fn(coord);\n // @ts-ignore typescript typing for .set seems to require bigint?\n positions.value.set(transformedCoord, i);\n }\n}\n\n/**\n * Apply transformation to every coordinate of GeoJSON features\n *\n * @param features Array of GeoJSON features\n * @param fn Function to call on each coordinate\n * @return Transformed GeoJSON features\n */\nexport function transformGeoJsonCoords(\n features: object[],\n fn: (coord: number[]) => number[]\n): object[] {\n for (const feature of features) {\n // @ts-ignore\n feature.geometry.coordinates = coordMap(feature.geometry.coordinates, fn);\n }\n return features;\n}\n\nfunction coordMap(array, fn) {\n if (isCoord(array)) {\n return fn(array);\n }\n\n return array.map((item) => {\n return coordMap(item, fn);\n });\n}\n\nfunction isCoord(array) {\n return Number.isFinite(array[0]) && Number.isFinite(array[1]);\n}\n"],"mappings":";AAUA,OAAO,SAASA,qBAAqB,CACnCC,cAA8B,EAC9BC,mBAAwC,EACxB;EAChB,IAAID,cAAc,CAACE,MAAM,EAAE;IACzBC,gCAAgC,CAACH,cAAc,CAACE,MAAM,EAAED,mBAAmB,CAAC;EAC9E;EACA,IAAID,cAAc,CAACI,KAAK,EAAE;IACxBD,gCAAgC,CAACH,cAAc,CAACI,KAAK,EAAEH,mBAAmB,CAAC;EAC7E;EACA,IAAID,cAAc,CAACK,QAAQ,EAAE;IAC3BF,gCAAgC,CAACH,cAAc,CAACK,QAAQ,EAAEJ,mBAAmB,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C;AAC/D"}
@@ -268,6 +268,7 @@ function triangulatePolygon(polygons, areas, indices, { startPosition, endPositi
268
268
  const offset = indices[0];
269
269
  const holes = indices.slice(1).map((n) => (n - offset) / coordLength);
270
270
  // Compute triangulation
271
+ // @ts-expect-error TODO can earcut handle binary arrays? Add tests?
271
272
  const triangles = (0, polygon_1.earcut)(polygonPositions, holes, coordLength, areas);
272
273
  // Indices returned by triangulation are relative to start
273
274
  // of polygon, so we need to offset
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@loaders.gl/gis",
3
3
  "description": "Helpers for GIS category data",
4
- "version": "3.3.0-alpha.5",
4
+ "version": "3.3.0-alpha.7",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -24,8 +24,8 @@
24
24
  "README.md"
25
25
  ],
26
26
  "dependencies": {
27
- "@loaders.gl/loader-utils": "3.3.0-alpha.5",
28
- "@loaders.gl/schema": "3.3.0-alpha.5",
27
+ "@loaders.gl/loader-utils": "3.3.0-alpha.7",
28
+ "@loaders.gl/schema": "3.3.0-alpha.7",
29
29
  "@mapbox/vector-tile": "^1.3.1",
30
30
  "@math.gl/polygon": "^3.5.1",
31
31
  "pbf": "^3.2.1"
@@ -33,5 +33,5 @@
33
33
  "devDependencies": {
34
34
  "@math.gl/proj4": "^3.5.1"
35
35
  },
36
- "gitHead": "d2df3bead97710c45fd2974cd51ecd7d5f7f5ea4"
36
+ "gitHead": "29b08f3519c50984e84bf4234e607cab7c7d1c3e"
37
37
  }
@@ -434,6 +434,7 @@ function triangulatePolygon(
434
434
  const holes = indices.slice(1).map((n: number) => (n - offset) / coordLength);
435
435
 
436
436
  // Compute triangulation
437
+ // @ts-expect-error TODO can earcut handle binary arrays? Add tests?
437
438
  const triangles = earcut(polygonPositions, holes, coordLength, areas);
438
439
 
439
440
  // Indices returned by triangulation are relative to start