@loaders.gl/flatgeobuf 4.1.0-alpha.6 → 4.1.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 (176) hide show
  1. package/dist/LICENSE +9 -0
  2. package/dist/flatgeobuf/3.27.2/LICENSE +29 -0
  3. package/dist/flatgeobuf/3.27.2/README.md +45 -0
  4. package/dist/flatgeobuf/3.27.2/column-meta.d.ts +14 -0
  5. package/dist/flatgeobuf/3.27.2/column-meta.d.ts.map +1 -0
  6. package/dist/flatgeobuf/3.27.2/column-meta.js +2 -0
  7. package/dist/flatgeobuf/3.27.2/column-meta.js.map +1 -0
  8. package/dist/flatgeobuf/3.27.2/config.d.ts +10 -0
  9. package/dist/flatgeobuf/3.27.2/config.d.ts.map +1 -0
  10. package/dist/flatgeobuf/3.27.2/config.js +16 -0
  11. package/dist/flatgeobuf/3.27.2/config.js.map +1 -0
  12. package/dist/flatgeobuf/3.27.2/constants.d.ts +3 -0
  13. package/dist/flatgeobuf/3.27.2/constants.d.ts.map +1 -0
  14. package/dist/flatgeobuf/3.27.2/constants.js +3 -0
  15. package/dist/flatgeobuf/3.27.2/constants.js.map +1 -0
  16. package/dist/flatgeobuf/3.27.2/crs-meta.d.ts +9 -0
  17. package/dist/flatgeobuf/3.27.2/crs-meta.d.ts.map +1 -0
  18. package/dist/flatgeobuf/3.27.2/crs-meta.js +2 -0
  19. package/dist/flatgeobuf/3.27.2/crs-meta.js.map +1 -0
  20. package/dist/flatgeobuf/3.27.2/dumptree.d.ts +2 -0
  21. package/dist/flatgeobuf/3.27.2/dumptree.d.ts.map +1 -0
  22. package/dist/flatgeobuf/3.27.2/dumptree.js +61 -0
  23. package/dist/flatgeobuf/3.27.2/dumptree.js.map +1 -0
  24. package/dist/flatgeobuf/3.27.2/feature.d.ts +2 -0
  25. package/dist/flatgeobuf/3.27.2/feature.d.ts.map +1 -0
  26. package/dist/flatgeobuf/3.27.2/feature.js +3 -0
  27. package/dist/flatgeobuf/3.27.2/feature.js.map +1 -0
  28. package/dist/flatgeobuf/3.27.2/flat-geobuf/column-type.d.ts +18 -0
  29. package/dist/flatgeobuf/3.27.2/flat-geobuf/column-type.d.ts.map +1 -0
  30. package/dist/flatgeobuf/3.27.2/flat-geobuf/column-type.js +19 -0
  31. package/dist/flatgeobuf/3.27.2/flat-geobuf/column-type.js.map +1 -0
  32. package/dist/flatgeobuf/3.27.2/flat-geobuf/column.d.ts +39 -0
  33. package/dist/flatgeobuf/3.27.2/flat-geobuf/column.d.ts.map +1 -0
  34. package/dist/flatgeobuf/3.27.2/flat-geobuf/column.js +121 -0
  35. package/dist/flatgeobuf/3.27.2/flat-geobuf/column.js.map +1 -0
  36. package/dist/flatgeobuf/3.27.2/flat-geobuf/crs.d.ts +29 -0
  37. package/dist/flatgeobuf/3.27.2/flat-geobuf/crs.d.ts.map +1 -0
  38. package/dist/flatgeobuf/3.27.2/flat-geobuf/crs.js +79 -0
  39. package/dist/flatgeobuf/3.27.2/flat-geobuf/crs.js.map +1 -0
  40. package/dist/flatgeobuf/3.27.2/flat-geobuf/feature.d.ts +29 -0
  41. package/dist/flatgeobuf/3.27.2/flat-geobuf/feature.d.ts.map +1 -0
  42. package/dist/flatgeobuf/3.27.2/flat-geobuf/feature.js +95 -0
  43. package/dist/flatgeobuf/3.27.2/flat-geobuf/feature.js.map +1 -0
  44. package/dist/flatgeobuf/3.27.2/flat-geobuf/geometry-type.d.ts +21 -0
  45. package/dist/flatgeobuf/3.27.2/flat-geobuf/geometry-type.d.ts.map +1 -0
  46. package/dist/flatgeobuf/3.27.2/flat-geobuf/geometry-type.js +22 -0
  47. package/dist/flatgeobuf/3.27.2/flat-geobuf/geometry-type.js.map +1 -0
  48. package/dist/flatgeobuf/3.27.2/flat-geobuf/geometry.d.ts +75 -0
  49. package/dist/flatgeobuf/3.27.2/flat-geobuf/geometry.d.ts.map +1 -0
  50. package/dist/flatgeobuf/3.27.2/flat-geobuf/geometry.js +214 -0
  51. package/dist/flatgeobuf/3.27.2/flat-geobuf/geometry.js.map +1 -0
  52. package/dist/flatgeobuf/3.27.2/flat-geobuf/header.d.ts +59 -0
  53. package/dist/flatgeobuf/3.27.2/flat-geobuf/header.d.ts.map +1 -0
  54. package/dist/flatgeobuf/3.27.2/flat-geobuf/header.js +166 -0
  55. package/dist/flatgeobuf/3.27.2/flat-geobuf/header.js.map +1 -0
  56. package/dist/flatgeobuf/3.27.2/flat-geobuf.d.ts +6 -0
  57. package/dist/flatgeobuf/3.27.2/flat-geobuf.d.ts.map +1 -0
  58. package/dist/flatgeobuf/3.27.2/flat-geobuf.js +6 -0
  59. package/dist/flatgeobuf/3.27.2/flat-geobuf.js.map +1 -0
  60. package/dist/flatgeobuf/3.27.2/generic/feature.d.ts +19 -0
  61. package/dist/flatgeobuf/3.27.2/generic/feature.d.ts.map +1 -0
  62. package/dist/flatgeobuf/3.27.2/generic/feature.js +220 -0
  63. package/dist/flatgeobuf/3.27.2/generic/feature.js.map +1 -0
  64. package/dist/flatgeobuf/3.27.2/generic/featurecollection.d.ts +18 -0
  65. package/dist/flatgeobuf/3.27.2/generic/featurecollection.d.ts.map +1 -0
  66. package/dist/flatgeobuf/3.27.2/generic/featurecollection.js +162 -0
  67. package/dist/flatgeobuf/3.27.2/generic/featurecollection.js.map +1 -0
  68. package/dist/flatgeobuf/3.27.2/generic/geometry.d.ts +33 -0
  69. package/dist/flatgeobuf/3.27.2/generic/geometry.d.ts.map +1 -0
  70. package/dist/flatgeobuf/3.27.2/generic/geometry.js +81 -0
  71. package/dist/flatgeobuf/3.27.2/generic/geometry.js.map +1 -0
  72. package/dist/flatgeobuf/3.27.2/generic/header.d.ts +5 -0
  73. package/dist/flatgeobuf/3.27.2/generic/header.d.ts.map +1 -0
  74. package/dist/flatgeobuf/3.27.2/generic/header.js +27 -0
  75. package/dist/flatgeobuf/3.27.2/generic/header.js.map +1 -0
  76. package/dist/flatgeobuf/3.27.2/generic.d.ts +16 -0
  77. package/dist/flatgeobuf/3.27.2/generic.d.ts.map +1 -0
  78. package/dist/flatgeobuf/3.27.2/generic.js +9 -0
  79. package/dist/flatgeobuf/3.27.2/generic.js.map +1 -0
  80. package/dist/flatgeobuf/3.27.2/geojson/feature.d.ts +8 -0
  81. package/dist/flatgeobuf/3.27.2/geojson/feature.d.ts.map +1 -0
  82. package/dist/flatgeobuf/3.27.2/geojson/feature.js +13 -0
  83. package/dist/flatgeobuf/3.27.2/geojson/feature.js.map +1 -0
  84. package/dist/flatgeobuf/3.27.2/geojson/featurecollection.d.ts +8 -0
  85. package/dist/flatgeobuf/3.27.2/geojson/featurecollection.d.ts.map +1 -0
  86. package/dist/flatgeobuf/3.27.2/geojson/featurecollection.js +54 -0
  87. package/dist/flatgeobuf/3.27.2/geojson/featurecollection.js.map +1 -0
  88. package/dist/flatgeobuf/3.27.2/geojson/geometry.d.ts +13 -0
  89. package/dist/flatgeobuf/3.27.2/geojson/geometry.d.ts.map +1 -0
  90. package/dist/flatgeobuf/3.27.2/geojson/geometry.js +118 -0
  91. package/dist/flatgeobuf/3.27.2/geojson/geometry.js.map +1 -0
  92. package/dist/flatgeobuf/3.27.2/geojson.d.ts +17 -0
  93. package/dist/flatgeobuf/3.27.2/geojson.d.ts.map +1 -0
  94. package/dist/flatgeobuf/3.27.2/geojson.js +10 -0
  95. package/dist/flatgeobuf/3.27.2/geojson.js.map +1 -0
  96. package/dist/flatgeobuf/3.27.2/header-meta.d.ts +17 -0
  97. package/dist/flatgeobuf/3.27.2/header-meta.d.ts.map +1 -0
  98. package/dist/flatgeobuf/3.27.2/header-meta.js +46 -0
  99. package/dist/flatgeobuf/3.27.2/header-meta.js.map +1 -0
  100. package/dist/flatgeobuf/3.27.2/header.d.ts +2 -0
  101. package/dist/flatgeobuf/3.27.2/header.d.ts.map +1 -0
  102. package/dist/flatgeobuf/3.27.2/header.js +3 -0
  103. package/dist/flatgeobuf/3.27.2/header.js.map +1 -0
  104. package/dist/flatgeobuf/3.27.2/http-reader.d.ts +41 -0
  105. package/dist/flatgeobuf/3.27.2/http-reader.d.ts.map +1 -0
  106. package/dist/flatgeobuf/3.27.2/http-reader.js +193 -0
  107. package/dist/flatgeobuf/3.27.2/http-reader.js.map +1 -0
  108. package/dist/flatgeobuf/3.27.2/index.d.ts +14 -0
  109. package/dist/flatgeobuf/3.27.2/index.d.ts.map +1 -0
  110. package/dist/flatgeobuf/3.27.2/index.js +16 -0
  111. package/dist/flatgeobuf/3.27.2/index.js.map +1 -0
  112. package/dist/flatgeobuf/3.27.2/logger.d.ts +15 -0
  113. package/dist/flatgeobuf/3.27.2/logger.d.ts.map +1 -0
  114. package/dist/flatgeobuf/3.27.2/logger.js +65 -0
  115. package/dist/flatgeobuf/3.27.2/logger.js.map +1 -0
  116. package/dist/flatgeobuf/3.27.2/packedrtree.d.ts +43 -0
  117. package/dist/flatgeobuf/3.27.2/packedrtree.d.ts.map +1 -0
  118. package/dist/flatgeobuf/3.27.2/packedrtree.js +138 -0
  119. package/dist/flatgeobuf/3.27.2/packedrtree.js.map +1 -0
  120. package/dist/flatgeobuf/3.27.2/streams/utils.d.ts +7 -0
  121. package/dist/flatgeobuf/3.27.2/streams/utils.d.ts.map +1 -0
  122. package/dist/flatgeobuf/3.27.2/streams/utils.js +67 -0
  123. package/dist/flatgeobuf/3.27.2/streams/utils.js.map +1 -0
  124. package/dist/flatgeobuf/3.27.2/types/jsts.d.ts +23 -0
  125. package/dist/flatgeobuf/3.27.2/types/slice.d.ts +16 -0
  126. package/dist/flatgeobuf-loader.js +1 -1
  127. package/dist/index.cjs +1547 -6
  128. package/dist/lib/binary-geometries.d.ts +1 -1
  129. package/dist/lib/binary-geometries.d.ts.map +1 -1
  130. package/dist/lib/binary-geometries.js.map +1 -1
  131. package/dist/lib/get-schema-from-fgb-header.d.ts +1 -1
  132. package/dist/lib/get-schema-from-fgb-header.d.ts.map +1 -1
  133. package/dist/lib/get-schema-from-fgb-header.js.map +1 -1
  134. package/dist/lib/parse-flatgeobuf.d.ts +1 -1
  135. package/dist/lib/parse-flatgeobuf.d.ts.map +1 -1
  136. package/dist/lib/parse-flatgeobuf.js +3 -3
  137. package/dist/lib/parse-flatgeobuf.js.map +1 -1
  138. package/package.json +8 -5
  139. package/src/LICENSE +9 -0
  140. package/src/flatgeobuf/3.27.2/LICENSE +29 -0
  141. package/src/flatgeobuf/3.27.2/README.md +45 -0
  142. package/src/flatgeobuf/3.27.2/column-meta.ts +14 -0
  143. package/src/flatgeobuf/3.27.2/config.ts +19 -0
  144. package/src/flatgeobuf/3.27.2/constants.ts +4 -0
  145. package/src/flatgeobuf/3.27.2/crs-meta.ts +8 -0
  146. package/src/flatgeobuf/3.27.2/dumptree.ts +82 -0
  147. package/src/flatgeobuf/3.27.2/feature.ts +3 -0
  148. package/src/flatgeobuf/3.27.2/flat-geobuf/column-type.ts +19 -0
  149. package/src/flatgeobuf/3.27.2/flat-geobuf/column.ts +170 -0
  150. package/src/flatgeobuf/3.27.2/flat-geobuf/crs.ts +114 -0
  151. package/src/flatgeobuf/3.27.2/flat-geobuf/feature.ts +140 -0
  152. package/src/flatgeobuf/3.27.2/flat-geobuf/geometry-type.ts +22 -0
  153. package/src/flatgeobuf/3.27.2/flat-geobuf/geometry.ts +382 -0
  154. package/src/flatgeobuf/3.27.2/flat-geobuf/header.ts +246 -0
  155. package/src/flatgeobuf/3.27.2/flat-geobuf.ts +7 -0
  156. package/src/flatgeobuf/3.27.2/generic/feature.ts +243 -0
  157. package/src/flatgeobuf/3.27.2/generic/featurecollection.ts +227 -0
  158. package/src/flatgeobuf/3.27.2/generic/geometry.ts +120 -0
  159. package/src/flatgeobuf/3.27.2/generic/header.ts +32 -0
  160. package/src/flatgeobuf/3.27.2/generic.ts +33 -0
  161. package/src/flatgeobuf/3.27.2/geojson/feature.ts +20 -0
  162. package/src/flatgeobuf/3.27.2/geojson/featurecollection.ts +101 -0
  163. package/src/flatgeobuf/3.27.2/geojson/geometry.ts +142 -0
  164. package/src/flatgeobuf/3.27.2/geojson.ts +37 -0
  165. package/src/flatgeobuf/3.27.2/header-meta.ts +66 -0
  166. package/src/flatgeobuf/3.27.2/header.ts +3 -0
  167. package/src/flatgeobuf/3.27.2/http-reader.ts +351 -0
  168. package/src/flatgeobuf/3.27.2/index.ts +19 -0
  169. package/src/flatgeobuf/3.27.2/logger.ts +51 -0
  170. package/src/flatgeobuf/3.27.2/packedrtree.ts +255 -0
  171. package/src/flatgeobuf/3.27.2/streams/utils.ts +80 -0
  172. package/src/flatgeobuf/3.27.2/types/jsts.d.ts +23 -0
  173. package/src/flatgeobuf/3.27.2/types/slice.d.ts +16 -0
  174. package/src/lib/binary-geometries.ts +2 -2
  175. package/src/lib/get-schema-from-fgb-header.ts +1 -1
  176. package/src/lib/parse-flatgeobuf.ts +4 -4
