@loaders.gl/pmtiles 4.3.0-alpha.1 → 4.3.0-alpha.3

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,45 +1,53 @@
1
- import type { TileLoadParameters, GetTileParameters } from '@loaders.gl/loader-utils';
2
- import type { ImageType, DataSourceProps } from '@loaders.gl/loader-utils';
3
- import type { ImageTileSource, VectorTileSource } from '@loaders.gl/loader-utils';
4
- import { DataSource } from '@loaders.gl/loader-utils';
1
+ import type { Schema } from '@loaders.gl/schema';
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';
5
5
  import { ImageLoaderOptions } from '@loaders.gl/images';
6
6
  import { MVTLoaderOptions, TileJSONLoaderOptions } from '@loaders.gl/mvt';
7
7
  import * as pmtiles from 'pmtiles';
8
8
  import type { PMTilesMetadata } from "./lib/parse-pmtiles.js";
9
- export type Service = {
10
- name: string;
11
- id: string;
12
- module: string;
13
- version: string;
14
- extensions: string[];
15
- mimeTypes: string[];
16
- options: Record<string, unknown>;
17
- };
18
- export type ServiceWithSource<SourceT, SourcePropsT> = Service & {
19
- _source?: SourceT;
20
- _sourceProps?: SourcePropsT;
21
- 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;
22
28
  };
