@loaders.gl/core 5.0.0 → 5.0.2

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 (219) hide show
  1. package/dist/api.cjs +4129 -0
  2. package/dist/api.cjs.map +6 -0
  3. package/dist/api.d.ts +34 -0
  4. package/dist/api.d.ts.map +1 -0
  5. package/dist/api.js +50 -0
  6. package/dist/api.js.map +1 -0
  7. package/dist/arrow-geometry/index.cjs +5 -2
  8. package/dist/arrow-geometry/index.cjs.map +2 -2
  9. package/dist/arrow-geometry/index.d.ts +1 -0
  10. package/dist/arrow-geometry/index.d.ts.map +1 -1
  11. package/dist/arrow-geometry/index.js +1 -0
  12. package/dist/arrow-geometry/index.js.map +1 -1
  13. package/dist/arrow-geometry/triangulate-wkb-geometry-column.cjs +100 -0
  14. package/dist/arrow-geometry/triangulate-wkb-geometry-column.cjs.map +7 -0
  15. package/dist/arrow-geometry/triangulate-wkb-geometry-column.d.ts +15 -0
  16. package/dist/arrow-geometry/triangulate-wkb-geometry-column.d.ts.map +1 -0
  17. package/dist/arrow-geometry/triangulate-wkb-geometry-column.js +87 -0
  18. package/dist/arrow-geometry/triangulate-wkb-geometry-column.js.map +1 -0
  19. package/dist/dist.dev.js +458 -539
  20. package/dist/dist.min.js +3 -3
  21. package/dist/geoarrow/geoarrow-converter/geoarrow-converter.d.ts +1 -1
  22. package/dist/geoarrow/geoarrow-converter/geoarrow-converter.d.ts.map +1 -1
  23. package/dist/geoarrow/index.cjs +1 -1
  24. package/dist/geoarrow/index.cjs.map +1 -1
  25. package/dist/geoarrow/index.d.ts +2 -2
  26. package/dist/geoarrow/index.d.ts.map +1 -1
  27. package/dist/geoarrow/index.js +1 -1
  28. package/dist/geoarrow/index.js.map +1 -1
  29. package/dist/geoarrow/lib/kernels/decode-wkt-native.cjs +1 -1
  30. package/dist/geoarrow/lib/kernels/decode-wkt-native.cjs.map +1 -1
  31. package/dist/geoarrow/lib/kernels/decode-wkt-native.d.ts +1 -1
  32. package/dist/geoarrow/lib/kernels/decode-wkt-native.d.ts.map +1 -1
  33. package/dist/geoarrow/lib/kernels/decode-wkt-native.js +1 -1
  34. package/dist/geoarrow/lib/kernels/decode-wkt-native.js.map +1 -1
  35. package/dist/index.cjs +67 -4114
  36. package/dist/index.cjs.map +3 -3
  37. package/dist/index.d.ts +1 -33
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +2 -46
  40. package/dist/index.js.map +1 -1
  41. package/dist/lib/api/encode-table.d.ts +4 -4
  42. package/dist/lib/api/encode-table.d.ts.map +1 -1
  43. package/dist/lib/api/encode-table.js +21 -3
  44. package/dist/lib/api/encode-table.js.map +1 -1
  45. package/dist/lib/api/encode.d.ts +6 -6
  46. package/dist/lib/api/encode.d.ts.map +1 -1
  47. package/dist/lib/api/encode.js +46 -7
  48. package/dist/lib/api/encode.js.map +1 -1
  49. package/dist/lib/init.js +1 -1
  50. package/dist/loader-utils/index.cjs +94 -24
  51. package/dist/loader-utils/index.cjs.map +3 -3
  52. package/dist/loader-utils/index.d.ts +3 -2
  53. package/dist/loader-utils/index.d.ts.map +1 -1
  54. package/dist/loader-utils/index.js +2 -1
  55. package/dist/loader-utils/index.js.map +1 -1
  56. package/dist/loader-utils/json-loader-metadata.cjs +85 -0
  57. package/dist/loader-utils/json-loader-metadata.cjs.map +6 -0
  58. package/dist/loader-utils/json-loader-metadata.d.ts +51 -0
  59. package/dist/loader-utils/json-loader-metadata.d.ts.map +1 -0
  60. package/dist/loader-utils/json-loader-metadata.js +31 -0
  61. package/dist/loader-utils/json-loader-metadata.js.map +1 -0
  62. package/dist/loader-utils/json-loader.cjs +80 -0
  63. package/dist/loader-utils/json-loader.cjs.map +6 -0
  64. package/dist/loader-utils/json-loader.d.ts +4 -4
  65. package/dist/loader-utils/json-loader.d.ts.map +1 -1
  66. package/dist/loader-utils/json-loader.js +3 -17
  67. package/dist/loader-utils/json-loader.js.map +1 -1
  68. package/dist/loader-utils/lib/log-utils/log.js +1 -1
  69. package/dist/loader-utils/lib/request-utils/authentication.d.ts +2 -0
  70. package/dist/loader-utils/lib/request-utils/authentication.d.ts.map +1 -1
  71. package/dist/loader-utils/lib/request-utils/authentication.js +12 -0
  72. package/dist/loader-utils/lib/request-utils/authentication.js.map +1 -1
  73. package/dist/loader-utils/lib/scan-utils/table-query.d.ts +1 -1
  74. package/dist/loader-utils/lib/scan-utils/table-query.d.ts.map +1 -1
  75. package/dist/loader-utils/lib/sources/data-source.d.ts +1 -1
  76. package/dist/loader-utils/lib/sources/data-source.d.ts.map +1 -1
  77. package/dist/loader-utils/lib/sources/raster-source.d.ts +21 -1
  78. package/dist/loader-utils/lib/sources/raster-source.d.ts.map +1 -1
  79. package/dist/loader-utils/lib/sources/raster-source.js.map +1 -1
  80. package/dist/loader-utils/lib/sources/raster-tile.d.ts +7 -0
  81. package/dist/loader-utils/lib/sources/raster-tile.d.ts.map +1 -0
  82. package/dist/loader-utils/lib/sources/raster-tile.js +34 -0
  83. package/dist/loader-utils/lib/sources/raster-tile.js.map +1 -0
  84. package/dist/loader-utils/lib/sources/utils/utils.d.ts +1 -1
  85. package/dist/loader-utils/lib/sources/utils/utils.d.ts.map +1 -1
  86. package/dist/loader-utils/tile-grid.d.ts +2 -1
  87. package/dist/loader-utils/tile-grid.d.ts.map +1 -1
  88. package/dist/loader-utils/tile-grid.js +1 -1
  89. package/dist/loader-utils/tile-grid.js.map +1 -1
  90. package/dist/loader-utils/writer-types.d.ts +2 -0
  91. package/dist/loader-utils/writer-types.d.ts.map +1 -1
  92. package/dist/null-loader-metadata.cjs +89 -0
  93. package/dist/null-loader-metadata.cjs.map +6 -0
  94. package/dist/null-loader-metadata.d.ts +48 -0
  95. package/dist/null-loader-metadata.d.ts.map +1 -0
  96. package/dist/null-loader-metadata.js +30 -0
  97. package/dist/null-loader-metadata.js.map +1 -0
  98. package/dist/null-loader.cjs +84 -0
  99. package/dist/null-loader.cjs.map +6 -0
  100. package/dist/null-loader.d.ts +6 -6
  101. package/dist/null-loader.d.ts.map +1 -1
  102. package/dist/null-loader.js +2 -15
  103. package/dist/null-loader.js.map +1 -1
  104. package/dist/null-worker-node.js +58 -28
  105. package/dist/null-worker.js +58 -28
  106. package/dist/scan/arrow-execution/expressions.d.ts +1 -1
  107. package/dist/scan/arrow-execution/expressions.d.ts.map +1 -1
  108. package/dist/scan/arrow-query.cjs +2 -0
  109. package/dist/scan/arrow-query.cjs.map +2 -2
  110. package/dist/scan/arrow-query.d.ts +1 -1
  111. package/dist/scan/arrow-query.d.ts.map +1 -1
  112. package/dist/scan/arrow-query.js +1 -1
  113. package/dist/scan/arrow-query.js.map +1 -1
  114. package/dist/scan/index.cjs +16 -22
  115. package/dist/scan/index.cjs.map +2 -2
  116. package/dist/scan/index.d.ts +7 -7
  117. package/dist/scan/index.d.ts.map +1 -1
  118. package/dist/scan/index.js +4 -6
  119. package/dist/scan/index.js.map +1 -1
  120. package/dist/scan/plan-arrow-table-query.d.ts +1 -1
  121. package/dist/scan/plan-arrow-table-query.d.ts.map +1 -1
  122. package/dist/scan/query-arrow-table-in-batches.cjs +7 -19
  123. package/dist/scan/query-arrow-table-in-batches.cjs.map +2 -2
  124. package/dist/scan/query-arrow-table-in-batches.d.ts.map +1 -1
  125. package/dist/scan/query-arrow-table-in-batches.js +7 -22
  126. package/dist/scan/query-arrow-table-in-batches.js.map +1 -1
  127. package/dist/scan/query-executor.cjs +202 -0
  128. package/dist/scan/query-executor.cjs.map +7 -0
  129. package/dist/scan/query-executor.d.ts +27 -0
  130. package/dist/scan/query-executor.d.ts.map +1 -0
  131. package/dist/scan/query-executor.js +203 -0
  132. package/dist/scan/query-executor.js.map +1 -0
  133. package/dist/scan/query.cjs +92 -205
  134. package/dist/scan/query.cjs.map +3 -3
  135. package/dist/scan/query.d.ts +5 -4
  136. package/dist/scan/query.d.ts.map +1 -1
  137. package/dist/scan/query.js +94 -238
  138. package/dist/scan/query.js.map +1 -1
  139. package/dist/schema-utils/index.cjs +182 -0
  140. package/dist/schema-utils/index.cjs.map +3 -3
  141. package/dist/schema-utils/index.d.ts +3 -0
  142. package/dist/schema-utils/index.d.ts.map +1 -1
  143. package/dist/schema-utils/index.js +3 -0
  144. package/dist/schema-utils/index.js.map +1 -1
  145. package/dist/schema-utils/lib/arrow/arrow-converter.d.ts +24 -0
  146. package/dist/schema-utils/lib/arrow/arrow-converter.d.ts.map +1 -0
  147. package/dist/schema-utils/lib/arrow/arrow-converter.js +43 -0
  148. package/dist/schema-utils/lib/arrow/arrow-converter.js.map +1 -0
  149. package/dist/schema-utils/lib/arrow/convert-arrow-variable-width.d.ts +29 -0
  150. package/dist/schema-utils/lib/arrow/convert-arrow-variable-width.d.ts.map +1 -0
  151. package/dist/schema-utils/lib/arrow/convert-arrow-variable-width.js +89 -0
  152. package/dist/schema-utils/lib/arrow/convert-arrow-variable-width.js.map +1 -0
  153. package/dist/schema-utils/lib/arrow/convert-arrow.d.ts +17 -0
  154. package/dist/schema-utils/lib/arrow/convert-arrow.d.ts.map +1 -0
  155. package/dist/schema-utils/lib/arrow/convert-arrow.js +24 -0
  156. package/dist/schema-utils/lib/arrow/convert-arrow.js.map +1 -0
  157. package/dist/schema-utils/lib/arrow/tighten-arrow-table-schema-nullability.d.ts +4 -0
  158. package/dist/schema-utils/lib/arrow/tighten-arrow-table-schema-nullability.d.ts.map +1 -0
  159. package/dist/schema-utils/lib/arrow/tighten-arrow-table-schema-nullability.js +51 -0
  160. package/dist/schema-utils/lib/arrow/tighten-arrow-table-schema-nullability.js.map +1 -0
  161. package/dist/worker-utils/index.cjs +2 -2
  162. package/dist/worker-utils/lib/env-utils/version.js +1 -1
  163. package/package.json +49 -23
  164. package/src/api.ts +99 -0
  165. package/src/arrow-geometry/index.ts +5 -0
  166. package/src/arrow-geometry/triangulate-wkb-geometry-column.ts +122 -0
  167. package/src/geoarrow/index.ts +2 -2
  168. package/src/geoarrow/lib/kernels/decode-wkt-native.ts +1 -1
  169. package/src/index.ts +2 -94
  170. package/src/lib/api/encode-table.ts +31 -6
  171. package/src/lib/api/encode.ts +61 -11
  172. package/src/loader-utils/index.ts +3 -0
  173. package/src/loader-utils/json-loader-metadata.ts +35 -0
  174. package/src/loader-utils/json-loader.ts +3 -18
  175. package/src/loader-utils/lib/request-utils/authentication.ts +17 -0
  176. package/src/loader-utils/lib/sources/raster-source.ts +22 -1
  177. package/src/loader-utils/lib/sources/raster-tile.ts +46 -0
  178. package/src/loader-utils/tile-grid.ts +16 -1
  179. package/src/loader-utils/writer-types.ts +2 -0
  180. package/src/null-loader-metadata.ts +32 -0
  181. package/src/null-loader.ts +2 -17
  182. package/src/scan/arrow-query.ts +1 -1
  183. package/src/scan/index.ts +24 -13
  184. package/src/scan/query-arrow-table-in-batches.ts +7 -24
  185. package/src/scan/query-executor.ts +286 -0
  186. package/src/scan/query.ts +112 -299
  187. package/src/schema-utils/index.ts +14 -0
  188. package/src/schema-utils/lib/arrow/arrow-converter.ts +74 -0
  189. package/src/schema-utils/lib/arrow/convert-arrow-variable-width.ts +121 -0
  190. package/src/schema-utils/lib/arrow/convert-arrow.ts +52 -0
  191. package/src/schema-utils/lib/arrow/tighten-arrow-table-schema-nullability.ts +83 -0
  192. package/dist/cluster-source.cjs +0 -6360
  193. package/dist/cluster-source.cjs.map +0 -6
  194. package/dist/cluster-source.d.ts +0 -2
  195. package/dist/cluster-source.d.ts.map +0 -1
  196. package/dist/cluster-source.js +0 -2
  197. package/dist/cluster-source.js.map +0 -1
  198. package/dist/federated-table-scan-source.cjs +0 -1905
  199. package/dist/federated-table-scan-source.cjs.map +0 -6
  200. package/dist/federated-table-scan-source.d.ts +0 -2
  201. package/dist/federated-table-scan-source.d.ts.map +0 -1
  202. package/dist/federated-table-scan-source.js +0 -2
  203. package/dist/federated-table-scan-source.js.map +0 -1
  204. package/dist/geoarrow/geoarrow-builder.cjs +0 -31
  205. package/dist/geoarrow/geoarrow-builder.cjs.map +0 -7
  206. package/dist/geoarrow/geoarrow-builder.d.ts +0 -3
  207. package/dist/geoarrow/geoarrow-builder.d.ts.map +0 -1
  208. package/dist/geoarrow/geoarrow-builder.js +0 -5
  209. package/dist/geoarrow/geoarrow-builder.js.map +0 -1
  210. package/dist/vector-table-scan-source.cjs +0 -1200
  211. package/dist/vector-table-scan-source.cjs.map +0 -6
  212. package/dist/vector-table-scan-source.d.ts +0 -2
  213. package/dist/vector-table-scan-source.d.ts.map +0 -1
  214. package/dist/vector-table-scan-source.js +0 -2
  215. package/dist/vector-table-scan-source.js.map +0 -1
  216. package/src/cluster-source.ts +0 -1
  217. package/src/federated-table-scan-source.ts +0 -1
  218. package/src/geoarrow/geoarrow-builder.ts +0 -21
  219. package/src/vector-table-scan-source.ts +0 -1
