@loaders.gl/flatgeobuf 4.3.0-alpha.2 → 4.3.0-alpha.4

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.
@@ -1,16 +1,17 @@
1
1
  import type { LoaderOptions } from '@loaders.gl/loader-utils';
2
- import { parseFlatGeobuf, parseFlatGeobufInBatches } from "./lib/parse-flatgeobuf.js";
3
2
  export type FlatGeobufLoaderOptions = LoaderOptions & {
4
3
  flatgeobuf?: {
5
4
  shape?: 'geojson-table' | 'columnar-table' | 'binary';
6
5
  /** Override the URL to the worker bundle (by default loads from unpkg.com) */
7
6
  workerUrl?: string;
7
+ boundingBox?: [[number, number], [number, number]];
8
8
  };
9
9
  gis?: {
10
10
  reproject?: boolean;
11
11
  _targetCrs?: string;
12
12
  };
13
13
  };
14
+ /** Load flatgeobuf on a worker */
14
15
  export declare const FlatGeobufWorkerLoader: {
15
16
  readonly dataType: any;
16
17
  readonly batchType: any;
@@ -33,9 +34,9 @@ export declare const FlatGeobufWorkerLoader: {
33
34
  };
34
35
  };
35
36
  export declare const FlatGeobufLoader: {
36
- readonly parse: (arrayBuffer: ArrayBuffer, options: FlatGeobufLoaderOptions | undefined) => Promise<import("@loaders.gl/schema").Table>;
37
- readonly parseSync: typeof parseFlatGeobuf;
38
- readonly parseInBatchesFromStream: typeof parseFlatGeobufInBatches;
37
+ readonly parse: (arrayBuffer: ArrayBuffer, options?: FlatGeobufLoaderOptions) => Promise<import("@loaders.gl/schema").Table>;
38
+ readonly parseSync: typeof parseSync;
39
+ readonly parseInBatchesFromStream: typeof parseInBatchesFromStream;
39
40
  readonly binary: true;
40
41
  readonly dataType: any;
41
42
  readonly batchType: any;
@@ -57,4 +58,7 @@ export declare const FlatGeobufLoader: {
57
58
  };
58
59
  };
59
60
  };
61
+ declare function parseSync(arrayBuffer: ArrayBuffer, options?: FlatGeobufLoaderOptions): import("@loaders.gl/schema").Table;
62
+ declare function parseInBatchesFromStream(stream: any, options: FlatGeobufLoaderOptions): any[] | AsyncGenerator<import("./flatgeobuf/3.27.2").IFeature, any, unknown> | AsyncGenerator<any, void, unknown>;
63
+ export {};
60
64
  //# sourceMappingURL=flatgeobuf-loader.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"flatgeobuf-loader.d.ts","sourceRoot":"","sources":["../src/flatgeobuf-loader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAA2B,aAAa,EAAC,MAAM,0BAA0B,CAAC;AACtF,OAAO,EAAC,eAAe,EAAE,wBAAwB,EAAC,kCAA+B;AASjF,MAAM,MAAM,uBAAuB,GAAG,aAAa,GAAG;IACpD,UAAU,CAAC,EAAE;QACX,KAAK,CAAC,EAAE,eAAe,GAAG,gBAAgB,GAAG,QAAQ,CAAC;QACtD,8EAA8E;QAC9E,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,GAAG,CAAC,EAAE;QACJ,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC;CACH,CAAC;AAEF,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;CAqB2B,CAAC;AAE/D,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;CAO2C,CAAC"}