23
- export declare const PMTilesService: ServiceWithSource<PMTilesSource, PMTilesSourceProps>;
24
- export type PMTilesSourceProps = DataSourceProps & {
29
+ export type PMTilesTileSourceProps = DataSourceProps & {
25
30
  url: string | Blob;
26
31
  attributions?: string[];
27
- loadOptions?: TileJSONLoaderOptions & MVTLoaderOptions & ImageLoaderOptions;
32
+ pmtiles?: {
33
+ loadOptions?: TileJSONLoaderOptions & MVTLoaderOptions & ImageLoaderOptions;
34
+ };
28
35
  };
29
36
  /**
30
37
  * A PMTiles data source
31
38
  * @note Can be either a raster or vector tile source depending on the contents of the PMTiles file.
32
39
  */
33
- export declare class PMTilesSource extends DataSource implements ImageTileSource, VectorTileSource {
40
+ export declare class PMTilesTileSource extends DataSource implements ImageTileSource, VectorTileSource {
34
41
  data: string | Blob;
35
- props: PMTilesSourceProps;
42
+ props: PMTilesTileSourceProps;
36
43
  mimeType: string | null;
37
44
  pmtiles: pmtiles.PMTiles;
38
45
  metadata: Promise<PMTilesMetadata>;
39
- constructor(props: PMTilesSourceProps);
46
+ constructor(data: string | Blob, props: PMTilesTileSourceProps);
47
+ getSchema(): Promise<Schema>;
40
48
  getMetadata(): Promise<PMTilesMetadata>;
41
49
  getTile(tileParams: GetTileParameters): Promise<ArrayBuffer | null>;
42
- getTileData(tileParams: TileLoadParameters): Promise<unknown | null>;
50
+ getTileData(tileParams: GetTileDataParameters): Promise<any>;
43
51
  getImageTile(tileParams: GetTileParameters): Promise<ImageType | null>;
44
52
  getVectorTile(tileParams: GetTileParameters): Promise<unknown | null>;
45
53
  }
@@ -1 +1 @@
1
- {"version":3,"file":"pmtiles-source.d.ts","sourceRoot":"","sources":["../src/pmtiles-source.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,kBAAkB,EAAE,iBAAiB,EAAC,MAAM,0BAA0B,CAAC;AACpF,OAAO,KAAK,EAAC,SAAS,EAAE,eAAe,EAA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YT,MAAM;qCACG,MAAM,GAAG,IAAI,SAAS,sBAAsB;CAEA,CAAC;AAEvE,MAAM,MAAM,sBAAsB,GAAG,eAAe,GAAG;IACrD,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,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,37 +9,45 @@ 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');
42
+ const url = typeof data === 'string' ? resolvePath(data) : new BlobSource(data, 'pmtiles');
38
43
  this.data = props.url;
39
44
  this.pmtiles = new PMTiles(url);
40
45
  this.getTileData = this.getTileData.bind(this);
41
46
  this.metadata = this.getMetadata();
42
47
  }
48
+ async getSchema() {
49
+ return { fields: [], metadata: {} };
50
+ }
43
51
  async getMetadata() {
44
52
  const pmtilesHeader = await this.pmtiles.getHeader();
45
53
  const pmtilesMetadata = await this.pmtiles.getMetadata();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/pmtiles",
3
- "version": "4.3.0-alpha.1",
3
+ "version": "4.3.0-alpha.3",
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.1",
50
- "@loaders.gl/loader-utils": "4.3.0-alpha.1",
51
- "@loaders.gl/mvt": "4.3.0-alpha.1",
52
- "@loaders.gl/schema": "4.3.0-alpha.1",
49
+ "@loaders.gl/images": "4.3.0-alpha.3",
50
+ "@loaders.gl/loader-utils": "4.3.0-alpha.3",
51
+ "@loaders.gl/mvt": "4.3.0-alpha.3",
52
+ "@loaders.gl/schema": "4.3.0-alpha.3",
53
53
  "pmtiles": "^3.0.4"
54
54
  },
55
55
  "peerDependencies": {
56
56
  "@loaders.gl/core": "^4.0.0"
57
57
  },
58
- "gitHead": "568446ea69eb590f0c42d965459b636216cda74e"
58
+ "gitHead": "3213679d79e6ff2814d48fd3337acfa446c74099"
59
59
  }
package/src/index.ts CHANGED
@@ -2,6 +2,8 @@
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';
@@ -2,10 +2,15 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import type {TileLoadParameters, GetTileParameters} from '@loaders.gl/loader-utils';
6
- import type {ImageType, DataSourceProps} from '@loaders.gl/loader-utils';
7
- import type {ImageTileSource, VectorTileSource} from '@loaders.gl/loader-utils';
8
- import {DataSource, resolvePath} from '@loaders.gl/loader-utils';
5
+ import type {Schema} from '@loaders.gl/schema';
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';
9
14
  import {ImageLoader, ImageLoaderOptions} from '@loaders.gl/images';
10
15
  import {MVTLoader, MVTLoaderOptions, TileJSONLoaderOptions} from '@loaders.gl/mvt';
11
16
 
@@ -18,63 +23,60 @@ import {BlobSource} from './lib/blob-source';
18
23
 
19
24
  const VERSION = '1.0.0';
20
25
 
21
- export type Service = {
22
- name: string;
23
- id: string;
24
- module: string;
25
- version: string;
26
- extensions: string[];
27
- mimeTypes: string[];
28
- options: Record<string, unknown>;
29
- };
30
-
31
- export type ServiceWithSource<SourceT, SourcePropsT> = Service & {
32
- _source?: SourceT;
33
- _sourceProps?: SourcePropsT;
34
- createSource: (props: SourcePropsT) => SourceT;
35
- };
36
-
37
- export const PMTilesService: ServiceWithSource<PMTilesSource, PMTilesSourceProps> = {
26
+ /**
27
+ * Creates vector tile data sources for PMTiles urls or blobs
28
+ */
29
+ export const PMTilesSource = {
38
30
  name: 'PMTiles',
39
31
  id: 'pmtiles',
40
32
  module: 'pmtiles',
41
33
  version: VERSION,
42
34
  extensions: ['pmtiles'],
43
35
  mimeTypes: ['application/octet-stream'],
44
- options: {
45
- pmtiles: {}
46
- },
47
- createSource: (props: PMTilesSourceProps) => new PMTilesSource(props)
48
- };
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>;
49
45
 
50
- export type PMTilesSourceProps = DataSourceProps & {
46
+ export type PMTilesTileSourceProps = DataSourceProps & {
51
47
  url: string | Blob;
52
48
  attributions?: string[];
53
- loadOptions?: TileJSONLoaderOptions & MVTLoaderOptions & ImageLoaderOptions;
49
+ pmtiles?: {
50
+ loadOptions?: TileJSONLoaderOptions & MVTLoaderOptions & ImageLoaderOptions;
51
+ // TODO - add options here
52
+ };
54
53
  };
55
54
 
56
55
  /**
57
56
  * A PMTiles data source
58
57
  * @note Can be either a raster or vector tile source depending on the contents of the PMTiles file.
59
58
  */
60
- export class PMTilesSource extends DataSource implements ImageTileSource, VectorTileSource {
59
+ export class PMTilesTileSource extends DataSource implements ImageTileSource, VectorTileSource {
61
60
  data: string | Blob;
62
- props: PMTilesSourceProps;
61
+ props: PMTilesTileSourceProps;
63
62
  mimeType: string | null = null;
64
63
  pmtiles: pmtiles.PMTiles;
65
64
  metadata: Promise<PMTilesMetadata>;
66
65
 
67
- constructor(props: PMTilesSourceProps) {
66
+ constructor(data: string | Blob, props: PMTilesTileSourceProps) {
68
67
  super(props);
69
68
  this.props = props;
70
- const url =
71
- typeof props.url === 'string' ? resolvePath(props.url) : new BlobSource(props.url, 'pmtiles');
69
+ const url = typeof data === 'string' ? resolvePath(data) : new BlobSource(data, 'pmtiles');
72
70
  this.data = props.url;
73
71
  this.pmtiles = new PMTiles(url);
74
72
  this.getTileData = this.getTileData.bind(this);
75
73
  this.metadata = this.getMetadata();
76
74
  }
77
75
 
76
+ async getSchema(): Promise<Schema> {
77
+ return {fields: [], metadata: {}};
78
+ }
79
+
78
80
  async getMetadata(): Promise<PMTilesMetadata> {
79
81
  const pmtilesHeader = await this.pmtiles.getHeader();
80
82
  const pmtilesMetadata = await this.pmtiles.getMetadata();
@@ -109,7 +111,7 @@ export class PMTilesSource extends DataSource implements ImageTileSource, Vector
109
111
  // Tile Source interface implementation: deck.gl compatible API
110
112
  // TODO - currently only handles image tiles, not vector tiles
111
113
 
112
- async getTileData(tileParams: TileLoadParameters): Promise<unknown | null> {
114
+ async getTileData(tileParams: GetTileDataParameters): Promise<any> {
113
115
  const {x, y, z} = tileParams.index;
114
116
  const metadata = await this.metadata;
115
117
  switch (metadata.tileMIMEType) {