@@ -0,0 +1,19 @@
1
+ export * as generic from './generic.js';
2
+ export * as geojson from './geojson.js';
3
+ // export * as ol from './ol.js';
4
+
5
+ export {Column} from './flat-geobuf/column.js';
6
+ export {Geometry} from './flat-geobuf/geometry.js';
7
+ export {Feature} from './flat-geobuf/feature.js';
8
+
9
+ export {ISimpleGeometry} from './generic/geometry.js';
10
+ export {IFeature} from './generic/feature.js';
11
+ export {FromFeatureFn} from './generic/featurecollection.js';
12
+
13
+ export {IGeoJsonFeature} from './geojson/feature.js';
14
+
15
+ export {default as HeaderMeta} from './header-meta.js';
16
+ export {default as ColumnMeta} from './column-meta.js';
17
+ export {default as CrsMeta} from './crs-meta.js';
18
+
19
+ export {Rect} from './packedrtree.js';
@@ -0,0 +1,51 @@
1
+ export enum LogLevel {
2
+ Debug,
3
+ Info,
4
+ Warn,
5
+ Error
6
+ }
7
+
8
+ export default class Logger {
9
+ static logLevel: LogLevel = LogLevel.Warn;
10
+
11
+ static debug(...args: any[]): void {
12
+ this.log(LogLevel.Debug, ...args);
13
+ }
14
+
15
+ static info(...args: any[]): void {
16
+ this.log(LogLevel.Info, ...args);
17
+ }
18
+
19
+ static warn(...args: any[]): void {
20
+ this.log(LogLevel.Warn, ...args);
21
+ }
22
+
23
+ static error(...args: any[]): void {
24
+ this.log(LogLevel.Error, ...args);
25
+ }
26
+
27
+ static log(level: LogLevel, ...args: any[]): void {
28
+ if (this.logLevel > level) {
29
+ return;
30
+ }
31
+
32
+ switch (level) {
33
+ case LogLevel.Debug: {
34
+ console.debug(...args);
35
+ break;
36
+ }
37
+ case LogLevel.Info: {
38
+ console.info(...args);
39
+ break;
40
+ }
41
+ case LogLevel.Warn: {
42
+ console.warn(...args);
43
+ break;
44
+ }
45
+ case LogLevel.Error: {
46
+ console.error(...args);
47
+ break;
48
+ }
49
+ }
50
+ }
51
+ }
@@ -0,0 +1,255 @@
1
+ import Config from './config.js';
2
+ import Logger from './logger.js';
3
+
4
+ export const NODE_ITEM_BYTE_LEN: number = 8 * 4 + 8;
5
+ /**
6
+ * @deprecated Use `NODE_ITEM_BYTE_LEN` instead.
7
+ */
8
+ export const NODE_ITEM_LEN = NODE_ITEM_BYTE_LEN;
9
+
10
+ // default branching factor of a node in the rtree
11
+ //
12
+ // actual value will be specified in the header but
13
+ // this can be useful for having reasonably sized guesses for fetch-sizes when
14
+ // streaming results
15
+ export const DEFAULT_NODE_SIZE = 16;
16
+
17
+ export interface Rect {
18
+ minX: number;
19
+ minY: number;
20
+ maxX: number;
21
+ maxY: number;
22
+ }
23
+
24
+ export function calcTreeSize(numItems: number, nodeSize: number): number {
25
+ nodeSize = Math.min(Math.max(Number(nodeSize), 2), 65535);
26
+ let n = numItems;
27
+ let numNodes = n;
28
+ do {
29
+ n = Math.ceil(n / nodeSize);
30
+ numNodes += n;
31
+ } while (n !== 1);
32
+ return numNodes * NODE_ITEM_BYTE_LEN;
33
+ }
34
+
35
+ /**
36
+ * returns [levelOffset, numNodes] for each level
37
+ */
38
+ export function generateLevelBounds(numItems: number, nodeSize: number): Array<[number, number]> {
39
+ if (nodeSize < 2) throw new Error('Node size must be at least 2');
40
+ if (numItems === 0) throw new Error('Number of items must be greater than 0');
41
+
42
+ // number of nodes per level in bottom-up order
43
+ let n = numItems;
44
+ let numNodes = n;
45
+ const levelNumNodes = [n];
46
+ do {
47
+ n = Math.ceil(n / nodeSize);
48
+ numNodes += n;
49
+ levelNumNodes.push(n);
50
+ } while (n !== 1);
51
+
52
+ // bounds per level in reversed storage order (top-down)
53
+ const levelOffsets: Array<number> = [];
54
+ n = numNodes;
55
+ for (const size of levelNumNodes) {
56
+ levelOffsets.push(n - size);
57
+ n -= size;
58
+ }
59
+ const levelBounds: Array<[number, number]> = [];
60
+ for (let i = 0; i < levelNumNodes.length; i++)
61
+ levelBounds.push([levelOffsets[i], levelOffsets[i] + levelNumNodes[i]]);
62
+ return levelBounds;
63
+ }
64
+
65
+ type ReadNodeFn = (treeOffset: number, size: number) => Promise<ArrayBuffer>;
66
+
67
+ /**
68
+ * A feature found to be within the bounding box `rect`
69
+ *
70
+ * (offset, index)
71
+ * `offset`: Byte offset in feature data section
72
+ * `index`: feature number
73
+ * `featureLength`: featureLength, except for the last element
74
+ */
75
+ export type SearchResult = [number, number, number | null];
76
+
77
+ /**
78
+ * Yield's a `SearchResult` for each feature within the bounds of `rect`.
79
+ *
80
+ * Every node in the FGB index tree has a bounding rect, all of the nodes children
81
+ * are contained within that bounding rect. The leaf nodes of the tree represent
82
+ * the features of the collection.
83
+ *
84
+ * As we traverse the tree, starting from the root, we'll need to read more data
85
+ * from the index. When we don't already have this range data buffered locally,
86
+ * an HTTP fetch is triggered. For performance, we merge adjacent and nearby
87
+ * request ranges into a single request, reasoning that fetching a few extra
88
+ * bytes is a good tradeoff if it means we can reduce the number of requests.
89
+ */
90
+ export async function* streamSearch(
91
+ numItems: number,
92
+ nodeSize: number,
93
+ rect: Rect,
94
+ readNode: ReadNodeFn
95
+ ): AsyncGenerator<SearchResult, void, unknown> {
96
+ type NodeIdx = number;
97
+ class NodeRange {
98
+ _level: number;
99
+ nodes: [NodeIdx, NodeIdx];
100
+ constructor(nodes: [NodeIdx, NodeIdx], level: number) {
101
+ this._level = level;
102
+ this.nodes = nodes;
103
+ }
104
+
105
+ level(): number {
106
+ return this._level;
107
+ }
108
+
109
+ startNodeIdx(): NodeIdx {
110
+ return this.nodes[0];
111
+ }
112
+
113
+ endNodeIdx(): NodeIdx {
114
+ return this.nodes[1];
115
+ }
116
+
117
+ extendEndNodeIdx(newIdx: number) {
118
+ console.assert(newIdx > this.nodes[1]);
119
+ this.nodes[1] = newIdx;
120
+ }
121
+
122
+ toString(): string {
123
+ return `[NodeRange level: ${this._level}, nodes: ${this.nodes[0]}-${this.nodes[1]}]`;
124
+ }
125
+ }
126
+
127
+ const {minX, minY, maxX, maxY} = rect;
128
+ Logger.info(`tree items: ${numItems}, nodeSize: ${nodeSize}`);
129
+ const levelBounds = generateLevelBounds(numItems, nodeSize);
130
+ const firstLeafNodeIdx = levelBounds[0][0];
131
+
132
+ const rootNodeRange: NodeRange = (() => {
133
+ const range: [number, number] = [0, 1];
134
+ const level = levelBounds.length - 1;
135
+ return new NodeRange(range, level);
136
+ })();
137
+
138
+ const queue: Array<NodeRange> = [rootNodeRange];
139
+
140
+ Logger.debug(
141
+ `starting stream search with queue: ${queue}, numItems: ${numItems}, nodeSize: ${nodeSize}, levelBounds: ${levelBounds}`
142
+ );
143
+
144
+ while (queue.length != 0) {
145
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
146
+ const nodeRange = queue.shift()!;
147
+
148
+ Logger.debug(`popped node: ${nodeRange}, queueLength: ${queue.length}`);
149
+
150
+ const nodeRangeStartIdx = nodeRange.startNodeIdx();
151
+ const isLeafNode = nodeRangeStartIdx >= firstLeafNodeIdx;
152
+
153
+ // find the end index of the node
154
+ const nodeRangeEndIdx = (() => {
155
+ const [, levelBound] = levelBounds[nodeRange.level()];
156
+ const nodeIdx = Math.min(nodeRange.endNodeIdx() + nodeSize, levelBound);
157
+
158
+ if (isLeafNode && nodeIdx < levelBound) {
159
+ // We can infer the length of *this* feature by getting the start of the *next*
160
+ // feature, so we get an extra node.
161
+ // This approach doesn't work for the final node in the index,
162
+ // but in that case we know that the feature runs to the end of the FGB file and
163
+ // could make an open ended range request to get "the rest of the data".
164
+ return nodeIdx + 1;
165
+ }
166
+ return nodeIdx;
167
+ })();
168
+
169
+ const numNodesInRange = nodeRangeEndIdx - nodeRangeStartIdx;
170
+
171
+ const buffer = await readNode(
172
+ nodeRangeStartIdx * NODE_ITEM_BYTE_LEN,
173
+ numNodesInRange * NODE_ITEM_BYTE_LEN
174
+ );
175
+
176
+ const dataView = new DataView(buffer);
177
+ for (let nodeIdx = nodeRangeStartIdx; nodeIdx < nodeRangeEndIdx; nodeIdx++) {
178
+ const nodeIdxInDataView = nodeIdx - nodeRangeStartIdx;
179
+ const dataViewByteStart = nodeIdxInDataView * NODE_ITEM_BYTE_LEN;
180
+ if (maxX < dataView.getFloat64(dataViewByteStart + 0, true)) continue; // maxX < nodeMinX
181
+ if (maxY < dataView.getFloat64(dataViewByteStart + 8, true)) continue; // maxY < nodeMinY
182
+ if (minX > dataView.getFloat64(dataViewByteStart + 16, true)) continue; // minX > nodeMaxX
183
+ if (minY > dataView.getFloat64(dataViewByteStart + 24, true)) continue; // minY > nodeMaxY
184
+
185
+ // `offset` is:
186
+ // For leaf nodes: the byte-offset into the feature buffer.
187
+ // For inner nodes: the node-idx of its first child.
188
+ const offset = dataView.getBigUint64(dataViewByteStart + 32, true);
189
+
190
+ if (isLeafNode) {
191
+ const featureByteOffset = offset;
192
+ const featureLength = (() => {
193
+ if (nodeIdx < numItems - 1) {
194
+ // Since features are tightly packed, we infer the
195
+ // length of _this_ feature by measuring to the _next_
196
+ // feature's start.
197
+ const nextPos = (nodeIdxInDataView + 1) * NODE_ITEM_BYTE_LEN;
198
+ // console.debug(`nodeIdx: ${nodeIdx} of ${numItems}, nodeRangeStartIdx: ${nodeRangeStartIdx}, nextPos: ${nextPos}, dataView.byteLength: ${dataView.byteLength}`,);
199
+ const nextOffset = dataView.getBigUint64(nextPos + 32, true);
200
+ return nextOffset - featureByteOffset;
201
+ }
202
+ // This is the last feature - there's no "next" feature
203
+ // to measure to, so we can't know it's length.
204
+ return null;
205
+ })();
206
+
207
+ // Logger.debug(`featureByteOffset: ${featureByteOffset}, nodeIdx: ${nodeIdx}, featureLength: ${featureLength}`);
208
+ const featureIdx = nodeIdx - firstLeafNodeIdx;
209
+ yield [Number(featureByteOffset), featureIdx, Number(featureLength)];
210
+ continue;
211
+ }
212
+
213
+ const firstChildNodeIdx = offset;
214
+
215
+ // request up to this many nodes if it means we can eliminate an
216
+ // extra request
217
+ const extraRequestThresholdNodes = Config.global.extraRequestThreshold() / NODE_ITEM_BYTE_LEN;
218
+
219
+ // Since we're traversing the tree by monotonically increasing byte
220
+ // offset, the most recently enqueued node range will be the
221
+ // nearest, and thus presents the best candidate for merging.
222
+ const nearestNodeRange = queue[queue.length - 1];
223
+ if (
224
+ nearestNodeRange !== undefined &&
225
+ nearestNodeRange.level() == nodeRange.level() - 1 &&
226
+ firstChildNodeIdx < nearestNodeRange.endNodeIdx() + extraRequestThresholdNodes
227
+ ) {
228
+ Logger.debug(
229
+ `Merging "nodeRange" request into existing range: ${nearestNodeRange}, newEndNodeIdx: ${nearestNodeRange.endNodeIdx()} -> ${firstChildNodeIdx}`
230
+ );
231
+ nearestNodeRange.extendEndNodeIdx(Number(firstChildNodeIdx));
232
+ continue;
233
+ }
234
+
235
+ const newNodeRange: NodeRange = (() => {
236
+ const level = nodeRange.level() - 1;
237
+ const range: [number, number] = [Number(firstChildNodeIdx), Number(firstChildNodeIdx) + 1];
238
+ return new NodeRange(range, level);
239
+ })();
240
+
241
+ // We're going to add a new node range - log the reason
242
+ if (nearestNodeRange !== undefined && nearestNodeRange.level() == newNodeRange.level()) {
243
+ Logger.info(
244
+ `Same level, but too far away. Pushing new request for nodeIdx: ${firstChildNodeIdx} rather than merging with distant ${nearestNodeRange}`
245
+ );
246
+ } else {
247
+ Logger.info(
248
+ `Pushing new level for ${newNodeRange} onto queue with nearestNodeRange: ${nearestNodeRange} since there's not already a range for this level.`
249
+ );
250
+ }
251
+
252
+ queue.push(newNodeRange);
253
+ }
254
+ }
255
+ }
@@ -0,0 +1,80 @@
1
+ import {ReadableStream} from 'web-streams-polyfill';
2
+ import {ReadableStreamBuffer} from 'stream-buffers';
3
+ import {Readable} from 'stream';
4
+
5
+ export function arrayToStream(array: ArrayBuffer): ReadableStream {
6
+ const myReadableStreamBuffer = new ReadableStreamBuffer({
7
+ frequency: 10, // in milliseconds.
8
+ chunkSize: 2048 // in bytes.
9
+ });
10
+
11
+ myReadableStreamBuffer.put(Buffer.from(array));
12
+ myReadableStreamBuffer.stop();
13
+
14
+ const webReader = nodeToWeb(myReadableStreamBuffer as any);
15
+
16
+ return webReader;
17
+ }
18
+
19
+ export async function takeAsync(
20
+ asyncIterable: AsyncIterable<any>,
21
+ count = Infinity
22
+ ): Promise<any[]> {
23
+ const result: any[] = [];
24
+ const iterator = asyncIterable[Symbol.asyncIterator]();
25
+ while (result.length < count) {
26
+ const {value, done} = await iterator.next();
27
+ if (done) break;
28
+ result.push(value);
29
+ }
30
+ return result;
31
+ }
32
+
33
+ export function nodeToWeb(nodeStream: Readable): ReadableStream {
34
+ let destroyed = false;
35
+ const listeners: any = {};
36
+
37
+ function start(controller: ReadableStreamDefaultController) {
38
+ listeners.data = onData;
39
+ listeners.end = onData;
40
+ listeners.end = onDestroy;
41
+ listeners.close = onDestroy;
42
+ listeners.error = onDestroy;
43
+ for (const name in listeners) nodeStream.on(name, listeners[name]);
44
+
45
+ nodeStream.pause();
46
+
47
+ function onData(chunk: Buffer) {
48
+ if (destroyed) return;
49
+ controller.enqueue(chunk);
50
+ nodeStream.pause();
51
+ }
52
+
53
+ function onDestroy(err: Error) {
54
+ if (destroyed) return;
55
+ destroyed = true;
56
+
57
+ for (const name in listeners) nodeStream.removeListener(name, listeners[name]);
58
+
59
+ if (err) controller.error(err);
60
+ else controller.close();
61
+ }
62
+ }
63
+
64
+ function pull() {
65
+ if (destroyed) return;
66
+ nodeStream.resume();
67
+ }
68
+
69
+ function cancel() {
70
+ destroyed = true;
71
+
72
+ for (const name in listeners) nodeStream.removeListener(name, listeners[name]);
73
+
74
+ nodeStream.push(null);
75
+ nodeStream.pause();
76
+ nodeStream.destroy();
77
+ }
78
+
79
+ return new ReadableStream({start, pull, cancel});
80
+ }
@@ -0,0 +1,23 @@
1
+ declare module 'jsts/org/locationtech/jts/io/GeoJSONWriter.js' {
2
+ export default class GeoJSONWriter {
3
+ write(geometry: any): any;
4
+ }
5
+ }
6
+
7
+ declare module 'jsts/org/locationtech/jts/io/WKTReader.js' {
8
+ export default class WKTReader {
9
+ read(): any;
10
+ }
11
+ }
12
+
13
+ declare module 'jsts/org/locationtech/jts/geom/Envelope.js' {
14
+ export default class Envelope {
15
+ constructor(minx: number, maxx: number, miny: number, maxy: number);
16
+ }
17
+ }
18
+
19
+ declare module 'jsts/org/locationtech/jts/geom/GeometryFactory.js' {
20
+ export default class GeometryFactory {
21
+ toGeometry(e: any): any;
22
+ }
23
+ }
@@ -0,0 +1,16 @@
1
+ declare module 'slice-source' {
2
+ function slice(source: ReadableStream | SliceSource): SliceSource;
3
+
4
+ interface SliceChunk {
5
+ value: Uint8Array;
6
+ done: boolean;
7
+ }
8
+
9
+ interface SliceSource {
10
+ slice(length: number): Promise<Uint8Array>;
11
+ read(): Promise<SliceChunk>;
12
+ cancel(): Promise<void>;
13
+ }
14
+
15
+ export = slice;
16
+ }
@@ -2,8 +2,8 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {Geometry as FGBGeometry, Feature as FGBFeature} from 'flatgeobuf';
6
- // import {GeometryType} from 'flatgeobuf/generic';
5
+ import {Geometry as FGBGeometry, Feature as FGBFeature} from '../flatgeobuf/3.27.2';
6
+ // import {GeometryType} from '../flatgeobuf/generic';
7
7
  // Copy geometry type as it is hard to access the export