@@ -0,0 +1,122 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import * as arrow from 'apache-arrow';
6
+ import {parseWKB} from '@math.gl/core/arrow';
7
+ import {triangulateWKB} from './triangulate-wkb';
8
+ import type {Geometry, MultiPolygon, Polygon, Position} from '@loaders.gl/core/schema';
9
+
10
+ /** Tessellated columns derived from a GeoArrow WKB geometry column. */
11
+ export type TriangulatedWKBGeometryColumns = {
12
+ /** Triangle vertex indices into the matching row of the `vertices` column. */
13
+ vertexIndices: arrow.Vector<arrow.List<arrow.Int32>>;
14
+ /** XY vertices from the source WKB geometry, preserving the WKB vertex order. */
15
+ vertices: arrow.Vector<arrow.List<arrow.FixedSizeList<arrow.Float64>>>;
16
+ };
17
+
18
+ /**
19
+ * Triangulates a GeoArrow WKB geometry column into triangle index and vertex columns.
20
+ * @param geometryColumn GeoArrow WKB geometry column.
21
+ * @returns Arrow columns with per-geometry triangle vertex indices and source vertices.
22
+ */
23
+ export function triangulateWKBGeometryColumn(
24
+ geometryColumn: arrow.Vector<arrow.Binary>
25
+ ): TriangulatedWKBGeometryColumns {
26
+ const vertexIndices: (number[] | null)[] = [];
27
+ const vertices: (number[][] | null)[] = [];
28
+
29
+ for (let geometryIndex = 0; geometryIndex < geometryColumn.length; geometryIndex++) {
30
+ const wkb = geometryColumn.get(geometryIndex);
31
+ if (!wkb) {
32
+ vertexIndices.push(null);
33
+ vertices.push(null);
34
+ continue;
35
+ }
36
+
37
+ vertexIndices.push(triangulateWKB(wkb));
38
+ vertices.push(getWKBGeometryVertices(wkb));
39
+ }
40
+
41
+ return {
42
+ vertexIndices: arrow.vectorFromArray(
43
+ vertexIndices,
44
+ new arrow.List(new arrow.Field('vertex_index', new arrow.Int32(), true))
45
+ ),
46
+ vertices: arrow.vectorFromArray(
47
+ vertices,
48
+ new arrow.List(
49
+ new arrow.Field(
50
+ 'vertex',
51
+ new arrow.FixedSizeList(2, new arrow.Field('coordinate', new arrow.Float64(), false)),
52
+ true
53
+ )
54
+ )
55
+ )
56
+ };
57
+ }
58
+
59
+ /**
60
+ * Extracts XY vertices from a WKB Polygon or MultiPolygon, preserving source vertex order.
61
+ * @param wkb Binary WKB input.
62
+ * @returns XY vertex pairs.
63
+ */
64
+ function getWKBGeometryVertices(wkb: ArrayBufferLike | ArrayBufferView): number[][] {
65
+ return getGeometryVertices(parseWKB(getWKBByteArray(wkb)).geometry as Geometry);
66
+ }
67
+
68
+ /**
69
+ * Converts WKB input to a byte view for math.gl's WKB parser.
70
+ * @param wkb Binary WKB input.
71
+ * @returns Byte view containing only the WKB bytes.
72
+ */
73
+ function getWKBByteArray(wkb: ArrayBufferLike | ArrayBufferView): Uint8Array {
74
+ return ArrayBuffer.isView(wkb)
75
+ ? new Uint8Array(wkb.buffer, wkb.byteOffset, wkb.byteLength)
76
+ : new Uint8Array(wkb);
77
+ }
78
+
79
+ /**
80
+ * Extracts XY vertices from a GeoJSON Polygon or MultiPolygon.
81
+ * @param geometry GeoJSON geometry.
82
+ * @returns XY vertex pairs.
83
+ */
84
+ function getGeometryVertices(geometry: Geometry): number[][] {
85
+ switch (geometry.type) {
86
+ case 'Polygon':
87
+ return getPolygonVertices(geometry);
88
+ case 'MultiPolygon':
89
+ return getMultiPolygonVertices(geometry);
90
+ default:
91
+ throw new Error(`WKB: Expected Polygon or MultiPolygon, found ${geometry.type}`);
92
+ }
93
+ }
94
+
95
+ /**
96
+ * Extracts XY vertices from a GeoJSON Polygon.
97
+ * @param polygon GeoJSON polygon.
98
+ * @returns XY vertex pairs.
99
+ */
100
+ function getPolygonVertices(polygon: Polygon): number[][] {
101
+ return polygon.coordinates.flatMap(ring => ring.map(getXYVertex));
102
+ }
103
+
104
+ /**
105
+ * Extracts XY vertices from a GeoJSON MultiPolygon.
106
+ * @param multiPolygon GeoJSON multipolygon.
107
+ * @returns XY vertex pairs.
108
+ */
109
+ function getMultiPolygonVertices(multiPolygon: MultiPolygon): number[][] {
110
+ return multiPolygon.coordinates.flatMap(polygon =>
111
+ polygon.flatMap(ring => ring.map(getXYVertex))
112
+ );
113
+ }
114
+
115
+ /**
116
+ * Converts one GeoJSON position to an XY vertex.
117
+ * @param position GeoJSON position.
118
+ * @returns XY vertex pair.
119
+ */
120
+ function getXYVertex(position: Position): number[] {
121
+ return [position[0], position[1]];
122
+ }
@@ -123,7 +123,7 @@ export type {GeoArrowRingOrientation, RewindGeoArrowOptions} from './rewind-geoa
123
123
  export type {GeoArrowResourceLimitOptions} from './geoarrow-resource-limits';
