@loaders.gl/pmtiles 4.3.2 → 4.4.0-alpha.1
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.
- package/dist/dist.dev.js +95 -47
- package/dist/dist.min.js +1 -1
- package/dist/index.cjs +29 -24
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/lib/version.js +1 -1
- package/dist/pmtiles-format.d.ts +12 -0
- package/dist/pmtiles-format.d.ts.map +1 -0
- package/dist/pmtiles-format.js +14 -0
- package/dist/pmtiles-loader.d.ts +8 -8
- package/dist/pmtiles-loader.d.ts.map +1 -1
- package/dist/pmtiles-loader.js +2 -6
- package/dist/pmtiles-source.d.ts +19 -21
- package/dist/pmtiles-source.d.ts.map +1 -1
- package/dist/pmtiles-source.js +15 -17
- package/package.json +7 -7
- package/src/index.ts +1 -1
- package/src/pmtiles-format.ts +17 -0
- package/src/pmtiles-loader.ts +4 -8
- package/src/pmtiles-source.ts +31 -29
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PMTiles
|
|
3
|
+
*/
|
|
4
|
+
export declare const PMTilesFormat: {
|
|
5
|
+
readonly name: "PMTiles";
|
|
6
|
+
readonly id: "pmtiles";
|
|
7
|
+
readonly module: "pmtiles";
|
|
8
|
+
readonly extensions: ["pmtiles"];
|
|
9
|
+
readonly mimeTypes: ["application/octet-stream"];
|
|
10
|
+
readonly tests: ["PMTiles"];
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=pmtiles-format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pmtiles-format.d.ts","sourceRoot":"","sources":["../src/pmtiles-format.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,eAAO,MAAM,aAAa;;;;;;;CAOC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
/**
|
|
5
|
+
* PMTiles
|
|
6
|
+
*/
|
|
7
|
+
export const PMTilesFormat = {
|
|
8
|
+
name: 'PMTiles',
|
|
9
|
+
id: 'pmtiles',
|
|
10
|
+
module: 'pmtiles',
|
|
11
|
+
extensions: ['pmtiles'],
|
|
12
|
+
mimeTypes: ['application/octet-stream'],
|
|
13
|
+
tests: ['PMTiles']
|
|
14
|
+
};
|
package/dist/pmtiles-loader.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { LoaderOptions, ReadableFile } from '@loaders.gl/loader-utils';
|
|
2
2
|
import { VectorSourceInfo, ImageSourceInfo } from "./source-info.js";
|
|
3
|
-
import {
|
|
3
|
+
import { PMTilesSourceOptions } from "./pmtiles-source.js";
|
|
4
4
|
export type PMTilesLoaderOptions = LoaderOptions & {
|
|
5
|
-
pmtiles?:
|
|
5
|
+
pmtiles?: PMTilesSourceOptions['pmtiles'];
|
|
6
6
|
};
|
|
7
7
|
/**
|
|
8
8
|
* Loader for PMTiles metadata
|
|
@@ -10,18 +10,18 @@ export type PMTilesLoaderOptions = LoaderOptions & {
|
|
|
10
10
|
* @note For actual access to the tile data, use the PMTilesSource class.
|
|
11
11
|
*/
|
|
12
12
|
export declare const PMTilesLoader: {
|
|
13
|
-
readonly name: "PMTiles";
|
|
14
|
-
readonly id: "pmtiles";
|
|
15
|
-
readonly module: "pmtiles";
|
|
16
13
|
readonly version: any;
|
|
17
|
-
readonly extensions: ["pmtiles"];
|
|
18
|
-
readonly mimeTypes: ["application/octet-stream"];
|
|
19
|
-
readonly tests: ["PMTiles"];
|
|
20
14
|
readonly options: {
|
|
21
15
|
readonly pmtiles: {};
|
|
22
16
|
};
|
|
23
17
|
readonly parse: (arrayBuffer: ArrayBuffer, options?: PMTilesLoaderOptions) => Promise<VectorSourceInfo | ImageSourceInfo>;
|
|
24
18
|
readonly parseFile: typeof parseFileAsPMTiles;
|
|
19
|
+
readonly name: "PMTiles";
|
|
20
|
+
readonly id: "pmtiles";
|
|
21
|
+
readonly module: "pmtiles";
|
|
22
|
+
readonly extensions: ["pmtiles"];
|
|
23
|
+
readonly mimeTypes: ["application/octet-stream"];
|
|
24
|
+
readonly tests: ["PMTiles"];
|
|
25
25
|
};
|
|
26
26
|
declare function parseFileAsPMTiles(file: ReadableFile, options?: PMTilesLoaderOptions): Promise<VectorSourceInfo | ImageSourceInfo>;
|
|
27
27
|
export {};
|
|
@@ -1 +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,
|
|
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,oBAAoB,EAAC,4BAAyB;AAGzE,MAAM,MAAM,oBAAoB,GAAG,aAAa,GAAG;IACjD,OAAO,CAAC,EAAE,oBAAoB,CAAC,SAAS,CAAC,CAAC;CAC3C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,aAAa;;;;;kCAMG,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"}
|
package/dist/pmtiles-loader.js
CHANGED
|
@@ -4,19 +4,15 @@
|
|
|
4
4
|
import { BlobFile } from '@loaders.gl/loader-utils';
|
|
5
5
|
import { VERSION } from "./lib/version.js";
|
|
6
6
|
import { PMTilesTileSource } from "./pmtiles-source.js";
|
|
7
|
+
import { PMTilesFormat } from "./pmtiles-format.js";
|
|
7
8
|
/**
|
|
8
9
|
* Loader for PMTiles metadata
|
|
9
10
|
* @note This loader is intended to allow PMTiles to be treated like other file types in top-level loading logic.
|
|
10
11
|
* @note For actual access to the tile data, use the PMTilesSource class.
|
|
11
12
|
*/
|
|
12
13
|
export const PMTilesLoader = {
|
|
13
|
-
|
|
14
|
-
id: 'pmtiles',
|
|
15
|
-
module: 'pmtiles',
|
|
14
|
+
...PMTilesFormat,
|
|
16
15
|
version: VERSION,
|
|
17
|
-
extensions: ['pmtiles'],
|
|
18
|
-
mimeTypes: ['application/octet-stream'],
|
|
19
|
-
tests: ['PMTiles'],
|
|
20
16
|
options: {
|
|
21
17
|
pmtiles: {}
|
|
22
18
|
},
|
package/dist/pmtiles-source.d.ts
CHANGED
|
@@ -1,47 +1,45 @@
|
|
|
1
1
|
import type { Schema } from '@loaders.gl/schema';
|
|
2
2
|
import type { VectorTileSource, GetTileParameters, GetTileDataParameters, ImageTileSource, ImageType } from '@loaders.gl/loader-utils';
|
|
3
|
-
import { DataSource,
|
|
3
|
+
import { DataSource, DataSourceOptions } from '@loaders.gl/loader-utils';
|
|
4
4
|
import { ImageLoaderOptions } from '@loaders.gl/images';
|
|
5
5
|
import { MVTLoaderOptions, TileJSONLoaderOptions } from '@loaders.gl/mvt';
|
|
6
6
|
import * as pmtiles from 'pmtiles';
|
|
7
7
|
import type { PMTilesMetadata } from "./lib/parse-pmtiles.js";
|
|
8
|
+
export type PMTilesSourceOptions = DataSourceOptions & {
|
|
9
|
+
core?: DataSourceOptions['core'] & {
|
|
10
|
+
loadOptions?: TileJSONLoaderOptions & MVTLoaderOptions & ImageLoaderOptions;
|
|
11
|
+
};
|
|
12
|
+
pmtiles?: {};
|
|
13
|
+
};
|
|
8
14
|
/**
|
|
9
15
|
* Creates vector tile data sources for PMTiles urls or blobs
|
|
10
16
|
*/
|
|
11
17
|
export declare const PMTilesSource: {
|
|
12
|
-
readonly name: "PMTiles";
|
|
13
|
-
readonly id: "pmtiles";
|
|
14
|
-
readonly module: "pmtiles";
|
|
15
18
|
readonly version: "1.0.0";
|
|
16
|
-
readonly extensions: ["pmtiles"];
|
|
17
|
-
readonly mimeTypes: ["application/octet-stream"];
|
|
18
|
-
readonly options: {
|
|
19
|
-
readonly url: never;
|
|
20
|
-
readonly pmtiles: {};
|
|
21
|
-
};
|
|
22
19
|
readonly type: "pmtiles";
|
|
23
20
|
readonly fromUrl: true;
|
|
24
21
|
readonly fromBlob: true;
|
|
25
|
-
readonly
|
|
26
|
-
|
|
27
|
-
};
|
|
28
|
-
export type PMTilesTileSourceProps = DataSourceProps & {
|
|
29
|
-
attributions?: string[];
|
|
30
|
-
pmtiles?: {
|
|
31
|
-
loadOptions?: TileJSONLoaderOptions & MVTLoaderOptions & ImageLoaderOptions;
|
|
22
|
+
readonly defaultOptions: {
|
|
23
|
+
readonly pmtiles: {};
|
|
32
24
|
};
|
|
25
|
+
readonly testURL: (url: string) => boolean;
|
|
26
|
+
readonly createDataSource: (url: string | Blob, options: PMTilesSourceOptions) => PMTilesTileSource;
|
|
27
|
+
readonly name: "PMTiles";
|
|
28
|
+
readonly id: "pmtiles";
|
|
29
|
+
readonly module: "pmtiles";
|
|
30
|
+
readonly extensions: ["pmtiles"];
|
|
31
|
+
readonly mimeTypes: ["application/octet-stream"];
|
|
32
|
+
readonly tests: ["PMTiles"];
|
|
33
33
|
};
|
|
34
34
|
/**
|
|
35
35
|
* A PMTiles data source
|
|
36
36
|
* @note Can be either a raster or vector tile source depending on the contents of the PMTiles file.
|
|
37
37
|
*/
|
|
38
|
-
export declare class PMTilesTileSource extends DataSource implements ImageTileSource, VectorTileSource {
|
|
39
|
-
data: string | Blob;
|
|
40
|
-
props: PMTilesTileSourceProps;
|
|
38
|
+
export declare class PMTilesTileSource extends DataSource<string | Blob, PMTilesSourceOptions> implements ImageTileSource, VectorTileSource {
|
|
41
39
|
mimeType: string | null;
|
|
42
40
|
pmtiles: pmtiles.PMTiles;
|
|
43
41
|
metadata: Promise<PMTilesMetadata>;
|
|
44
|
-
constructor(data: string | Blob,
|
|
42
|
+
constructor(data: string | Blob, options: PMTilesSourceOptions);
|
|
45
43
|
getSchema(): Promise<Schema>;
|
|
46
44
|
getMetadata(): Promise<PMTilesMetadata>;
|
|
47
45
|
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,EAEV,gBAAgB,EAChB,iBAAiB,EACjB,qBAAqB,EACrB,eAAe,EACf,SAAS,EACV,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAC,UAAU,EAAE,
|
|
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,EAEV,gBAAgB,EAChB,iBAAiB,EACjB,qBAAqB,EACrB,eAAe,EACf,SAAS,EACV,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAC,UAAU,EAAE,iBAAiB,EAAc,MAAM,0BAA0B,CAAC;AACpF,OAAO,EAAc,kBAAkB,EAAC,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAY,gBAAgB,EAAE,qBAAqB,EAAC,MAAM,iBAAiB,CAAC;AAGnF,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAGnC,OAAO,KAAK,EAAC,eAAe,EAAC,+BAA4B;AAMzD,MAAM,MAAM,oBAAoB,GAAG,iBAAiB,GAAG;IACrD,IAAI,CAAC,EAAE,iBAAiB,CAAC,MAAM,CAAC,GAAG;QACjC,WAAW,CAAC,EAAE,qBAAqB,GAAG,gBAAgB,GAAG,kBAAkB,CAAC;KAC7E,CAAC;IACF,OAAO,CAAC,EAAE,EAAE,CAAC;CACd,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa;;;;;;;;4BAWT,MAAM;qCACG,MAAM,GAAG,IAAI,WAAW,oBAAoB;;;;;;;CAExB,CAAC;AAE/C;;;GAGG;AACH,qBAAa,iBACX,SAAQ,UAAU,CAAC,MAAM,GAAG,IAAI,EAAE,oBAAoB,CACtD,YAAW,eAAe,EAAE,gBAAgB;IAE5C,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,OAAO,EAAE,oBAAoB;IASxD,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC;IAI5B,WAAW,IAAI,OAAO,CAAC,eAAe,CAAC;IAuBvC,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"}
|
package/dist/pmtiles-source.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { DataSource, resolvePath } from '@loaders.gl/loader-utils';
|
|
5
5
|
import { ImageLoader } from '@loaders.gl/images';
|
|
6
6
|
import { MVTLoader } from '@loaders.gl/mvt';
|
|
7
|
+
import { PMTilesFormat } from "./pmtiles-format.js";
|
|
7
8
|
import * as pmtiles from 'pmtiles';
|
|
8
9
|
const { PMTiles } = pmtiles;
|
|
9
10
|
import { parsePMTilesHeader } from "./lib/parse-pmtiles.js";
|
|
@@ -13,35 +14,29 @@ const VERSION = '1.0.0';
|
|
|
13
14
|
* Creates vector tile data sources for PMTiles urls or blobs
|
|
14
15
|
*/
|
|
15
16
|
export const PMTilesSource = {
|
|
16
|
-
|
|
17
|
-
id: 'pmtiles',
|
|
18
|
-
module: 'pmtiles',
|
|
17
|
+
...PMTilesFormat,
|
|
19
18
|
version: VERSION,
|
|
20
|
-
extensions: ['pmtiles'],
|
|
21
|
-
mimeTypes: ['application/octet-stream'],
|
|
22
|
-
options: { url: undefined, pmtiles: {} },
|
|
23
19
|
type: 'pmtiles',
|
|
24
20
|
fromUrl: true,
|
|
25
21
|
fromBlob: true,
|
|
22
|
+
defaultOptions: {
|
|
23
|
+
pmtiles: {}
|
|
24
|
+
},
|
|
26
25
|
testURL: (url) => url.endsWith('.pmtiles'),
|
|
27
|
-
createDataSource: (url,
|
|
26
|
+
createDataSource: (url, options) => new PMTilesTileSource(url, options)
|
|
28
27
|
};
|
|
29
28
|
/**
|
|
30
29
|
* A PMTiles data source
|
|
31
30
|
* @note Can be either a raster or vector tile source depending on the contents of the PMTiles file.
|
|
32
31
|
*/
|
|
33
32
|
export class PMTilesTileSource extends DataSource {
|
|
34
|
-
data;
|
|
35
|
-
props;
|
|
36
33
|
mimeType = null;
|
|
37
34
|
pmtiles;
|
|
38
35
|
metadata;
|
|
39
|
-
constructor(data,
|
|
40
|
-
super(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
this.data = data;
|
|
44
|
-
this.pmtiles = new PMTiles(url);
|
|
36
|
+
constructor(data, options) {
|
|
37
|
+
super(data, options, PMTilesSource.defaultOptions);
|
|
38
|
+
const urlOrBlob = typeof data === 'string' ? resolvePath(data) : new BlobSource(data, 'pmtiles');
|
|
39
|
+
this.pmtiles = new PMTiles(urlOrBlob);
|
|
45
40
|
this.getTileData = this.getTileData.bind(this);
|
|
46
41
|
this.metadata = this.getMetadata();
|
|
47
42
|
}
|
|
@@ -53,8 +48,11 @@ export class PMTilesTileSource extends DataSource {
|
|
|
53
48
|
const pmtilesMetadata = (await this.pmtiles.getMetadata()) || {};
|
|
54
49
|
const metadata = parsePMTilesHeader(pmtilesHeader, pmtilesMetadata, { includeFormatHeader: false }, this.loadOptions);
|
|
55
50
|
// Add additional attribution if necessary
|
|
56
|
-
if (this.
|
|
57
|
-
metadata.attributions = [
|
|
51
|
+
if (this.options.attributions) {
|
|
52
|
+
metadata.attributions = [
|
|
53
|
+
...(this.options.core?.attributions || []),
|
|
54
|
+
...(metadata.attributions || [])
|
|
55
|
+
];
|
|
58
56
|
}
|
|
59
57
|
if (metadata?.tileMIMEType) {
|
|
60
58
|
this.mimeType = metadata?.tileMIMEType;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/pmtiles",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.0-alpha.1",
|
|
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.
|
|
50
|
-
"@loaders.gl/loader-utils": "4.
|
|
51
|
-
"@loaders.gl/mvt": "4.
|
|
52
|
-
"@loaders.gl/schema": "4.
|
|
49
|
+
"@loaders.gl/images": "4.4.0-alpha.1",
|
|
50
|
+
"@loaders.gl/loader-utils": "4.4.0-alpha.1",
|
|
51
|
+
"@loaders.gl/mvt": "4.4.0-alpha.1",
|
|
52
|
+
"@loaders.gl/schema": "4.4.0-alpha.1",
|
|
53
53
|
"pmtiles": "^3.0.4"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@loaders.gl/core": "
|
|
56
|
+
"@loaders.gl/core": "4.4.0-alpha.0"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "f1732de45907bd500bf4eedb4803beca8bf4bfb0"
|
|
59
59
|
}
|
package/src/index.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
export {PMTilesSource} from './pmtiles-source';
|
|
6
6
|
|
|
7
7
|
export type {PMTilesMetadata} from './lib/parse-pmtiles';
|
|
8
|
-
export type {
|
|
8
|
+
export type {PMTilesSourceOptions} from './pmtiles-source';
|
|
9
9
|
export {PMTilesTileSource} from './pmtiles-source';
|
|
10
10
|
|
|
11
11
|
export {PMTilesLoader as _PMTilesLoader} from './pmtiles-loader';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {Format} from '@loaders.gl/loader-utils';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* PMTiles
|
|
9
|
+
*/
|
|
10
|
+
export const PMTilesFormat = {
|
|
11
|
+
name: 'PMTiles',
|
|
12
|
+
id: 'pmtiles',
|
|
13
|
+
module: 'pmtiles',
|
|
14
|
+
extensions: ['pmtiles'],
|
|
15
|
+
mimeTypes: ['application/octet-stream'],
|
|
16
|
+
tests: ['PMTiles']
|
|
17
|
+
} as const satisfies Format;
|
package/src/pmtiles-loader.ts
CHANGED
|
@@ -7,10 +7,11 @@ import {BlobFile} from '@loaders.gl/loader-utils';
|
|
|
7
7
|
import {VERSION} from './lib/version';
|
|
8
8
|
|
|
9
9
|
import {VectorSourceInfo, ImageSourceInfo} from './source-info';
|
|
10
|
-
import {PMTilesTileSource,
|
|
10
|
+
import {PMTilesTileSource, PMTilesSourceOptions} from './pmtiles-source';
|
|
11
|
+
import {PMTilesFormat} from './pmtiles-format';
|
|
11
12
|
|
|
12
13
|
export type PMTilesLoaderOptions = LoaderOptions & {
|
|
13
|
-
pmtiles?:
|
|
14
|
+
pmtiles?: PMTilesSourceOptions['pmtiles'];
|
|
14
15
|
};
|
|
15
16
|
|
|
16
17
|
/**
|
|
@@ -19,13 +20,8 @@ export type PMTilesLoaderOptions = LoaderOptions & {
|
|
|
19
20
|
* @note For actual access to the tile data, use the PMTilesSource class.
|
|
20
21
|
*/
|
|
21
22
|
export const PMTilesLoader = {
|
|
22
|
-
|
|
23
|
-
id: 'pmtiles',
|
|
24
|
-
module: 'pmtiles',
|
|
23
|
+
...PMTilesFormat,
|
|
25
24
|
version: VERSION,
|
|
26
|
-
extensions: ['pmtiles'],
|
|
27
|
-
mimeTypes: ['application/octet-stream'],
|
|
28
|
-
tests: ['PMTiles'],
|
|
29
25
|
options: {
|
|
30
26
|
pmtiles: {}
|
|
31
27
|
},
|
package/src/pmtiles-source.ts
CHANGED
|
@@ -11,9 +11,10 @@ import type {
|
|
|
11
11
|
ImageTileSource,
|
|
12
12
|
ImageType
|
|
13
13
|
} from '@loaders.gl/loader-utils';
|
|
14
|
-
import {DataSource,
|
|
14
|
+
import {DataSource, DataSourceOptions, resolvePath} from '@loaders.gl/loader-utils';
|
|
15
15
|
import {ImageLoader, ImageLoaderOptions} from '@loaders.gl/images';
|
|
16
16
|
import {MVTLoader, MVTLoaderOptions, TileJSONLoaderOptions} from '@loaders.gl/mvt';
|
|
17
|
+
import {PMTilesFormat} from './pmtiles-format';
|
|
17
18
|
|
|
18
19
|
import * as pmtiles from 'pmtiles';
|
|
19
20
|
const {PMTiles} = pmtiles;
|
|
@@ -24,51 +25,49 @@ import {BlobSource} from './lib/blob-source';
|
|
|
24
25
|
|
|
25
26
|
const VERSION = '1.0.0';
|
|
26
27
|
|
|
28
|
+
export type PMTilesSourceOptions = DataSourceOptions & {
|
|
29
|
+
core?: DataSourceOptions['core'] & {
|
|
30
|
+
loadOptions?: TileJSONLoaderOptions & MVTLoaderOptions & ImageLoaderOptions;
|
|
31
|
+
};
|
|
32
|
+
pmtiles?: {};
|
|
33
|
+
};
|
|
34
|
+
|
|
27
35
|
/**
|
|
28
36
|
* Creates vector tile data sources for PMTiles urls or blobs
|
|
29
37
|
*/
|
|
30
38
|
export const PMTilesSource = {
|
|
31
|
-
|
|
32
|
-
id: 'pmtiles',
|
|
33
|
-
module: 'pmtiles',
|
|
39
|
+
...PMTilesFormat,
|
|
34
40
|
version: VERSION,
|
|
35
|
-
extensions: ['pmtiles'],
|
|
36
|
-
mimeTypes: ['application/octet-stream'],
|
|
37
|
-
options: {url: undefined!, pmtiles: {}},
|
|
38
41
|
type: 'pmtiles',
|
|
39
42
|
fromUrl: true,
|
|
40
43
|
fromBlob: true,
|
|
41
44
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
} as const satisfies Source<PMTilesTileSource, PMTilesTileSourceProps>;
|
|
45
|
+
defaultOptions: {
|
|
46
|
+
pmtiles: {}
|
|
47
|
+
},
|
|
46
48
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
// TODO - add options here
|
|
52
|
-
};
|
|
53
|
-
};
|
|
49
|
+
testURL: (url: string) => url.endsWith('.pmtiles'),
|
|
50
|
+
createDataSource: (url: string | Blob, options: PMTilesSourceOptions) =>
|
|
51
|
+
new PMTilesTileSource(url, options)
|
|
52
|
+
} as const satisfies Source<PMTilesTileSource>;
|
|
54
53
|
|
|
55
54
|
/**
|
|
56
55
|
* A PMTiles data source
|
|
57
56
|
* @note Can be either a raster or vector tile source depending on the contents of the PMTiles file.
|
|
58
57
|
*/
|
|
59
|
-
export class PMTilesTileSource
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
export class PMTilesTileSource
|
|
59
|
+
extends DataSource<string | Blob, PMTilesSourceOptions>
|
|
60
|
+
implements ImageTileSource, VectorTileSource
|
|
61
|
+
{
|
|
62
62
|
mimeType: string | null = null;
|
|
63
63
|
pmtiles: pmtiles.PMTiles;
|
|
64
64
|
metadata: Promise<PMTilesMetadata>;
|
|
65
65
|
|
|
66
|
-
constructor(data: string | Blob,
|
|
67
|
-
super(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
this.
|
|
71
|
-
this.pmtiles = new PMTiles(url);
|
|
66
|
+
constructor(data: string | Blob, options: PMTilesSourceOptions) {
|
|
67
|
+
super(data, options, PMTilesSource.defaultOptions);
|
|
68
|
+
const urlOrBlob =
|
|
69
|
+
typeof data === 'string' ? resolvePath(data) : new BlobSource(data, 'pmtiles');
|
|
70
|
+
this.pmtiles = new PMTiles(urlOrBlob);
|
|
72
71
|
this.getTileData = this.getTileData.bind(this);
|
|
73
72
|
this.metadata = this.getMetadata();
|
|
74
73
|
}
|
|
@@ -87,8 +86,11 @@ export class PMTilesTileSource extends DataSource implements ImageTileSource, Ve
|
|
|
87
86
|
this.loadOptions
|
|
88
87
|
);
|
|
89
88
|
// Add additional attribution if necessary
|
|
90
|
-
if (this.
|
|
91
|
-
metadata.attributions = [
|
|
89
|
+
if (this.options.attributions) {
|
|
90
|
+
metadata.attributions = [
|
|
91
|
+
...(this.options.core?.attributions || []),
|
|
92
|
+
...(metadata.attributions || [])
|
|
93
|
+
];
|
|
92
94
|
}
|
|
93
95
|
if (metadata?.tileMIMEType) {
|
|
94
96
|
this.mimeType = metadata?.tileMIMEType;
|