@loaders.gl/pmtiles 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 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,YAAY,EAAC,eAAe,EAAC,+BAA4B;AACzD,YAAY,EAAC,kBAAkB,EAAC,4BAAyB;AACzD,OAAO,EAAC,aAAa,EAAC,4BAAyB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,aAAa,EAAC,4BAAyB;AAE/C,YAAY,EAAC,eAAe,EAAC,+BAA4B;AACzD,YAAY,EAAC,sBAAsB,EAAC,4BAAyB;AAC7D,OAAO,EAAC,iBAAiB,EAAC,4BAAyB;AAEnD,OAAO,EAAC,aAAa,IAAI,cAAc,EAAC,4BAAyB;AACjE,YAAY,EAAC,oBAAoB,EAAC,4BAAyB"}
package/dist/index.js CHANGED
@@ -2,3 +2,5 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
  export { PMTilesSource } from "./pmtiles-source.js";
5
+ export { PMTilesTileSource } from "./pmtiles-source.js";
6
+ export { PMTilesLoader as _PMTilesLoader } from "./pmtiles-loader.js";
@@ -1,4 +1,4 @@
1
- import type { LoaderOptions } from '@loaders.gl/loader-utils';
1
+ import { LoaderOptions } from '@loaders.gl/loader-utils';
2
2
  import type { TileJSON } from '@loaders.gl/mvt';
3
3
  import * as pmtiles from 'pmtiles';
4
4
  /** Metadata describing a PMTiles file */