124
124
 
125
125
  // GeoArrow exposes the shared builder used by loader-facing GIS integrations.
126
- export {GeoArrowBuilder} from './geoarrow-builder';
126
+ export {GeoArrowBuilder} from '../arrow-geometry/geoarrow-builder';
127
127
  export type {
128
128
  GeoArrowBuilderEncoding,
129
129
  GeoArrowCoordinateTransform,
@@ -139,7 +139,7 @@ export type {
139
139
  GeoArrowBuilderWriteOptions,
140
140
  GeoArrowBuilderOptions,
141
141
  GeoArrowGeometryWriter
142
- } from './geoarrow-builder';
142
+ } from '../arrow-geometry/geoarrow-builder';
143
143
  export {
144
144
  getGeoArrowFieldInfo,
145
145
  validateGeoArrowField,
@@ -14,7 +14,7 @@ import {
14
14
  GeoArrowBuilder,
15
15
  type GeoArrowBuilderEncoding,
16
16
  type GeoArrowGeometryWriter
17
- } from '../../geoarrow-builder';
17
+ } from '../../../arrow-geometry/geoarrow-builder';
18
18
 
19
19
  type WKTGeometryKind =
20
20
  | 'Point'
package/src/index.ts CHANGED
@@ -2,101 +2,9 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- // TYPES
6
- export type {
7
- Loader,
8
- LoaderWithParser,
9
- LoaderContext,
10
- CoreAPI,
11
- LoaderOptions,
12
- Writer,
13
- WriterOptions,
14
- DataType,
15
- SyncDataType,
16
- BatchableDataType,
17
- ReadableFile,
18
- WritableFile,
19
- Stat,
20
- FileSystem,
21
- RandomAccessFileSystem
22
- } from '@loaders.gl/core/loader-utils';
23
- export type {SourceLoader} from '@loaders.gl/core/loader-utils';
24
-
25
- // FILE READING AND WRITING
26
- export {fetchFile} from './lib/fetch/fetch-file';
27
- export {FetchError} from './lib/fetch/fetch-error';
28
-
29
- export {readArrayBuffer} from './lib/fetch/read-array-buffer';
30
- // export {readFileSync} from './lib/fetch/read-file';
31
- // export {writeFile, writeFileSync} from './lib/fetch/write-file';
32
-
33
- // CONFIGURATION
34
- export {setLoaderOptions, getLoaderOptions, compareLoaderOptions} from './lib/api/loader-options';
35
- export {registerLoaders} from './lib/api/register-loaders';
36
- export {selectLoader, selectLoaderSync} from './lib/api/select-loader';
37
-
38
- // LOADING (READING + PARSING)
39
- export {parse} from './lib/api/parse';
40
- export {parseFile} from './lib/api/parse-file';
41
- export {parseSync} from './lib/api/parse-sync';
42
- export {parseInBatches} from './lib/api/parse-in-batches';
43
- export {preload, preloadSync} from './lib/api/preload';
44
- export {coreApi} from './lib/api/core-api';
45
-
46
- export {load} from './lib/api/load';
47
- export {loadInBatches} from './lib/api/load-in-batches';
48
-
49
- // ENCODING (ENCODING AND WRITING)
50
- export {encodeTable, encodeTableAsText, encodeTableInBatches} from './lib/api/encode-table';
51
- export {encode, encodeSync, encodeInBatches, encodeURLtoURL} from './lib/api/encode';
52
- export {encodeText, encodeTextSync} from './lib/api/encode';
53
-
54
- // SERVICES AND SOURCES
55
- export {createDataSource, createDataSourceSync} from './lib/api/create-data-source';
56
- export {selectSource as _selectSource} from './lib/api/select-source';
57
-
58
- // CORE UTILS SHARED WITH LOADERS (RE-EXPORTED FROM LOADER-UTILS)
59
- export {setPathPrefix, getPathPrefix, resolvePath} from '@loaders.gl/core/loader-utils';
60
- export {RequestScheduler} from '@loaders.gl/core/loader-utils';
61
-
62
- // ITERATOR UTILS
63
- export {makeIterator} from './iterators/make-iterator/make-iterator';
64
- export {makeStream} from './iterators/make-stream/make-stream';
5
+ // Compatibility entry point for applications using the original core imports.
6
+ export * from '@loaders.gl/core/api';
65
7
 