1
+ {"version":3,"file":"flatgeobuf-loader.d.ts","sourceRoot":"","sources":["../src/flatgeobuf-loader.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAA2B,aAAa,EAAC,MAAM,0BAA0B,CAAC;AActF,MAAM,MAAM,uBAAuB,GAAG,aAAa,GAAG;IACpD,UAAU,CAAC,EAAE;QACX,KAAK,CAAC,EAAE,eAAe,GAAG,gBAAgB,GAAG,QAAQ,CAAC;QACtD,8EAA8E;QAC9E,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,WAAW,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;KACpD,CAAC;IACF,GAAG,CAAC,EAAE;QACJ,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC;CACH,CAAC;AAEF,kCAAkC;AAClC,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;CAqB8D,CAAC;AAElG,eAAO,MAAM,gBAAgB;kCAEA,WAAW,YAAW,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;CAMF,CAAC;AAEzE,iBAAS,SAAS,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,GAAE,uBAA4B,sCAEjF;AAED,iBAAS,wBAAwB,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,uBAAuB,qHAE9E"}
@@ -4,9 +4,10 @@
4
4
  import { parseFlatGeobuf, parseFlatGeobufInBatches } from "./lib/parse-flatgeobuf.js";
5
5
  // __VERSION__ is injected by babel-plugin-version-inline
6
6
  // @ts-ignore TS2304: Cannot find name '__VERSION__'.
7
- const VERSION = typeof "4.3.0-alpha.1" !== 'undefined' ? "4.3.0-alpha.1" : 'latest';
7
+ const VERSION = typeof "4.3.0-alpha.3" !== 'undefined' ? "4.3.0-alpha.3" : 'latest';
8
8
  // FGB\3FGB\1
9
9
  const FGB_MAGIC_NUMBER = [0x66, 0x67, 0x62, 0x03, 0x66, 0x67, 0x62, 0x01];
10
+ /** Load flatgeobuf on a worker */
10
11
  export const FlatGeobufWorkerLoader = {
11
12
  dataType: null,
12
13
  batchType: null,
@@ -30,9 +31,28 @@ export const FlatGeobufWorkerLoader = {
30
31
  };
31
32
  export const FlatGeobufLoader = {
32
33
  ...FlatGeobufWorkerLoader,
33
- parse: async (arrayBuffer, options) => parseFlatGeobuf(arrayBuffer, options),
34
- parseSync: parseFlatGeobuf,
34
+ parse: async (arrayBuffer, options = {}) => parseSync(arrayBuffer, options),
35
+ parseSync,
35
36
  // @ts-expect-error this is a stream parser not an async iterator parser
36
- parseInBatchesFromStream: parseFlatGeobufInBatches,
37
+ parseInBatchesFromStream,
37
38
  binary: true
38
39
  };
40
+ function parseSync(arrayBuffer, options = {}) {
41
+ return parseFlatGeobuf(arrayBuffer, getOptions(options));
42
+ }
43
+ function parseInBatchesFromStream(stream, options) {
44
+ return parseFlatGeobufInBatches(stream, getOptions(options));
45
+ }
46
+ function getOptions(options) {
47
+ options = {
48
+ ...options,
49
+ flatgeobuf: { ...FlatGeobufLoader.options.flatgeobuf, ...options?.flatgeobuf },
50
+ gis: { ...FlatGeobufLoader.options.gis, ...options?.gis }
51
+ };
52
+ return {
53
+ shape: options?.flatgeobuf?.shape ?? 'geojson-table',
54
+ boundingBox: options?.flatgeobuf?.boundingBox,
55
+ crs: options?.gis?._targetCrs || 'WGS84',
56
+ reproject: options?.gis?.reproject || false
57
+ };
58
+ }
@@ -8769,15 +8769,8 @@
8769
8769
  // src/lib/parse-flatgeobuf.ts
8770
8770
  var deserializeGeoJson = deserialize3;
8771
8771
  var deserializeGeneric = deserialize4;
8772
- function binaryFromFeature(feature, header) {
8773
- const geometry = feature.geometry();
8774
- const geometryType = header.geometryType || geometry?.type();
8775
- const parsedGeometry = fgbToBinaryGeometry(geometry, geometryType);
8776
- parsedGeometry.properties = parseProperties(feature, header.columns);
8777
- return parsedGeometry;
8778
- }
8779
8772
  function parseFlatGeobuf(arrayBuffer, options) {
8780
- const shape = options?.flatgeobuf?.shape;
8773
+ const shape = options.shape;
8781
8774
  switch (shape) {
8782
8775
  case "geojson-table": {
8783
8776
  return parseFlatGeobufToGeoJSONTable(arrayBuffer, options);
@@ -8795,24 +8788,25 @@
8795
8788
  const array = new Uint8Array(arrayBuffer);
8796
8789
  return deserializeGeneric(array, fgbToBinaryGeometry);
8797
8790
  }
8798
- function parseFlatGeobufToGeoJSONTable(arrayBuffer, options = {}) {
8791
+ function parseFlatGeobufToGeoJSONTable(arrayBuffer, options) {
8799
8792
  if (arrayBuffer.byteLength === 0) {
8800
8793
  return { shape: "geojson-table", type: "FeatureCollection", features: [] };
8801
8794
  }
8802
- const { reproject = false, _targetCrs = "WGS84" } = options && options.gis || {};
8795
+ const { reproject = false, crs = "WGS84" } = options;
8803
8796
  const arr = new Uint8Array(arrayBuffer);
8804
8797
  let fgbHeader;
8805
8798
  let schema;
8806
- let { features } = deserializeGeoJson(arr, void 0, (headerMeta) => {
8799
+ const rect = options.boundingBox && convertBoundingBox(options.boundingBox);
8800
+ let { features } = deserializeGeoJson(arr, rect, (headerMeta) => {
8807
8801
  fgbHeader = headerMeta;
8808
8802
  schema = getSchemaFromFGBHeader(fgbHeader);
8809
8803
  });
8810
- const crs = fgbHeader && fgbHeader.crs;
8804
+ const fromCRS = fgbHeader?.crs?.wkt;
8811
8805
  let projection;
8812
- if (reproject && crs) {
8806
+ if (reproject && fromCRS) {
8813
8807
  try {
8814
- projection = new Proj4Projection({ from: crs.wkt, to: _targetCrs });
8815
- } catch (e) {
8808
+ projection = new Proj4Projection({ from: fromCRS, to: crs });
8809
+ } catch (error) {
8816
8810
  }
8817
8811
  }
8818
8812
  if (projection) {
@@ -8821,7 +8815,7 @@
8821
8815
  return { shape: "geojson-table", schema, type: "FeatureCollection", features };
8822
8816
  }
8823
8817
  function parseFlatGeobufInBatches(stream, options) {
8824
- const shape = options.flatgeobuf?.shape;
8818
+ const shape = options.shape;
8825
8819
  switch (shape) {
8826
8820
  case "binary":
8827
8821
  return parseFlatGeobufInBatchesToBinary(stream, options);
@@ -8832,11 +8826,12 @@
8832
8826
  }
8833
8827
  }
8834
8828
  function parseFlatGeobufInBatchesToBinary(stream, options) {
8835
- const iterator = deserializeGeneric(stream, binaryFromFeature);
8829
+ const rect = options.boundingBox && convertBoundingBox(options.boundingBox);
8830
+ const iterator = deserializeGeneric(stream, binaryFromFeature, rect);
8836
8831
  return iterator;
8837
8832
  }
8838
8833
  async function* parseFlatGeobufInBatchesToGeoJSON(stream, options) {
8839
- const { reproject = false, _targetCrs = "WGS84" } = options && options.gis || {};
8834
+ const { reproject = false, crs = "WGS84" } = options || {};
8840
8835
  let fgbHeader;
8841
8836
  const iterator = deserializeGeoJson(stream, void 0, (headerMeta) => {
8842
8837
  fgbHeader = headerMeta;
@@ -8845,9 +8840,9 @@
8845
8840
  let firstRecord = true;
8846
8841
  for await (const feature of iterator) {
8847
8842
  if (firstRecord) {
8848
- const crs = fgbHeader && fgbHeader.crs;
8849
- if (reproject && crs) {
8850
- projection = new Proj4Projection({ from: crs.wkt, to: _targetCrs });
8843
+ const fromCRS = fgbHeader?.crs?.wkt;
8844
+ if (reproject && fromCRS) {
8845
+ projection = new Proj4Projection({ from: fromCRS, to: crs });
8851
8846
  }
8852
8847
  firstRecord = false;
8853
8848
  }
@@ -8858,9 +8853,24 @@
8858
8853
  }
8859
8854
  }
8860
8855
  }
8856
+ function convertBoundingBox(boundingBox) {
8857
+ return {
8858
+ minX: boundingBox[0][0],
8859
+ minY: boundingBox[0][1],
8860
+ maxX: boundingBox[1][0],
8861
+ maxY: boundingBox[1][1]
8862
+ };
8863
+ }
8864
+ function binaryFromFeature(feature, header) {
8865
+ const geometry = feature.geometry();
8866
+ const geometryType = header.geometryType || geometry?.type();
8867
+ const parsedGeometry = fgbToBinaryGeometry(geometry, geometryType);
8868
+ parsedGeometry.properties = parseProperties(feature, header.columns);
8869
+ return parsedGeometry;
8870
+ }
8861
8871
 
8862
8872
  // src/flatgeobuf-loader.ts
8863
- var VERSION = true ? "4.3.0-alpha.1" : "latest";
8873
+ var VERSION = true ? "4.3.0-alpha.3" : "latest";
8864
8874
  var FGB_MAGIC_NUMBER = [102, 103, 98, 3, 102, 103, 98, 1];
8865
8875
  var FlatGeobufWorkerLoader = {
8866
8876
  dataType: null,
@@ -8885,12 +8895,31 @@
8885
8895
  };
8886
8896
  var FlatGeobufLoader = {
8887
8897
  ...FlatGeobufWorkerLoader,
8888
- parse: async (arrayBuffer, options) => parseFlatGeobuf(arrayBuffer, options),
8889
- parseSync: parseFlatGeobuf,
8898
+ parse: async (arrayBuffer, options = {}) => parseSync(arrayBuffer, options),
8899
+ parseSync,
8890
8900
  // @ts-expect-error this is a stream parser not an async iterator parser
8891
- parseInBatchesFromStream: parseFlatGeobufInBatches,
8901
+ parseInBatchesFromStream,
8892
8902
  binary: true
8893
8903
  };
8904
+ function parseSync(arrayBuffer, options = {}) {
8905
+ return parseFlatGeobuf(arrayBuffer, getOptions(options));
8906
+ }
8907
+ function parseInBatchesFromStream(stream, options) {
8908
+ return parseFlatGeobufInBatches(stream, getOptions(options));
8909
+ }
8910
+ function getOptions(options) {
8911
+ options = {
8912
+ ...options,
8913
+ flatgeobuf: { ...FlatGeobufLoader.options.flatgeobuf, ...options?.flatgeobuf },
8914
+ gis: { ...FlatGeobufLoader.options.gis, ...options?.gis }
8915
+ };
8916
+ return {
8917
+ shape: options?.flatgeobuf?.shape ?? "geojson-table",
8918
+ boundingBox: options?.flatgeobuf?.boundingBox,
8919
+ crs: options?.gis?._targetCrs || "WGS84",
8920
+ reproject: options?.gis?.reproject || false
8921
+ };
8922
+ }
8894
8923
 
8895
8924
  // src/workers/flatgeobuf-worker.ts
8896
8925
  createLoaderWorker(FlatGeobufLoader);
@@ -0,0 +1,51 @@
1
+ import { Schema, GeoJSONTable } from '@loaders.gl/schema';
2
+ import type { VectorSourceProps, VectorSourceMetadata, GetFeaturesParameters, LoaderWithParser } from '@loaders.gl/loader-utils';
3
+ import { VectorSource } from '@loaders.gl/loader-utils';
4
+ /**
5
+ * @ndeprecated This is a WIP, not fully implemented
6
+ * @see https://developers.arcgis.com/rest/services-reference/enterprise/feature-service.htm
7
+ */
8
+ export declare const FlatGeobufSource: {
9
+ readonly name: "FlatGeobuf";
10
+ readonly id: "flatgeobuf-server";
11
+ readonly module: "wms";
12
+ readonly version: "0.0.0";
13
+ readonly extensions: [];
14
+ readonly mimeTypes: [];
15
+ readonly options: {
16
+ readonly url: never;
17
+ readonly 'flatgeobuf-server': {
18
+ /** Tabular loaders, normally the GeoJSONLoader */
19
+ readonly loaders: [];
20
+ };
21
+ };
22
+ readonly type: "flatgeobuf-server";
23
+ readonly fromUrl: true;
24
+ readonly fromBlob: false;
25
+ readonly testURL: (url: string) => boolean;
26
+ readonly createDataSource: (url: string | Blob, props: FlatGeobufVectorSourceProps) => FlatGeobufVectorSource;
27
+ };
28
+ export type FlatGeobufVectorSourceProps = VectorSourceProps & {
29
+ url: string;
30
+ 'flatgeobuf-server'?: {
31
+ loaders: LoaderWithParser[];
32
+ };
33
+ };
34
+ /**
35
+ * ArcGIS ImageServer
36
+ * Note - exports a big API, that could be exposed here if there is a use case
37
+ * @see https://developers.arcgis.com/rest/services-reference/enterprise/feature-service.htm
38
+ */
39
+ export declare class FlatGeobufVectorSource extends VectorSource<FlatGeobufVectorSourceProps> {
40
+ data: string;
41
+ url: string;
42
+ protected formatSpecificMetadata: Promise<any> | null;
43
+ constructor(props: FlatGeobufVectorSourceProps);
44
+ /** TODO - not yet clear if we can find schema information in the FeatureServer metadata or if we need to request a feature */
45
+ getSchema(): Promise<Schema>;
46
+ getMetadata(options: {
47
+ formatSpecificMetadata: any;
48
+ }): Promise<VectorSourceMetadata>;
49
+ getFeatures(parameters: GetFeaturesParameters): Promise<GeoJSONTable>;
50
+ }
51
+ //# sourceMappingURL=floatgeobuf-source.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"floatgeobuf-source.d.ts","sourceRoot":"","sources":["../src/floatgeobuf-source.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,MAAM,EAAE,YAAY,EAAC,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EACV,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACrB,gBAAgB,EACjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAS,YAAY,EAAC,MAAM,0BAA0B,CAAC;AAI9D;;;GAGG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;YAUvB,kDAAkD;;;;;;;4BASvC,MAAM,KAAG,OAAO;2DACA,2BAA2B,KAAG,sBAAsB;CAEL,CAAC;AAEjF,MAAM,MAAM,2BAA2B,GAAG,iBAAiB,GAAG;IAC5D,GAAG,EAAE,MAAM,CAAC;IACZ,mBAAmB,CAAC,EAAE;QACpB,OAAO,EAAE,gBAAgB,EAAE,CAAC;KAC7B,CAAC;CACH,CAAC;AAEF;;;;GAIG;AACH,qBAAa,sBAAuB,SAAQ,YAAY,CAAC,2BAA2B,CAAC;IACnF,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,sBAAsB,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAQ;gBAEjD,KAAK,EAAE,2BAA2B;IAO9C,8HAA8H;IACxH,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;IAK5B,WAAW,CAAC,OAAO,EAAE;QAAC,sBAAsB,MAAA;KAAC,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAgB7E,WAAW,CAAC,UAAU,EAAE,qBAAqB,GAAG,OAAO,CAAC,YAAY,CAAC;CAU5E"}
@@ -0,0 +1,72 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ import { VectorSource } from '@loaders.gl/loader-utils';
5
+ import { FlatGeobufLoader } from "./flatgeobuf-loader.js";
6
+ /**
7
+ * @ndeprecated This is a WIP, not fully implemented
8
+ * @see https://developers.arcgis.com/rest/services-reference/enterprise/feature-service.htm
9
+ */
10
+ export const FlatGeobufSource = {
11
+ name: 'FlatGeobuf',
12
+ id: 'flatgeobuf-server',
13
+ module: 'wms',
14
+ version: '0.0.0',
15
+ extensions: [],
16
+ mimeTypes: [],
17
+ options: {
18
+ url: undefined,
19
+ 'flatgeobuf-server': {
20
+ /** Tabular loaders, normally the GeoJSONLoader */
21
+ loaders: []
22
+ }
23
+ },
24
+ type: 'flatgeobuf-server',
25
+ fromUrl: true,
26
+ fromBlob: false, // TODO check if supported by library?
27
+ testURL: (url) => url.toLowerCase().includes('FeatureServer'),
28
+ createDataSource: (url, props) => new FlatGeobufVectorSource(props)
29
+ };
30
+ /**
31
+ * ArcGIS ImageServer
32
+ * Note - exports a big API, that could be exposed here if there is a use case
33
+ * @see https://developers.arcgis.com/rest/services-reference/enterprise/feature-service.htm
34
+ */
35
+ export class FlatGeobufVectorSource extends VectorSource {
36
+ data;
37
+ url;
38
+ formatSpecificMetadata = null;
39
+ constructor(props) {
40
+ super(props);
41
+ this.data = props.url;
42
+ this.url = props.url;
43
+ // this.formatSpecificMetadata = this._getFormatSpecificMetadata();
44
+ }
45
+ /** TODO - not yet clear if we can find schema information in the FeatureServer metadata or if we need to request a feature */
46
+ async getSchema() {
47
+ await this.getMetadata({ formatSpecificMetadata: true });
48
+ return { metadata: {}, fields: [] };
49
+ }
50
+ async getMetadata(options) {
51
+ // Wait for raw metadata to load
52
+ if (!this.formatSpecificMetadata) {
53
+ // this.formatSpecificMetadata = await this._getFormatSpecificMetadata();
54
+ }
55
+ // const metadata = parseFlatGeobufMetadata(this.formatSpecificMetadata);
56
+ // Only add the big blob of source metadata if explicitly requested
57
+ if (options.formatSpecificMetadata) {
58
+ // metadata.formatSpecificMetadata = this.formatSpecificMetadata;
59
+ }
60
+ // @ts-expect-error
61
+ return {};
62
+ }
63
+ async getFeatures(parameters) {
64
+ const response = await this.fetch(this.url);
65
+ const arrayBuffer = await response.arrayBuffer();
66
+ // TODO - hack - done to avoid pulling in selectLoader from core
67
+ const table = await FlatGeobufLoader.parse(arrayBuffer, {});
68
+ // const loader = this.props['flatgeobuf-server']?.loaders?.[0];
69
+ // const table = loader?.parse(arrayBuffer);
70
+ return table;
71
+ }
72
+ }
package/dist/index.cjs CHANGED
@@ -1744,16 +1744,8 @@ function deserialize4(input, fromFeature2, rect) {
1744
1744
  // dist/lib/parse-flatgeobuf.js
1745
1745
  var deserializeGeoJson = deserialize3;
1746
1746
  var deserializeGeneric = deserialize4;
1747
- function binaryFromFeature(feature, header) {
1748
- const geometry = feature.geometry();
1749
- const geometryType = header.geometryType || (geometry == null ? void 0 : geometry.type());
1750
- const parsedGeometry = fgbToBinaryGeometry(geometry, geometryType);
1751
- parsedGeometry.properties = parseProperties(feature, header.columns);
1752
- return parsedGeometry;
1753
- }
1754
1747
  function parseFlatGeobuf(arrayBuffer, options) {
1755
- var _a;
1756
- const shape = (_a = options == null ? void 0 : options.flatgeobuf) == null ? void 0 : _a.shape;
1748
+ const shape = options.shape;
1757
1749
  switch (shape) {
1758
1750
  case "geojson-table": {
1759
1751
  return parseFlatGeobufToGeoJSONTable(arrayBuffer, options);
@@ -1771,24 +1763,26 @@ function parseFlatGeobufToBinary(arrayBuffer, options = {}) {
1771
1763
  const array = new Uint8Array(arrayBuffer);
1772
1764
  return deserializeGeneric(array, fgbToBinaryGeometry);
1773
1765
  }
1774
- function parseFlatGeobufToGeoJSONTable(arrayBuffer, options = {}) {
1766
+ function parseFlatGeobufToGeoJSONTable(arrayBuffer, options) {
1767
+ var _a;
1775
1768
  if (arrayBuffer.byteLength === 0) {
1776
1769
  return { shape: "geojson-table", type: "FeatureCollection", features: [] };
1777
1770
  }
1778
- const { reproject = false, _targetCrs = "WGS84" } = options && options.gis || {};
1771
+ const { reproject = false, crs = "WGS84" } = options;
1779
1772
  const arr = new Uint8Array(arrayBuffer);
1780
1773
  let fgbHeader;
1781
1774
  let schema;
1782
- let { features } = deserializeGeoJson(arr, void 0, (headerMeta) => {
1775
+ const rect = options.boundingBox && convertBoundingBox(options.boundingBox);
1776
+ let { features } = deserializeGeoJson(arr, rect, (headerMeta) => {
1783
1777
  fgbHeader = headerMeta;
1784
1778
  schema = getSchemaFromFGBHeader(fgbHeader);
1785
1779
  });
1786
- const crs = fgbHeader && fgbHeader.crs;
1780
+ const fromCRS = (_a = fgbHeader == null ? void 0 : fgbHeader.crs) == null ? void 0 : _a.wkt;
1787
1781
  let projection;
1788
- if (reproject && crs) {
1782
+ if (reproject && fromCRS) {
1789
1783
  try {
1790
- projection = new import_proj4.Proj4Projection({ from: crs.wkt, to: _targetCrs });
1791
- } catch (e) {
1784
+ projection = new import_proj4.Proj4Projection({ from: fromCRS, to: crs });
1785
+ } catch (error) {
1792
1786
  }
1793
1787
  }
1794
1788
  if (projection) {
@@ -1797,8 +1791,7 @@ function parseFlatGeobufToGeoJSONTable(arrayBuffer, options = {}) {
1797
1791
  return { shape: "geojson-table", schema, type: "FeatureCollection", features };
1798
1792
  }
1799
1793
  function parseFlatGeobufInBatches(stream, options) {
1800
- var _a;
1801
- const shape = (_a = options.flatgeobuf) == null ? void 0 : _a.shape;
1794
+ const shape = options.shape;
1802
1795
  switch (shape) {
1803
1796
  case "binary":
1804
1797
  return parseFlatGeobufInBatchesToBinary(stream, options);
@@ -1809,11 +1802,13 @@ function parseFlatGeobufInBatches(stream, options) {
1809
1802
  }
1810
1803
  }
1811
1804
  function parseFlatGeobufInBatchesToBinary(stream, options) {
1812
- const iterator = deserializeGeneric(stream, binaryFromFeature);
1805
+ const rect = options.boundingBox && convertBoundingBox(options.boundingBox);
1806
+ const iterator = deserializeGeneric(stream, binaryFromFeature, rect);
1813
1807
  return iterator;
1814
1808
  }
1815
1809
  async function* parseFlatGeobufInBatchesToGeoJSON(stream, options) {
1816
- const { reproject = false, _targetCrs = "WGS84" } = options && options.gis || {};
1810
+ var _a;
1811
+ const { reproject = false, crs = "WGS84" } = options || {};
1817
1812
  let fgbHeader;
1818
1813
  const iterator = deserializeGeoJson(stream, void 0, (headerMeta) => {
1819
1814
  fgbHeader = headerMeta;
@@ -1822,9 +1817,9 @@ async function* parseFlatGeobufInBatchesToGeoJSON(stream, options) {
1822
1817
  let firstRecord = true;
1823
1818
  for await (const feature of iterator) {
1824
1819
  if (firstRecord) {
1825
- const crs = fgbHeader && fgbHeader.crs;
1826
- if (reproject && crs) {
1827
- projection = new import_proj4.Proj4Projection({ from: crs.wkt, to: _targetCrs });
1820
+ const fromCRS = (_a = fgbHeader == null ? void 0 : fgbHeader.crs) == null ? void 0 : _a.wkt;
1821
+ if (reproject && fromCRS) {
1822
+ projection = new import_proj4.Proj4Projection({ from: fromCRS, to: crs });
1828
1823
  }
1829
1824
  firstRecord = false;
1830
1825
  }
@@ -1835,9 +1830,24 @@ async function* parseFlatGeobufInBatchesToGeoJSON(stream, options) {
1835
1830
  }
1836
1831
  }
1837
1832
  }
1833
+ function convertBoundingBox(boundingBox) {
1834
+ return {
1835
+ minX: boundingBox[0][0],
1836
+ minY: boundingBox[0][1],
1837
+ maxX: boundingBox[1][0],
1838
+ maxY: boundingBox[1][1]
1839
+ };
1840
+ }
1841
+ function binaryFromFeature(feature, header) {
1842
+ const geometry = feature.geometry();
1843
+ const geometryType = header.geometryType || (geometry == null ? void 0 : geometry.type());
1844
+ const parsedGeometry = fgbToBinaryGeometry(geometry, geometryType);
1845
+ parsedGeometry.properties = parseProperties(feature, header.columns);
1846
+ return parsedGeometry;
1847
+ }
1838
1848
 
1839
1849
  // dist/flatgeobuf-loader.js
1840
- var VERSION = true ? "4.3.0-alpha.1" : "latest";
1850
+ var VERSION = true ? "4.3.0-alpha.3" : "latest";
1841
1851
  var FGB_MAGIC_NUMBER = [102, 103, 98, 3, 102, 103, 98, 1];
1842
1852
  var FlatGeobufWorkerLoader = {
1843
1853
  dataType: null,
@@ -1862,10 +1872,30 @@ var FlatGeobufWorkerLoader = {
1862
1872
  };
1863
1873
  var FlatGeobufLoader = {
1864
1874
  ...FlatGeobufWorkerLoader,
1865
- parse: async (arrayBuffer, options) => parseFlatGeobuf(arrayBuffer, options),
1866
- parseSync: parseFlatGeobuf,
1875
+ parse: async (arrayBuffer, options = {}) => parseSync(arrayBuffer, options),
1876
+ parseSync,
1867
1877
  // @ts-expect-error this is a stream parser not an async iterator parser
1868
- parseInBatchesFromStream: parseFlatGeobufInBatches,
1878
+ parseInBatchesFromStream,
1869
1879
  binary: true
1870
1880
  };
1881
+ function parseSync(arrayBuffer, options = {}) {
1882
+ return parseFlatGeobuf(arrayBuffer, getOptions(options));
1883
+ }
1884
+ function parseInBatchesFromStream(stream, options) {
1885
+ return parseFlatGeobufInBatches(stream, getOptions(options));
1886
+ }
1887
+ function getOptions(options) {
1888
+ var _a, _b, _c, _d;
1889
+ options = {
1890
+ ...options,
1891
+ flatgeobuf: { ...FlatGeobufLoader.options.flatgeobuf, ...options == null ? void 0 : options.flatgeobuf },
1892
+ gis: { ...FlatGeobufLoader.options.gis, ...options == null ? void 0 : options.gis }
1893
+ };
1894
+ return {
1895
+ shape: ((_a = options == null ? void 0 : options.flatgeobuf) == null ? void 0 : _a.shape) ?? "geojson-table",
1896
+ boundingBox: (_b = options == null ? void 0 : options.flatgeobuf) == null ? void 0 : _b.boundingBox,
1897
+ crs: ((_c = options == null ? void 0 : options.gis) == null ? void 0 : _c._targetCrs) || "WGS84",
1898
+ reproject: ((_d = options == null ? void 0 : options.gis) == null ? void 0 : _d.reproject) || false
1899
+ };
1900
+ }
1871
1901
  //# sourceMappingURL=index.cjs.map