@@ -39,7 +39,7 @@ export type PMTilesMetadata = {
39
39
  * @param loadOptions
40
40
  * @returns
41
41
  */
42
- export declare function parsePMTilesHeader(header: pmtiles.Header, pmmetadata: unknown, options?: {
42
+ export declare function parsePMTilesHeader(header: pmtiles.Header, pmtilesMetadata: Record<string, unknown> | null, options?: {
43
43
  includeFormatHeader?: boolean;
44
44
  }, loadOptions?: LoaderOptions): PMTilesMetadata;
45
45
  //# sourceMappingURL=parse-pmtiles.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parse-pmtiles.d.ts","sourceRoot":"","sources":["../../src/lib/parse-pmtiles.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,iBAAiB,CAAC;AAG9C,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAGnC,yCAAyC;AACzC,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,SAAS,CAAC;IAClB,sDAAsD;IACtD,aAAa,EAAE,MAAM,CAAC;IAEtB,4FAA4F;IAC5F,YAAY,EACR,oCAAoC,GACpC,WAAW,GACX,YAAY,GACZ,YAAY,GACZ,YAAY,GACZ,0BAA0B,CAAC;IAE/B,sEAAsE;IACtE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qEAAqE;IACrE,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IAExB,kDAAkD;IAClD,OAAO,EAAE,MAAM,CAAC;IAChB,kDAAkD;IAClD,OAAO,EAAE,MAAM,CAAC;IAChB,gEAAgE;IAChE,WAAW,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;IACxE,uCAAuC;IACvC,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzB,wCAAwC;IACxC,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,qDAAqD;IACrD,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAEpB,iDAAiD;IACjD,YAAY,CAAC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EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzB,wCAAwC;IACxC,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,qDAAqD;IACrD,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAEpB,iDAAiD;IACjD,YAAY,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC;IAC9B,2GAA2G;IAC3G,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC1C,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,OAAO,CAAC,MAAM,EACtB,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,EAC/C,OAAO,CAAC,EAAE;IAAC,mBAAmB,CAAC,EAAE,OAAO,CAAA;CAAC,EACzC,WAAW,CAAC,EAAE,aAAa,GAC1B,eAAe,CAqDjB"}
@@ -13,8 +13,7 @@ const { TileType } = pmtiles;
13
13
  * @param loadOptions
14
14
  * @returns
15
15
  */
16
- export function parsePMTilesHeader(header, pmmetadata, options, loadOptions) {
17
- const pmtilesMetadata = pmmetadata;
16
+ export function parsePMTilesHeader(header, pmtilesMetadata, options, loadOptions) {
18
17
  // Ironically, to use the TileJSON loader we need to stringify the metadata again.
19
18
  // This is the price of integrating with the existing pmtiles library.
20
19
  // TODO - provide a non-standard TileJSONLoader parsers that accepts a JSON object?
@@ -0,0 +1,2 @@
1
+ export declare const VERSION: any;
2
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/lib/version.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,OAAO,KAA8D,CAAC"}
@@ -0,0 +1,7 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ // Version constant cannot be imported, it needs to correspond to the build version of **this** module.
5
+ // __VERSION__ is injected by babel-plugin-version-inline
6
+ // @ts-ignore TS2304: Cannot find name '__VERSION__'.
7
+ export const VERSION = typeof "4.3.0-alpha.3" !== 'undefined' ? "4.3.0-alpha.3" : 'latest';
@@ -0,0 +1,28 @@
1
+ import type { LoaderOptions, ReadableFile } from '@loaders.gl/loader-utils';
2
+ import { VectorSourceInfo, ImageSourceInfo } from "./source-info.js";
3
+ import { PMTilesTileSourceProps } from "./pmtiles-source.js";
4
+ export type PMTilesLoaderOptions = LoaderOptions & {
5
+ pmtiles?: PMTilesTileSourceProps['pmtiles'];
6
+ };
7
+ /**
8
+ * Loader for PMTiles metadata
9
+ * @note This loader is intended to allow PMTiles to be treated like other file types in top-level loading logic.
10
+ * @note For actual access to the tile data, use the PMTilesSource class.
11
+ */
12
+ export declare const PMTilesLoader: {
13
+ readonly name: "PMTiles";
14
+ readonly id: "pmtiles";
15
+ readonly module: "pmtiles";
16
+ readonly version: any;
17
+ readonly extensions: ["pmtiles"];
18
+ readonly mimeTypes: ["application/octet-stream"];
19
+ readonly tests: ["PMTiles"];
20
+ readonly options: {
21
+ readonly pmtiles: {};
22
+ };
23
+ readonly parse: (arrayBuffer: ArrayBuffer, options?: PMTilesLoaderOptions) => Promise<VectorSourceInfo | ImageSourceInfo>;
24
+ readonly parseFile: typeof parseFileAsPMTiles;
25
+ };
26
+ declare function parseFileAsPMTiles(file: ReadableFile, options?: PMTilesLoaderOptions): Promise<VectorSourceInfo | ImageSourceInfo>;
27
+ export {};
28
+ //# sourceMappingURL=pmtiles-loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pmtiles-loader.d.ts","sourceRoot":"","sources":["../src/pmtiles-loader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAmB,aAAa,EAAE,YAAY,EAAC,MAAM,0BAA0B,CAAC;AAI5F,OAAO,EAAC,gBAAgB,EAAE,eAAe,EAAC,yBAAsB;AAChE,OAAO,EAAoB,sBAAsB,EAAC,4BAAyB;AAE3E,MAAM,MAAM,oBAAoB,GAAG,aAAa,GAAG;IACjD,OAAO,CAAC,EAAE,sBAAsB,CAAC,SAAS,CAAC,CAAC;CAC7C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;kCAWG,WAAW,YAAY,oBAAoB;;CAOvE,CAAC;AAEF,iBAAe,kBAAkB,CAC/B,IAAI,EAAE,YAAY,EAClB,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,gBAAgB,GAAG,eAAe,CAAC,CAqB7C"}
@@ -0,0 +1,47 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ import { BlobFile } from '@loaders.gl/loader-utils';
5
+ import { VERSION } from "./lib/version.js";
6
+ import { PMTilesTileSource } from "./pmtiles-source.js";
7
+ /**
8
+ * Loader for PMTiles metadata
9
+ * @note This loader is intended to allow PMTiles to be treated like other file types in top-level loading logic.
10
+ * @note For actual access to the tile data, use the PMTilesSource class.
11
+ */
12
+ export const PMTilesLoader = {
13
+ name: 'PMTiles',
14
+ id: 'pmtiles',
15
+ module: 'pmtiles',
16
+ version: VERSION,
17
+ extensions: ['pmtiles'],
18
+ mimeTypes: ['application/octet-stream'],
19
+ tests: ['PMTiles'],
20
+ options: {
21
+ pmtiles: {}
22
+ },
23
+ parse: async (arrayBuffer, options) => parseFileAsPMTiles(new BlobFile(new Blob([arrayBuffer])), options),
24
+ parseFile: parseFileAsPMTiles
25
+ };
26
+ async function parseFileAsPMTiles(file, options) {
27
+ const source = new PMTilesTileSource(file.handle, {
28
+ pmtiles: options?.pmtiles || {}
29
+ });
30
+ const formatSpecificMetadata = await source.getMetadata();
31
+ const { tileMIMEType, tilejson = {} } = formatSpecificMetadata;
32
+ const { layers = [] } = tilejson;
33
+ switch (tileMIMEType) {
34
+ case 'application/vnd.mapbox-vector-tile':
35
+ return {
36
+ shape: 'vector-source',
37
+ layers: layers.map((layer) => ({ name: layer.name, schema: layer.schema })),
38
+ tables: [],
39
+ formatSpecificMetadata
40
+ };
41
+ case 'image/png':
42
+ case 'image/jpeg':
43
+ return { shape: 'image-source', formatSpecificMetadata };
44
+ default:
45
+ throw new Error(`PMTilesLoader: Unsupported tile MIME type ${tileMIMEType}`);
46
+ }
47
+ }
@@ -1,43 +1,48 @@
1
1
  import type { Schema } from '@loaders.gl/schema';
2
- import type { GetTileParameters, GetTileDataParameters } from '@loaders.gl/loader-utils';
3
- import type { ImageType, DataSourceProps } from '@loaders.gl/loader-utils';
4
- import type { ImageTileSource, VectorTileSource } from '@loaders.gl/loader-utils';
5
- import { DataSource } from '@loaders.gl/loader-utils';
2
+ import type { VectorTileSource, GetTileParameters, GetTileDataParameters } from '@loaders.gl/loader-utils';
3
+ import type { ImageTileSource, ImageType } from '@loaders.gl/loader-utils';
4
+ import { DataSource, DataSourceProps } from '@loaders.gl/loader-utils';
6
5
  import { ImageLoaderOptions } from '@loaders.gl/images';
7
6
  import { MVTLoaderOptions, TileJSONLoaderOptions } from '@loaders.gl/mvt';
8
7
  import * as pmtiles from 'pmtiles';
9
8
  import type { PMTilesMetadata } from "./lib/parse-pmtiles.js";
10
- export type Service = {
11
- name: string;
12
- id: string;
13
- module: string;
14
- version: string;
15
- extensions: string[];
16
- mimeTypes: string[];
17
- options: Record<string, unknown>;
18
- };
19
- export type ServiceWithSource<SourceT, SourcePropsT> = Service & {
20
- _source?: SourceT;
21
- _sourceProps?: SourcePropsT;
22
- createSource: (props: SourcePropsT) => SourceT;
9
+ /**
10
+ * Creates vector tile data sources for PMTiles urls or blobs
11
+ */
12
+ export declare const PMTilesSource: {
13
+ readonly name: "PMTiles";
14
+ readonly id: "pmtiles";
15
+ readonly module: "pmtiles";
16
+ readonly version: "1.0.0";
17
+ readonly extensions: ["pmtiles"];
18
+ readonly mimeTypes: ["application/octet-stream"];
19
+ readonly options: {
20
+ readonly url: never;
21
+ readonly pmtiles: {};
22
+ };
23
+ readonly type: "pmtiles";
24
+ readonly fromUrl: true;
25
+ readonly fromBlob: true;
26
+ readonly testURL: (url: string) => boolean;
27
+ readonly createDataSource: (url: string | Blob, props: PMTilesTileSourceProps) => PMTilesTileSource;
23
28
  };
24
- export declare const PMTilesService: ServiceWithSource<PMTilesSource, PMTilesSourceProps>;
25
- export type PMTilesSourceProps = DataSourceProps & {
26
- url: string | Blob;
29
+ export type PMTilesTileSourceProps = DataSourceProps & {
27
30
  attributions?: string[];
28
- loadOptions?: TileJSONLoaderOptions & MVTLoaderOptions & ImageLoaderOptions;
31
+ pmtiles?: {
32
+ loadOptions?: TileJSONLoaderOptions & MVTLoaderOptions & ImageLoaderOptions;
33
+ };
29
34
  };
30
35
  /**
31
36
  * A PMTiles data source
32
37
  * @note Can be either a raster or vector tile source depending on the contents of the PMTiles file.
33
38
  */
34
- export declare class PMTilesSource extends DataSource implements ImageTileSource, VectorTileSource {
39
+ export declare class PMTilesTileSource extends DataSource implements ImageTileSource, VectorTileSource {
35
40
  data: string | Blob;
36
- props: PMTilesSourceProps;
41
+ props: PMTilesTileSourceProps;
37
42
  mimeType: string | null;
38
43
  pmtiles: pmtiles.PMTiles;
39
44
  metadata: Promise<PMTilesMetadata>;
40
- constructor(props: PMTilesSourceProps);
45
+ constructor(data: string | Blob, props: PMTilesTileSourceProps);
41
46
  getSchema(): Promise<Schema>;
42
47
  getMetadata(): Promise<PMTilesMetadata>;
43
48
  getTile(tileParams: GetTileParameters): Promise<ArrayBuffer | null>;
@@ -1 +1 @@
1
- {"version":3,"file":"pmtiles-source.d.ts","sourceRoot":"","sources":["../src/pmtiles-source.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,oBAAoB,CAAC;AAC/C,OAAO,KAAK,EAAC,iBAAiB,EAAE,qBAAqB,EAAC,MAAM,0BAA0B,CAAC;AACvF,OAAO,KAAK,EAAC,SAAS,EAAE,eAAe,EAAC,MAAM,0BAA0B,CAAC;AACzE,OAAO,KAAK,EAA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ACG,MAAM,GAAG,IAAI,SAAS,sBAAsB;CAEA,CAAC;AAEvE,MAAM,MAAM,sBAAsB,GAAG,eAAe,GAAG;IACrD,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,OAAO,CAAC,EAAE;QACR,WAAW,CAAC,EAAE,qBAAqB,GAAG,gBAAgB,GAAG,kBAAkB,CAAC;KAE7E,CAAC;CACH,CAAC;AAEF;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,UAAW,YAAW,eAAe,EAAE,gBAAgB;IAC5F,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,KAAK,EAAE,sBAAsB,CAAC;IAC9B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAQ;IAC/B,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC;IACzB,QAAQ,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;gBAEvB,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,sBAAsB;IAUxD,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;IAI5B,WAAW,IAAI,OAAO,CAAC,eAAe,CAAC;IAoBvC,OAAO,CAAC,UAAU,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAcnE,WAAW,CAAC,UAAU,EAAE,qBAAqB,GAAG,OAAO,CAAC,GAAG,CAAC;IAa5D,YAAY,CAAC,UAAU,EAAE,iBAAiB,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;IAOtE,aAAa,CAAC,UAAU,EAAE,iBAAiB,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;CAc5E"}
@@ -9,33 +9,38 @@ const { PMTiles } = pmtiles;
9
9
  import { parsePMTilesHeader } from "./lib/parse-pmtiles.js";
10
10
  import { BlobSource } from "./lib/blob-source.js";
11
11
  const VERSION = '1.0.0';
12
- export const PMTilesService = {
12
+ /**
13
+ * Creates vector tile data sources for PMTiles urls or blobs
14
+ */
15
+ export const PMTilesSource = {
13
16
  name: 'PMTiles',
14
17
  id: 'pmtiles',
15
18
  module: 'pmtiles',
16
19
  version: VERSION,
17
20
  extensions: ['pmtiles'],
18
21
  mimeTypes: ['application/octet-stream'],
19
- options: {
20
- pmtiles: {}
21
- },
22
- createSource: (props) => new PMTilesSource(props)
22
+ options: { url: undefined, pmtiles: {} },
23
+ type: 'pmtiles',
24
+ fromUrl: true,
25
+ fromBlob: true,
26
+ testURL: (url) => url.endsWith('.pmtiles'),
27
+ createDataSource: (url, props) => new PMTilesTileSource(url, props)
23
28
  };
24
29
  /**
25
30
  * A PMTiles data source
26
31
  * @note Can be either a raster or vector tile source depending on the contents of the PMTiles file.
27
32
  */
28
- export class PMTilesSource extends DataSource {
33
+ export class PMTilesTileSource extends DataSource {
29
34
  data;
30
35
  props;
31
36
  mimeType = null;
32
37
  pmtiles;
33
38
  metadata;
34
- constructor(props) {
39
+ constructor(data, props) {
35
40
  super(props);
36
41
  this.props = props;
37
- const url = typeof props.url === 'string' ? resolvePath(props.url) : new BlobSource(props.url, 'pmtiles');
38
- this.data = props.url;
42
+ const url = typeof data === 'string' ? resolvePath(data) : new BlobSource(data, 'pmtiles');
43
+ this.data = data;
39
44
  this.pmtiles = new PMTiles(url);
40
45
  this.getTileData = this.getTileData.bind(this);
41
46
  this.metadata = this.getMetadata();
@@ -45,7 +50,7 @@ export class PMTilesSource extends DataSource {
45
50
  }
46
51
  async getMetadata() {
47
52
  const pmtilesHeader = await this.pmtiles.getHeader();
48
- const pmtilesMetadata = await this.pmtiles.getMetadata();
53
+ const pmtilesMetadata = (await this.pmtiles.getMetadata()) || {};
49
54
  const metadata = parsePMTilesHeader(pmtilesHeader, pmtilesMetadata, { includeFormatHeader: false }, this.loadOptions);
50
55
  // Add additional attribution if necessary
51
56
  if (this.props.attributions) {
@@ -0,0 +1,25 @@
1
+ import { Schema } from '@loaders.gl/schema';
2
+ export type SourceInfo = VectorSourceInfo | ImageSourceInfo;
3
+ /** Information about a vector source */
4
+ export type VectorSourceInfo = {
5
+ shape: 'vector-source';
6
+ /** List of geospatial tables */
7
+ layers: {
8
+ name: string;
9
+ schema: Schema;
10
+ }[];
11
+ /** List of nongeospatial tables */
12
+ tables: {
13
+ name: string;
14
+ schema: Schema;
15
+ }[];
16
+ /** Format specific metadata */
17
+ formatSpecificMetadata?: Record<string, any>;
18
+ };
19
+ /** Information about an image source */
20
+ export type ImageSourceInfo = {
21
+ shape: 'image-source';
22
+ /** Format specific metadata */
23
+ formatSpecificMetadata?: Record<string, any>;
24
+ };
25
+ //# sourceMappingURL=source-info.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source-info.d.ts","sourceRoot":"","sources":["../src/source-info.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,MAAM,EAAC,MAAM,oBAAoB,CAAC;AAE1C,MAAM,MAAM,UAAU,GAAG,gBAAgB,GAAG,eAAe,CAAC;AAE5D,wCAAwC;AACxC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,eAAe,CAAC;IACvB,gCAAgC;IAChC,MAAM,EAAE;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAC,EAAE,CAAC;IACzC,mCAAmC;IACnC,MAAM,EAAE;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAC,EAAE,CAAC;IACzC,+BAA+B;IAC/B,sBAAsB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC9C,CAAC;AAEF,wCAAwC;AACxC,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,EAAE,cAAc,CAAC;IACtB,+BAA+B;IAC/B,sBAAsB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC9C,CAAC"}
@@ -0,0 +1,4 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/pmtiles",
3
- "version": "4.3.0-alpha.2",
3
+ "version": "4.3.0-alpha.4",
4
4
  "description": "Framework-independent loader for the pmtiles format",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -46,14 +46,14 @@
46
46
  "build-bundle-dev": "ocular-bundle ./bundle.ts --env=dev --output=dist/dist.dev.js"
47
47
  },
48
48
  "dependencies": {
49
- "@loaders.gl/images": "4.3.0-alpha.2",
50
- "@loaders.gl/loader-utils": "4.3.0-alpha.2",
51
- "@loaders.gl/mvt": "4.3.0-alpha.2",
52
- "@loaders.gl/schema": "4.3.0-alpha.2",
49
+ "@loaders.gl/images": "4.3.0-alpha.4",
50
+ "@loaders.gl/loader-utils": "4.3.0-alpha.4",
51
+ "@loaders.gl/mvt": "4.3.0-alpha.4",
52
+ "@loaders.gl/schema": "4.3.0-alpha.4",
53
53
  "pmtiles": "^3.0.4"
54
54
  },
55
55
  "peerDependencies": {
56
56
  "@loaders.gl/core": "^4.0.0"
57
57
  },
58
- "gitHead": "77a3cb538ab7a1fbf74245f25590210451689f5c"
58
+ "gitHead": "4900ac4c4de20366c050b80cef04dc5b52d167af"
59
59
  }
package/src/index.ts CHANGED
@@ -2,6 +2,11 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- export type {PMTilesMetadata} from './lib/parse-pmtiles';
6
- export type {PMTilesSourceProps} from './pmtiles-source';
7
5
  export {PMTilesSource} from './pmtiles-source';
6
+
7
+ export type {PMTilesMetadata} from './lib/parse-pmtiles';
8
+ export type {PMTilesTileSourceProps} from './pmtiles-source';
9
+ export {PMTilesTileSource} from './pmtiles-source';
10
+
11
+ export {PMTilesLoader as _PMTilesLoader} from './pmtiles-loader';
12
+ export type {PMTilesLoaderOptions} from './pmtiles-loader';
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import type {LoaderOptions} from '@loaders.gl/loader-utils';
5
+ import {LoaderOptions} from '@loaders.gl/loader-utils';
6
6
  import type {TileJSON} from '@loaders.gl/mvt';
7
7
  import {TileJSONLoader} from '@loaders.gl/mvt';
8
8
  // import {Source, PMTiles, Header, TileType} from 'pmtiles';
@@ -61,12 +61,10 @@ export type PMTilesMetadata = {
61
61
  */
62
62
  export function parsePMTilesHeader(
63
63
  header: pmtiles.Header,
64
- pmmetadata: unknown,
64
+ pmtilesMetadata: Record<string, unknown> | null,
65
65
  options?: {includeFormatHeader?: boolean},
66
66
  loadOptions?: LoaderOptions
67
67
  ): PMTilesMetadata {
68
- const pmtilesMetadata = pmmetadata as Record<string, unknown> | null;
69
-
70
68
  // Ironically, to use the TileJSON loader we need to stringify the metadata again.
71
69
  // This is the price of integrating with the existing pmtiles library.
72
70
  // TODO - provide a non-standard TileJSONLoader parsers that accepts a JSON object?
@@ -0,0 +1,8 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ // Version constant cannot be imported, it needs to correspond to the build version of **this** module.
6
+ // __VERSION__ is injected by babel-plugin-version-inline
7
+ // @ts-ignore TS2304: Cannot find name '__VERSION__'.
8
+ export const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
@@ -0,0 +1,65 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {LoaderWithParser, LoaderOptions, ReadableFile} from '@loaders.gl/loader-utils';
6
+ import {BlobFile} from '@loaders.gl/loader-utils';
7
+ import {VERSION} from './lib/version';
8
+
9
+ import {VectorSourceInfo, ImageSourceInfo} from './source-info';
10
+ import {PMTilesTileSource, PMTilesTileSourceProps} from './pmtiles-source';
11
+
12
+ export type PMTilesLoaderOptions = LoaderOptions & {
13
+ pmtiles?: PMTilesTileSourceProps['pmtiles'];
14
+ };
15
+
16
+ /**
17
+ * Loader for PMTiles metadata
18
+ * @note This loader is intended to allow PMTiles to be treated like other file types in top-level loading logic.
19
+ * @note For actual access to the tile data, use the PMTilesSource class.
20
+ */
21
+ export const PMTilesLoader = {
22
+ name: 'PMTiles',
23
+ id: 'pmtiles',
24
+ module: 'pmtiles',
25
+ version: VERSION,
26
+ extensions: ['pmtiles'],
27
+ mimeTypes: ['application/octet-stream'],
28
+ tests: ['PMTiles'],
29
+ options: {
30
+ pmtiles: {}
31
+ },
32
+ parse: async (arrayBuffer: ArrayBuffer, options?: PMTilesLoaderOptions) =>
33
+ parseFileAsPMTiles(new BlobFile(new Blob([arrayBuffer])), options),
34
+ parseFile: parseFileAsPMTiles
35
+ } as const satisfies LoaderWithParser<
36
+ VectorSourceInfo | ImageSourceInfo,
37
+ never,
38
+ PMTilesLoaderOptions
39
+ >;
40
+
41
+ async function parseFileAsPMTiles(
42
+ file: ReadableFile,
43
+ options?: PMTilesLoaderOptions
44
+ ): Promise<VectorSourceInfo | ImageSourceInfo> {
45
+ const source = new PMTilesTileSource(file.handle as string | Blob, {
46
+ pmtiles: options?.pmtiles || {}
47
+ });
48
+ const formatSpecificMetadata = await source.getMetadata();
49
+ const {tileMIMEType, tilejson = {}} = formatSpecificMetadata;
50
+ const {layers = []} = tilejson;
51
+ switch (tileMIMEType) {
52
+ case 'application/vnd.mapbox-vector-tile':
53
+ return {
54
+ shape: 'vector-source',
55
+ layers: layers.map((layer) => ({name: layer.name, schema: layer.schema})),
56
+ tables: [],
57
+ formatSpecificMetadata
58
+ } as VectorSourceInfo;
59
+ case 'image/png':
60
+ case 'image/jpeg':
61
+ return {shape: 'image-source', formatSpecificMetadata} as ImageSourceInfo;
62
+ default:
63
+ throw new Error(`PMTilesLoader: Unsupported tile MIME type ${tileMIMEType}`);
64
+ }
65
+ }
@@ -3,10 +3,14 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  import type {Schema} from '@loaders.gl/schema';
6
- import type {GetTileParameters, GetTileDataParameters} from '@loaders.gl/loader-utils';
7
- import type {ImageType, DataSourceProps} from '@loaders.gl/loader-utils';
8
- import type {ImageTileSource, VectorTileSource} from '@loaders.gl/loader-utils';
9
- import {DataSource, resolvePath} from '@loaders.gl/loader-utils';
6
+ import type {Source} from '@loaders.gl/loader-utils';
7
+ import type {
8
+ VectorTileSource,
9
+ GetTileParameters,
10
+ GetTileDataParameters
11
+ } from '@loaders.gl/loader-utils';
12
+ import type {ImageTileSource, ImageType} from '@loaders.gl/loader-utils';
13
+ import {DataSource, DataSourceProps, resolvePath} from '@loaders.gl/loader-utils';
10
14
  import {ImageLoader, ImageLoaderOptions} from '@loaders.gl/images';
11
15
  import {MVTLoader, MVTLoaderOptions, TileJSONLoaderOptions} from '@loaders.gl/mvt';
12
16
 
@@ -19,58 +23,50 @@ import {BlobSource} from './lib/blob-source';
19
23
 
20
24
  const VERSION = '1.0.0';
21
25
 
22
- export type Service = {
23
- name: string;
24
- id: string;
25
- module: string;
26
- version: string;
27
- extensions: string[];
28
- mimeTypes: string[];
29
- options: Record<string, unknown>;
30
- };
31
-
32
- export type ServiceWithSource<SourceT, SourcePropsT> = Service & {
33
- _source?: SourceT;
34
- _sourceProps?: SourcePropsT;
35
- createSource: (props: SourcePropsT) => SourceT;
36
- };
37
-
38
- export const PMTilesService: ServiceWithSource<PMTilesSource, PMTilesSourceProps> = {
26
+ /**
27
+ * Creates vector tile data sources for PMTiles urls or blobs
28
+ */
29
+ export const PMTilesSource = {
39
30
  name: 'PMTiles',
40
31
  id: 'pmtiles',
41
32
  module: 'pmtiles',
42
33
  version: VERSION,
43
34
  extensions: ['pmtiles'],
44
35
  mimeTypes: ['application/octet-stream'],
45
- options: {
46
- pmtiles: {}
47
- },
48
- createSource: (props: PMTilesSourceProps) => new PMTilesSource(props)
49
- };
36
+ options: {url: undefined!, pmtiles: {}},
37
+ type: 'pmtiles',
38
+ fromUrl: true,
39
+ fromBlob: true,
40
+
41
+ testURL: (url: string) => url.endsWith('.pmtiles'),
42
+ createDataSource: (url: string | Blob, props: PMTilesTileSourceProps) =>
43
+ new PMTilesTileSource(url, props)
44
+ } as const satisfies Source<PMTilesTileSource, PMTilesTileSourceProps>;
50
45
 
51
- export type PMTilesSourceProps = DataSourceProps & {
52
- url: string | Blob;
46
+ export type PMTilesTileSourceProps = DataSourceProps & {
53
47
  attributions?: string[];
54
- loadOptions?: TileJSONLoaderOptions & MVTLoaderOptions & ImageLoaderOptions;
48
+ pmtiles?: {
49
+ loadOptions?: TileJSONLoaderOptions & MVTLoaderOptions & ImageLoaderOptions;
50
+ // TODO - add options here
51
+ };
55
52
  };
56
53
 
57
54
  /**
58
55
  * A PMTiles data source
59
56
  * @note Can be either a raster or vector tile source depending on the contents of the PMTiles file.
60
57
  */
61
- export class PMTilesSource extends DataSource implements ImageTileSource, VectorTileSource {
58
+ export class PMTilesTileSource extends DataSource implements ImageTileSource, VectorTileSource {
62
59
  data: string | Blob;
63
- props: PMTilesSourceProps;
60
+ props: PMTilesTileSourceProps;
64
61
  mimeType: string | null = null;
65
62
  pmtiles: pmtiles.PMTiles;
66
63
  metadata: Promise<PMTilesMetadata>;
67
64
 
68
- constructor(props: PMTilesSourceProps) {
65
+ constructor(data: string | Blob, props: PMTilesTileSourceProps) {
69
66
  super(props);
70
67
  this.props = props;
71
- const url =
72
- typeof props.url === 'string' ? resolvePath(props.url) : new BlobSource(props.url, 'pmtiles');
73
- this.data = props.url;
68
+ const url = typeof data === 'string' ? resolvePath(data) : new BlobSource(data, 'pmtiles');
69
+ this.data = data;
74
70
  this.pmtiles = new PMTiles(url);
75
71
  this.getTileData = this.getTileData.bind(this);
76
72
  this.metadata = this.getMetadata();
@@ -82,7 +78,7 @@ export class PMTilesSource extends DataSource implements ImageTileSource, Vector
82
78
 
83
79
  async getMetadata(): Promise<PMTilesMetadata> {
84
80
  const pmtilesHeader = await this.pmtiles.getHeader();
85
- const pmtilesMetadata = await this.pmtiles.getMetadata();
81
+ const pmtilesMetadata = ((await this.pmtiles.getMetadata()) as Record<string, unknown>) || {};
86
82
  const metadata: PMTilesMetadata = parsePMTilesHeader(
87
83
  pmtilesHeader,
88
84
  pmtilesMetadata,
@@ -0,0 +1,25 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import {Schema} from '@loaders.gl/schema';
6
+
7
+ export type SourceInfo = VectorSourceInfo | ImageSourceInfo;
8
+
9
+ /** Information about a vector source */
10
+ export type VectorSourceInfo = {
11
+ shape: 'vector-source';
12
+ /** List of geospatial tables */
13
+ layers: {name: string; schema: Schema}[];
14
+ /** List of nongeospatial tables */
15
+ tables: {name: string; schema: Schema}[];
16
+ /** Format specific metadata */
17
+ formatSpecificMetadata?: Record<string, any>;
18
+ };
19
+
20
+ /** Information about an image source */
21
+ export type ImageSourceInfo = {
22
+ shape: 'image-source';
23
+ /** Format specific metadata */
24
+ formatSpecificMetadata?: Record<string, any>;
25
+ };