66
8
  // CORE LOADERS
67
9
  export {NullLoader} from './null-loader';
68
10
  export {JSONLoader} from '@loaders.gl/core/loader-utils';
69
-
70
- // EXPERIMENTAL
71
- export {fetchProgress as _fetchProgress} from './lib/progress/fetch-progress';
72
- export {BrowserFileSystem as _BrowserFileSystem} from './lib/filesystems/browser-filesystem';
73
-
74
- // FOR TESTING
75
- export {_unregisterLoaders} from './lib/api/register-loaders';
76
-
77
- //
78
- // TODO - MOVE TO LOADER-UTILS AND DEPRECATE IN CORE?
79
- //
80
-
81
- export {isBrowser, isWorker, self, window, global, document} from '@loaders.gl/core/loader-utils';
82
- export {assert} from '@loaders.gl/core/loader-utils';
83
- export {forEach, concatenateArrayBuffersAsync} from '@loaders.gl/core/loader-utils';
84
-
85
- export {
86
- makeTextDecoderIterator,
87
- makeTextEncoderIterator,
88
- makeLineIterator,
89
- makeNumberedLineIterator
90
- } from '@loaders.gl/core/loader-utils';
91
-
92
- // "JAVASCRIPT" UTILS - move to loader-utils?
93
- export {
94
- isPureObject,
95
- isPromise,
96
- isIterable,
97
- isAsyncIterable,
98
- isIterator,
99
- isResponse,
100
- isReadableStream,
101
- isWritableStream
102
- } from '@loaders.gl/core/loader-utils';
@@ -7,16 +7,21 @@
7
7
  import {
8
8
  concatenateArrayBuffers,
9
9
  ensureArrayBuffer,
10
+ Writer,
11
+ WriterOptions,
10
12
  WriterOptionsType,
11
13
  WriterWithEncoder
12
14
  } from '@loaders.gl/core/loader-utils';