8
8
  export declare enum GeometryType {
9
9
  Unknown = 0,
@@ -3,7 +3,7 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  import type {Schema, Field, DataType} from '@loaders.gl/schema';
6
- import * as fgb from 'flatgeobuf';
6
+ import * as fgb from '../flatgeobuf/3.27.2';
7
7
 
8
8
  /**
9
9
  * @param fgbHeader
@@ -11,10 +11,10 @@ import type {GeoJSONTable, Table, Schema} from '@loaders.gl/schema';
11
11
  import {fgbToBinaryGeometry} from './binary-geometries';
12
12
  import {getSchemaFromFGBHeader} from './get-schema-from-fgb-header';
13
13
 
14
- import * as fgb from 'flatgeobuf';
15
- import * as geojson from 'flatgeobuf/lib/mjs/geojson.js';
16
- import * as generic from 'flatgeobuf/lib/mjs/generic.js';
17
- import {parseProperties as parsePropertiesBinary} from 'flatgeobuf/lib/mjs/generic/feature';
14
+ import * as fgb from '../flatgeobuf/3.27.2';
15
+ import * as geojson from '../flatgeobuf/3.27.2/geojson.js';
16
+ import * as generic from '../flatgeobuf/3.27.2/generic.js';
17
+ import {parseProperties as parsePropertiesBinary} from '../flatgeobuf/3.27.2/generic/feature';
18
18
 
19
19
  const deserializeGeoJson = geojson.deserialize;
20
20
  const deserializeGeneric = generic.deserialize;