13
15
  import type {Table} from '@loaders.gl/core/schema';
14
16
 
15
- export async function encodeTable<WriterT extends WriterWithEncoder = WriterWithEncoder>(
17
+ export async function encodeTable<WriterT extends Writer = Writer>(
16
18
  data: Table,
17
- writer: WriterT,
19
+ writerDefinition: WriterT,
18
20
  options?: WriterOptionsType<WriterT>
19
21
  ): Promise<ArrayBuffer> {
22
+ const writer: Writer & Partial<WriterWithEncoder> = writerDefinition.preload
23
+ ? await writerDefinition.preload()
24
+ : writerDefinition;
20
25
  if (writer.encode) {
21
26
  return await writer.encode(data, options);
22
27
  }
@@ -42,11 +47,14 @@ export async function encodeTable<WriterT extends WriterWithEncoder = WriterWith
42
47
  throw new Error('Writer could not encode data');
43
48
  }
44
49
 
45
- export async function encodeTableAsText<WriterT extends WriterWithEncoder = WriterWithEncoder>(
50
+ export async function encodeTableAsText<WriterT extends Writer = Writer>(
46
51
  data: Table,
47
- writer: WriterT,
52
+ writerDefinition: WriterT,
48
53
  options?: WriterOptionsType<WriterT>
49
54
  ): Promise<string> {
55
+ const writer: Writer & Partial<WriterWithEncoder> = writerDefinition.preload
56
+ ? await writerDefinition.preload()
57
+ : writerDefinition;
50
58
  if (writer.text && writer.encodeText) {
51
59
  return await writer.encodeText(data, options);
52
60
  }
@@ -58,10 +66,27 @@ export async function encodeTableAsText<WriterT extends WriterWithEncoder = Writ
58
66
  throw new Error(`Writer ${writer.name} could not encode data as text`);
59
67
  }
60
68
 
61
- export function encodeTableInBatches<WriterT extends WriterWithEncoder = WriterWithEncoder>(
69
+ export function encodeTableInBatches<WriterT extends Writer = Writer>(
62
70
  data: Table,
63
- writer: WriterT,
71
+ writerDefinition: WriterT,
64
72
  options?: WriterOptionsType<WriterT>
73
+ ): AsyncIterable<ArrayBuffer> {
74
+ const writer: Writer & Partial<WriterWithEncoder> = writerDefinition;
75
+ if (!writer.encodeInBatches && writer.preload) {
76
+ const preload = writer.preload.bind(writer);
77
+ return (async function* () {
78
+ const implementation = await preload();
79
+ yield* encodeWriterTableInBatches(data, implementation, options);
80
+ })();
81
+ }
82
+ return encodeWriterTableInBatches(data, writer, options);
83
+ }
84
+
85
+ /** Encodes table batches using the resolved writer's batch method. */
86
+ function encodeWriterTableInBatches(
87
+ data: Table,
88
+ writer: Writer & Partial<WriterWithEncoder>,
89
+ options?: WriterOptions
65
90
  ): AsyncIterable<ArrayBuffer> {
66
91
  if (writer.encodeInBatches) {
67
92
  const dataIterator = getIterator(data);
@@ -3,6 +3,7 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  import type {
6
+ Writer,
6
7
  WriterOptions,
7
8
  WriterWithEncoder,
8
9
  WriterOptionsType,
@@ -23,11 +24,14 @@ import {getLoaderOptions} from './loader-options';
23
24
  /**
24
25
  * Encode loaded data into a binary ArrayBuffer using the specified Writer.
25
26
  */
26
- export async function encode<WriterT extends WriterWithEncoder>(
27
+ export async function encode<WriterT extends Writer>(
27
28
  data: WriterDataType<WriterT>,
28
- writer: WriterT,
29
+ writerDefinition: WriterT,
29
30
  options_?: WriterOptionsType<WriterT>
30
31
  ): Promise<ArrayBuffer> {
32
+ const writer: Writer & Partial<WriterWithEncoder> = writerDefinition.preload
33
+ ? await writerDefinition.preload()
34
+ : writerDefinition;
31
35
  const globalOptions = getLoaderOptions() as WriterOptions;
32
36
  // const globalOptions: WriterOptions = {}; // getWriterOptions();
33
37
  const options = {...globalOptions, ...options_};
@@ -43,6 +47,9 @@ export async function encode<WriterT extends WriterWithEncoder>(
43
47
  }
44
48
 
45
49
  // TODO Merge default writer options with options argument like it is done in load module.
50
+ if (!writer.encode) {
51
+ throw new Error(`Writer ${writer.name} could not encode data`);
52
+ }
46
53
  return await writer.encode(data, options);
47
54
  }
48
55
 
@@ -69,11 +76,14 @@ export function encodeSync<WriterT extends WriterWithEncoder>(
69
76
  * It is not optimized for performance. Data maybe converted from text to binary and back.
70
77
  * @throws if the writer does not generate text output
71
78
  */
72
- export async function encodeText<WriterT extends WriterWithEncoder>(
79
+ export async function encodeText<WriterT extends Writer>(
73
80
  data: WriterDataType<WriterT>,
74
- writer: WriterT,
81
+ writerDefinition: WriterT,
75
82
  options?: WriterOptionsType<WriterT>
76
83
  ): Promise<string> {
84
+ const writer: Writer & Partial<WriterWithEncoder> = writerDefinition.preload
85
+ ? await writerDefinition.preload()
86
+ : writerDefinition;
77
87
  if (writer.encodeText) {
78
88
  return await writer.encodeText(data, options);
79
89
  }
@@ -82,7 +92,7 @@ export async function encodeText<WriterT extends WriterWithEncoder>(
82
92
  return writer.encodeTextSync(data, options);
83
93
  }
84
94
 
85
- if (writer.text) {
95
+ if (writer.text && writer.encode) {
86
96
  const arrayBuffer = await writer.encode(data, options);
87
97
  return new TextDecoder().decode(arrayBuffer);
88
98
  }
@@ -116,13 +126,30 @@ export function encodeTextSync<WriterT extends WriterWithEncoder>(
116
126
  /**
117
127
  * Encode loaded data into a sequence (iterator) of binary ArrayBuffers using the specified Writer.
118
128
  */
119
- export function encodeInBatches<WriterT extends WriterWithEncoder>(
129
+ export function encodeInBatches<WriterT extends Writer>(
120
130
  data:
121
131
  | WriterBatchType<WriterT>
122
132
  | Iterable<WriterBatchType<WriterT>>
123
133
  | AsyncIterable<WriterBatchType<WriterT>>,
124
- writer: WriterT,
134
+ writerDefinition: WriterT,
125
135
  options?: WriterOptionsType<WriterT>
136
+ ): AsyncIterable<ArrayBuffer> {
137
+ const writer: Writer & Partial<WriterWithEncoder> = writerDefinition;
138
+ if (!writer.encodeInBatches && writer.preload) {
139
+ const preload = writer.preload.bind(writer);
140
+ return (async function* () {
141
+ const implementation = await preload();
142
+ yield* encodeWriterInBatches(data, implementation, options);
143
+ })();
144
+ }
145
+ return encodeWriterInBatches(data, writer, options);
146
+ }
147
+
148
+ /** Encodes binary batches using the resolved writer's batch method. */
149
+ function encodeWriterInBatches(
150
+ data: unknown,
151
+ writer: Writer & Partial<WriterWithEncoder>,
152
+ options?: WriterOptions
126
153
  ): AsyncIterable<ArrayBuffer> {
127
154
  if (writer.encodeInBatches) {
128
155
  let dataIterator: unknown;
@@ -146,7 +173,24 @@ export function encodeInBatches<WriterT extends WriterWithEncoder>(
146
173
  */
147
174
  export function encodeTextInBatches(
148
175
  data: unknown,
149
- writer: WriterWithEncoder,
176
+ writerDefinition: Writer,
177
+ options?: WriterOptions
178
+ ): AsyncIterable<ArrayBuffer> {
179
+ const writer: Writer & Partial<WriterWithEncoder> = writerDefinition;
180
+ if (!writer.encodeTextInBatches && writer.preload) {
181
+ const preload = writer.preload.bind(writer);
182
+ return (async function* () {
183
+ const implementation = await preload();
184
+ yield* encodeWriterTextInBatches(data, implementation, options);
185
+ })();
186
+ }
187
+ return encodeWriterTextInBatches(data, writer, options);
188
+ }
189
+
190
+ /** Encodes text batches using the resolved writer's batch method. */
191
+ function encodeWriterTextInBatches(
192
+ data: unknown,
193
+ writer: Writer & Partial<WriterWithEncoder>,
150
194
  options?: WriterOptions
151
195
  ): AsyncIterable<ArrayBuffer> {
152
196
  if (writer.encodeTextInBatches) {
@@ -165,12 +209,18 @@ export function encodeTextInBatches(
165
209
  export async function encodeURLtoURL(
166
210
  inputUrl: string,
167
211
  outputUrl: string,
168
- writer: Omit<WriterWithEncoder, 'encode'>,
212
+ writerDefinition: Omit<WriterWithEncoder, 'encode'>,
169
213
  options?: WriterOptions
170
214
  ): Promise<string> {
171
215
  inputUrl = resolvePath(inputUrl);
172
216
  outputUrl = resolvePath(outputUrl);
173
- if (isBrowser || !writer.encodeURLtoURL) {
217
+ if (isBrowser) {
218
+ throw new Error();
219
+ }
220
+ const writer = writerDefinition.encodeURLtoURL
221
+ ? writerDefinition
222
+ : ((await writerDefinition.preload?.()) ?? writerDefinition);
223
+ if (!writer.encodeURLtoURL) {
174
224
  throw new Error();
175
225
  }
176
226
  const outputFilename = await writer.encodeURLtoURL(inputUrl, outputUrl, options);
@@ -179,7 +229,7 @@ export async function encodeURLtoURL(
179
229
 
180
230
  /** Helper function to encode via external tool (typically command line execution in Node.js) */
181
231
  async function encodeWithCommandLineTool(
182
- writer: WriterWithEncoder,
232
+ writer: Omit<WriterWithEncoder, 'encode'>,
183
233
  data: unknown,
184
234
  options: WriterOptions
185
235
  ): Promise<ArrayBuffer> {
@@ -161,6 +161,7 @@ export {
161
161
  // REQUEST UTILS
162
162
  export {default as RequestScheduler} from './lib/request-utils/request-scheduler';
163
163
  export {
164
+ createSourceLoadOptionsResolver,
164
165
  resolveCredentials,
165
166
  resolveAuthenticationOptions,
166
167
  resolveLoaderAuthenticationOptions
@@ -471,6 +472,7 @@ export type {TileSourceMetadata, GetTileParameters} from './lib/sources/tile-sou
471
472
  export type {GetTileDataBatchResult, GetTileDataParameters} from './lib/sources/tile-source';
472
473
  export {getTileDataBatch} from './lib/sources/tile-source-utils';
473
474
  export {TileSourceAdapter} from './lib/sources/tile-source-adapter';
475
+ export {readRasterTile} from './lib/sources/raster-tile';
474
476
 
475
477
  export type {ImageTileSource} from './lib/sources/image-tile-source';
476
478
 
@@ -486,6 +488,7 @@ export type {
486
488
  RasterData,
487
489
  RasterSelection,
488
490
  GetRasterParameters,
491
+ GetRasterTileParameters,
489
492
  RasterOverview,
490
493
  RasterSourceMetadata
491
494
  } from './lib/sources/raster-source';
@@ -0,0 +1,35 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {Table, TableBatch} from '@loaders.gl/core/schema';
6
+
7
+ // __VERSION__ is injected by babel-plugin-version-inline
8
+ // @ts-ignore TS2304: Cannot find name '__VERSION__'.
9
+ const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
10
+
11
+ /** Shared metadata for JSONLoader. */
12
+ export const JSONLoaderMetadata = {
13
+ dataType: null as unknown as Table,
14
+ batchType: null as unknown as TableBatch,
15
+ name: 'JSON',
16
+ id: 'json',
17
+ module: 'json',
18
+ version: VERSION,
19
+ encoding: 'json',
20
+ format: 'json',
21
+ extensions: ['json', 'geojson'] as string[],
22
+ mimeTypes: ['application/json'] as string[],
23
+ category: 'json',
24
+ text: true,
25
+ options: {}
26
+ } as const;
27
+
28
+ /** Defers the JSONLoader parser until first use. */
29
+ export const JSONLoader = {
30
+ ...JSONLoaderMetadata,
31
+ async preload() {
32
+ const implementation = await import('./json-loader.js');
33
+ return implementation.JSONLoader;
34
+ }
35
+ } as const;
@@ -2,13 +2,10 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
+ import {JSONLoaderMetadata} from './json-loader-metadata';
5
6
  import type {LoaderWithParser, LoaderOptions} from './loader-types';
6
7
  import type {Table, TableBatch} from '@loaders.gl/core/schema';
7
8
 
8
- // __VERSION__ is injected by babel-plugin-version-inline
9
- // @ts-ignore TS2304: Cannot find name '__VERSION__'.
10
- const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
11
-
12
9
  export type JSONLoaderOptions = LoaderOptions;
13
10
 
14
11
  /**
@@ -16,21 +13,9 @@ export type JSONLoaderOptions = LoaderOptions;
16
13
  * Alternative to `@loaders.gl/tables/json`
17
14
  */
18
15
  export const JSONLoader = {
19
- dataType: null as unknown as Table,
20
- batchType: null as unknown as TableBatch,
21
- name: 'JSON',
22
- id: 'json',
23
- module: 'json',
24
- version: VERSION,
25
- encoding: 'json',
26
- format: 'json',
27
- extensions: ['json', 'geojson'],
28
- mimeTypes: ['application/json'],
29
- category: 'json',
30
- text: true,
16
+ ...JSONLoaderMetadata,
31
17
  parseTextSync,
32
- parse: async arrayBuffer => parseTextSync(new TextDecoder().decode(arrayBuffer)),
33
- options: {}
18
+ parse: async arrayBuffer => parseTextSync(new TextDecoder().decode(arrayBuffer))
34
19
  } as const satisfies LoaderWithParser<Table, TableBatch, JSONLoaderOptions>;
35
20
 
36
21
  // TODO - Better error handling!
@@ -120,6 +120,23 @@ export async function resolveLoaderAuthenticationOptions<OptionsT extends Loader
120
120
  });
121
121
  }
122
122
 
123
+ /** Creates a per-source accessor that shares credential discovery across concurrent resource loads. */
124
+ export function createSourceLoadOptionsResolver<OptionsT extends LoaderOptions>(
125
+ loader: Loader,
126
+ url: string,
127
+ options: OptionsT
128
+ ): () => Promise<OptionsT> {
129
+ let resolvedOptions: Promise<OptionsT> | undefined;
130
+ return () => {
131
+ resolvedOptions ||= resolveLoaderAuthenticationOptions(loader, url, options).catch(error => {
132
+ // A later request can retry a failed discovery.
133
+ resolvedOptions = undefined;
134
+ throw error;
135
+ });
136
+ return resolvedOptions;
137
+ };
138
+ }
139
+
123
140
  /** Tests the public runtime credential shape without relying on class identity. */
124
141
  function isAuthentication(credential: Credential): credential is Authentication {
125
142
  if (!credential || typeof credential !== 'object') return false;
@@ -126,6 +126,16 @@ export type GetRasterParameters = {
126
126
  signal?: AbortSignal;
127
127
  };
128
128
 
129
+ /** Experimental request for one tile of the source's native raster grid. */
130
+ export type GetRasterTileParameters = Omit<GetRasterParameters, 'viewport' | 'resampleMethod'> & {
131
+ /** Identifier of a matrix in the source's tile grid. */
132
+ tileMatrix: string;
133
+ /** Native tile column. */
134
+ x: number;
135
+ /** Native tile row. */
136
+ y: number;
137
+ };
138
+
129
139
  /**
130
140
  * Description of one available overview level.
131
141
  */
@@ -176,8 +186,13 @@ export type RasterSourceMetadata = {
176
186
  supportsRegion?: boolean;
177
187
  /** Native tile dimensions when the source is tiled. */
178
188
  tileSize?: {width: number; height: number};
179
- /** Native tiled overview geometry; matrix IDs are source image indices. Edge tiles may extend beyond raster bounds. */
189
+ /** Native tiled overview geometry with source-assigned matrix IDs. Edge tiles may extend beyond raster bounds. */
180
190
  tileGrid?: TileGrid;
191
+ /**
192
+ * IDs in `tileGrid` that the source can read with the default bands (experimental).
193
+ * The source checks whether the requested matrix supports an explicit band selection.
194
+ */
195
+ nativeTileMatrixIds?: string[];
181
196
  /** Available overview levels. */
182
197
  overviews?: RasterOverview[];
183
198
  /** Source no-data value when defined. */
@@ -206,6 +221,8 @@ export interface RasterSource<
206
221
  }): Promise<MetadataT>;
207
222
  /** Loads raster samples for the supplied viewport request. */
208
223
  getRaster(parameters: ParametersT): Promise<DataT>;
224
+ /** Experimental. Reads one native tile without resampling, or null for an unavailable tile. */
225
+ getRasterTile?(parameters: GetRasterTileParameters): Promise<NumericRasterData | null>;
209
226
  }
210
227
 
211
228
  /**
@@ -236,6 +253,10 @@ export type RasterBandMetadata = {
236
253
  index: number;
237
254
  /** Actual array representation for this band. */
238
255
  dtype: RasterChannelDataType;
256
+ /** GDAL-style display role. `'undefined'` denotes an explicitly unspecified role. */
257
+ colorInterpretation?: 'gray' | 'red' | 'green' | 'blue' | 'alpha' | 'palette' | 'undefined';
258
+ /** Alpha band only. `'premultiplied'` is associated alpha (TIFF ExtraSamples 1). Omission means straight alpha. */
259
+ alphaMode?: 'straight' | 'premultiplied';
239
260
  /** Human-readable band name. */
240
261
  name?: string;
241
262
  /** Physical units. */