@loaders.gl/pmtiles 4.2.0-alpha.4 → 4.2.0-alpha.5
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 +638 -551
- package/dist/dist.min.js +14 -0
- package/dist/index.cjs +12 -15
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/lib/blob-source.js +27 -17
- package/dist/lib/parse-pmtiles.d.ts +2 -2
- package/dist/lib/parse-pmtiles.d.ts.map +1 -1
- package/dist/lib/parse-pmtiles.js +75 -57
- package/dist/pmtiles-source.d.ts +1 -1
- package/dist/pmtiles-source.d.ts.map +1 -1
- package/dist/pmtiles-source.js +79 -97
- package/package.json +13 -9
- package/src/lib/parse-pmtiles.ts +4 -2
- package/dist/index.js.map +0 -1
- package/dist/lib/blob-source.js.map +0 -1
- package/dist/lib/parse-pmtiles.js.map +0 -1
- package/dist/pmtiles-source.js.map +0 -1
package/dist/pmtiles-source.js
CHANGED
|
@@ -1,112 +1,94 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
import { DataSource, resolvePath } from '@loaders.gl/loader-utils';
|
|
2
5
|
import { ImageLoader } from '@loaders.gl/images';
|
|
3
6
|
import { MVTLoader } from '@loaders.gl/mvt';
|
|
4
7
|
import * as pmtiles from 'pmtiles';
|
|
5
|
-
const {
|
|
6
|
-
PMTiles
|
|
7
|
-
} = pmtiles;
|
|
8
|
+
const { PMTiles } = pmtiles;
|
|
8
9
|
import { parsePMTilesHeader } from "./lib/parse-pmtiles.js";
|
|
9
10
|
import { BlobSource } from "./lib/blob-source.js";
|
|
10
11
|
const VERSION = '1.0.0';
|
|
11
12
|
export const PMTilesService = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
name: 'PMTiles',
|
|
14
|
+
id: 'pmtiles',
|
|
15
|
+
module: 'pmtiles',
|
|
16
|
+
version: VERSION,
|
|
17
|
+
extensions: ['pmtiles'],
|
|
18
|
+
mimeTypes: ['application/octet-stream'],
|
|
19
|
+
options: {
|
|
20
|
+
pmtiles: {}
|
|
21
|
+
},
|
|
22
|
+
createSource: (props) => new PMTilesSource(props)
|
|
22
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* A PMTiles data source
|
|
26
|
+
* @note Can be either a raster or vector tile source depending on the contents of the PMTiles file.
|
|
27
|
+
*/
|
|
23
28
|
export class PMTilesSource extends DataSource {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
this.data = props.url;
|
|
34
|
-
this.pmtiles = new PMTiles(url);
|
|
35
|
-
this.getTileData = this.getTileData.bind(this);
|
|
36
|
-
this.metadata = this.getMetadata();
|
|
37
|
-
}
|
|
38
|
-
async getMetadata() {
|
|
39
|
-
const pmtilesHeader = await this.pmtiles.getHeader();
|
|
40
|
-
const pmtilesMetadata = await this.pmtiles.getMetadata();
|
|
41
|
-
const metadata = parsePMTilesHeader(pmtilesHeader, pmtilesMetadata, {
|
|
42
|
-
includeFormatHeader: false
|
|
43
|
-
}, this.loadOptions);
|
|
44
|
-
if (this.props.attributions) {
|
|
45
|
-
metadata.attributions = [...this.props.attributions, ...(metadata.attributions || [])];
|
|
29
|
+
constructor(props) {
|
|
30
|
+
super(props);
|
|
31
|
+
this.mimeType = null;
|
|
32
|
+
this.props = props;
|
|
33
|
+
const url = typeof props.url === 'string' ? resolvePath(props.url) : new BlobSource(props.url, 'pmtiles');
|
|
34
|
+
this.data = props.url;
|
|
35
|
+
this.pmtiles = new PMTiles(url);
|
|
36
|
+
this.getTileData = this.getTileData.bind(this);
|
|
37
|
+
this.metadata = this.getMetadata();
|
|
46
38
|
}
|
|
47
|
-
|
|
48
|
-
|
|
39
|
+
async getMetadata() {
|
|
40
|
+
const pmtilesHeader = await this.pmtiles.getHeader();
|
|
41
|
+
const pmtilesMetadata = await this.pmtiles.getMetadata();
|
|
42
|
+
const metadata = parsePMTilesHeader(pmtilesHeader, pmtilesMetadata, { includeFormatHeader: false }, this.loadOptions);
|
|
43
|
+
// Add additional attribution if necessary
|
|
44
|
+
if (this.props.attributions) {
|
|
45
|
+
metadata.attributions = [...this.props.attributions, ...(metadata.attributions || [])];
|
|
46
|
+
}
|
|
47
|
+
if (metadata?.tileMIMEType) {
|
|
48
|
+
this.mimeType = metadata?.tileMIMEType;
|
|
49
|
+
}
|
|
50
|
+
// TODO - do we need to allow tileSize to be overridden? Some PMTiles examples seem to suggest it.
|
|
51
|
+
return metadata;
|
|
49
52
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const arrayBuffer = rangeResponse === null || rangeResponse === void 0 ? void 0 : rangeResponse.data;
|
|
60
|
-
if (!arrayBuffer) {
|
|
61
|
-
return null;
|
|
53
|
+
async getTile(tileParams) {
|
|
54
|
+
const { x, y, zoom: z } = tileParams;
|
|
55
|
+
const rangeResponse = await this.pmtiles.getZxy(z, x, y);
|
|
56
|
+
const arrayBuffer = rangeResponse?.data;
|
|
57
|
+
if (!arrayBuffer) {
|
|
58
|
+
// console.error('No arrayBuffer', tileParams);
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
return arrayBuffer;
|
|
62
62
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
63
|
+
// Tile Source interface implementation: deck.gl compatible API
|
|
64
|
+
// TODO - currently only handles image tiles, not vector tiles
|
|
65
|
+
async getTileData(tileParams) {
|
|
66
|
+
const { x, y, z } = tileParams.index;
|
|
67
|
+
const metadata = await this.metadata;
|
|
68
|
+
switch (metadata.tileMIMEType) {
|
|
69
|
+
case 'application/vnd.mapbox-vector-tile':
|
|
70
|
+
return await this.getVectorTile({ x, y, zoom: z, layers: [] });
|
|
71
|
+
default:
|
|
72
|
+
return await this.getImageTile({ x, y, zoom: z, layers: [] });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// ImageTileSource interface implementation
|
|
76
|
+
async getImageTile(tileParams) {
|
|
77
|
+
const arrayBuffer = await this.getTile(tileParams);
|
|
78
|
+
return arrayBuffer ? await ImageLoader.parse(arrayBuffer, this.loadOptions) : null;
|
|
79
|
+
}
|
|
80
|
+
// VectorTileSource interface implementation
|
|
81
|
+
async getVectorTile(tileParams) {
|
|
82
|
+
const arrayBuffer = await this.getTile(tileParams);
|
|
83
|
+
const loadOptions = {
|
|
84
|
+
shape: 'geojson-table',
|
|
85
|
+
mvt: {
|
|
86
|
+
coordinates: 'wgs84',
|
|
87
|
+
tileIndex: { x: tileParams.x, y: tileParams.y, z: tileParams.zoom },
|
|
88
|
+
...this.loadOptions?.mvt
|
|
89
|
+
},
|
|
90
|
+
...this.loadOptions
|
|
91
|
+
};
|
|
92
|
+
return arrayBuffer ? await MVTLoader.parse(arrayBuffer, loadOptions) : null;
|
|
87
93
|
}
|
|
88
|
-
}
|
|
89
|
-
async getImageTile(tileParams) {
|
|
90
|
-
const arrayBuffer = await this.getTile(tileParams);
|
|
91
|
-
return arrayBuffer ? await ImageLoader.parse(arrayBuffer, this.loadOptions) : null;
|
|
92
|
-
}
|
|
93
|
-
async getVectorTile(tileParams) {
|
|
94
|
-
var _this$loadOptions;
|
|
95
|
-
const arrayBuffer = await this.getTile(tileParams);
|
|
96
|
-
const loadOptions = {
|
|
97
|
-
shape: 'geojson-table',
|
|
98
|
-
mvt: {
|
|
99
|
-
coordinates: 'wgs84',
|
|
100
|
-
tileIndex: {
|
|
101
|
-
x: tileParams.x,
|
|
102
|
-
y: tileParams.y,
|
|
103
|
-
z: tileParams.zoom
|
|
104
|
-
},
|
|
105
|
-
...((_this$loadOptions = this.loadOptions) === null || _this$loadOptions === void 0 ? void 0 : _this$loadOptions.mvt)
|
|
106
|
-
},
|
|
107
|
-
...this.loadOptions
|
|
108
|
-
};
|
|
109
|
-
return arrayBuffer ? await MVTLoader.parse(arrayBuffer, loadOptions) : null;
|
|
110
|
-
}
|
|
111
94
|
}
|
|
112
|
-
//# sourceMappingURL=pmtiles-source.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/pmtiles",
|
|
3
|
-
"version": "4.2.0-alpha.
|
|
3
|
+
"version": "4.2.0-alpha.5",
|
|
4
4
|
"description": "Framework-independent loader for the pmtiles format",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -41,15 +41,19 @@
|
|
|
41
41
|
"README.md"
|
|
42
42
|
],
|
|
43
43
|
"scripts": {
|
|
44
|
-
"pre-build": "npm run build-bundle && npm run build-bundle
|
|
45
|
-
"build-bundle": "ocular-bundle ./
|
|
44
|
+
"pre-build": "npm run build-bundle && npm run build-bundle-dev",
|
|
45
|
+
"build-bundle": "ocular-bundle ./bundle.ts --output=dist/dist.min.js",
|
|
46
|
+
"build-bundle-dev": "ocular-bundle ./bundle.ts --env=dev --output=dist/dist.dev.js"
|
|
46
47
|
},
|
|
47
48
|
"dependencies": {
|
|
48
|
-
"@loaders.gl/images": "4.2.0-alpha.
|
|
49
|
-
"@loaders.gl/loader-utils": "4.2.0-alpha.
|
|
50
|
-
"@loaders.gl/mvt": "4.2.0-alpha.
|
|
51
|
-
"@loaders.gl/schema": "4.2.0-alpha.
|
|
52
|
-
"pmtiles": "^
|
|
49
|
+
"@loaders.gl/images": "4.2.0-alpha.5",
|
|
50
|
+
"@loaders.gl/loader-utils": "4.2.0-alpha.5",
|
|
51
|
+
"@loaders.gl/mvt": "4.2.0-alpha.5",
|
|
52
|
+
"@loaders.gl/schema": "4.2.0-alpha.5",
|
|
53
|
+
"pmtiles": "^3.0.4"
|
|
53
54
|
},
|
|
54
|
-
"
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"@loaders.gl/core": "^4.0.0"
|
|
57
|
+
},
|
|
58
|
+
"gitHead": "32d95a81971f104e4dfeb88ab57065f05321a76a"
|
|
55
59
|
}
|
package/src/lib/parse-pmtiles.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import {LoaderOptions} from '@loaders.gl/loader-utils';
|
|
5
|
+
import type {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,10 +61,12 @@ export type PMTilesMetadata = {
|
|
|
61
61
|
*/
|
|
62
62
|
export function parsePMTilesHeader(
|
|
63
63
|
header: pmtiles.Header,
|
|
64
|
-
|
|
64
|
+
pmmetadata: unknown,
|
|
65
65
|
options?: {includeFormatHeader?: boolean},
|
|
66
66
|
loadOptions?: LoaderOptions
|
|
67
67
|
): PMTilesMetadata {
|
|
68
|
+
const pmtilesMetadata = pmmetadata as Record<string, unknown> | null;
|
|
69
|
+
|
|
68
70
|
// Ironically, to use the TileJSON loader we need to stringify the metadata again.
|
|
69
71
|
// This is the price of integrating with the existing pmtiles library.
|
|
70
72
|
// TODO - provide a non-standard TileJSONLoader parsers that accepts a JSON object?
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["PMTilesSource"],"sources":["../src/index.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nexport type {PMTilesMetadata} from './lib/parse-pmtiles';\nexport type {PMTilesSourceProps} from './pmtiles-source';\nexport {PMTilesSource} from './pmtiles-source';\n"],"mappings":"SAMQA,aAAa"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"blob-source.js","names":["BlobSource","constructor","blob","key","getKey","url","getBytes","offset","length","signal","slice","data","arrayBuffer"],"sources":["../../src/lib/blob-source.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport * as pmtiles from 'pmtiles';\n\n/**\n * A PMTiles library compatible source that reads from blobs\n * @deprecated TODO - reimplement as ReadableFileSource\n * Use loaders.gl HTTP range requests instead\n */\nexport class BlobSource implements pmtiles.Source {\n blob: Blob;\n key: string;\n\n constructor(blob: Blob, key: string) {\n this.blob = blob;\n this.key = key;\n }\n\n // TODO - how is this used?\n getKey() {\n // @ts-expect-error url is only defined on File subclass\n return this.blob.url || '';\n }\n\n async getBytes(\n offset: number,\n length: number,\n signal?: AbortSignal\n ): Promise<pmtiles.RangeResponse> {\n const slice = this.blob.slice(offset, offset + length);\n const data = await slice.arrayBuffer();\n return {\n data\n // etag: response.headers.get('ETag') || undefined,\n // cacheControl: response.headers.get('Cache-Control') || undefined,\n // expires: response.headers.get('Expires') || undefined\n };\n }\n}\n"],"mappings":"AAWA,OAAO,MAAMA,UAAU,CAA2B;EAIhDC,WAAWA,CAACC,IAAU,EAAEC,GAAW,EAAE;IAAA,KAHrCD,IAAI;IAAA,KACJC,GAAG;IAGD,IAAI,CAACD,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACC,GAAG,GAAGA,GAAG;EAChB;EAGAC,MAAMA,CAAA,EAAG;IAEP,OAAO,IAAI,CAACF,IAAI,CAACG,GAAG,IAAI,EAAE;EAC5B;EAEA,MAAMC,QAAQA,CACZC,MAAc,EACdC,MAAc,EACdC,MAAoB,EACY;IAChC,MAAMC,KAAK,GAAG,IAAI,CAACR,IAAI,CAACQ,KAAK,CAACH,MAAM,EAAEA,MAAM,GAAGC,MAAM,CAAC;IACtD,MAAMG,IAAI,GAAG,MAAMD,KAAK,CAACE,WAAW,CAAC,CAAC;IACtC,OAAO;MACLD;IAIF,CAAC;EACH;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parse-pmtiles.js","names":["TileJSONLoader","pmtiles","TileType","parsePMTilesHeader","header","pmtilesMetadata","options","loadOptions","_tilejson","_tilejson2","tilejson","_TileJSONLoader$parse","string","JSON","stringify","parseTextSync","call","error","console","warn","partialMetadata","name","htmlAttribution","attributions","metadata","format","formatVersion","specVersion","tileMIMEType","decodeTileType","tileType","minZoom","maxZoom","boundingBox","minLon","minLat","maxLon","maxLat","center","centerLon","centerLat","centerZoom","etag","includeFormatHeader","formatHeader","formatMetadata","Mvt","Png","Jpeg","Webp","Avif"],"sources":["../../src/lib/parse-pmtiles.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport {LoaderOptions} from '@loaders.gl/loader-utils';\nimport type {TileJSON} from '@loaders.gl/mvt';\nimport {TileJSONLoader} from '@loaders.gl/mvt';\n// import {Source, PMTiles, Header, TileType} from 'pmtiles';\nimport * as pmtiles from 'pmtiles';\nconst {TileType} = pmtiles;\n\n/** Metadata describing a PMTiles file */\nexport type PMTilesMetadata = {\n format: 'pmtiles';\n /** Version of pm tiles format used by this tileset */\n formatVersion: number;\n\n /** MIME type for tile contents. Unknown tile types will return 'application/octet-stream */\n tileMIMEType:\n | 'application/vnd.mapbox-vector-tile'\n | 'image/png'\n | 'image/jpeg'\n | 'image/webp'\n | 'image/avif'\n | 'application/octet-stream';\n\n /** Name of the tileset (extracted from JSON metadata if available) */\n name?: string;\n /** Attribution string (extracted from JSON metadata if available) */\n attributions?: string[];\n\n /** Minimal zoom level of tiles in this tileset */\n minZoom: number;\n /** Maximal zoom level of tiles in this tileset */\n maxZoom: number;\n /** Bounding box of tiles in this tileset `[[w, s], [e, n]]` */\n boundingBox: [min: [x: number, y: number], max: [x: number, y: number]];\n /** Center long, lat of this tileset */\n center: [number, number];\n /** Center zoom level of this tileset */\n centerZoom: number;\n /** Cache tag */\n etag?: string;\n\n /** Parsed TileJSON/tilestats metadata, if present */\n tilejson?: TileJSON;\n\n /** @deprecated PMTiles format specific header */\n formatHeader?: pmtiles.Header;\n /** @deprecated Unparsed metadata (Assumption metadata generated by e.g. tippecanoe, typically TileJSON) */\n formatMetadata?: Record<string, unknown>;\n};\n\n/**\n * Parse PMTiles metdata from a PMTiles file\n * @param header\n * @param tilejsonMetadata\n * @param options\n * @param loadOptions\n * @returns\n */\nexport function parsePMTilesHeader(\n header: pmtiles.Header,\n pmtilesMetadata: Record<string, unknown> | null,\n options?: {includeFormatHeader?: boolean},\n loadOptions?: LoaderOptions\n): PMTilesMetadata {\n // Ironically, to use the TileJSON loader we need to stringify the metadata again.\n // This is the price of integrating with the existing pmtiles library.\n // TODO - provide a non-standard TileJSONLoader parsers that accepts a JSON object?\n let tilejson: TileJSON | null = null;\n if (pmtilesMetadata) {\n try {\n const string = JSON.stringify(pmtilesMetadata);\n tilejson = TileJSONLoader.parseTextSync?.(string, loadOptions) || null;\n } catch (error) {\n // eslint-disable-next-line no-console\n console.warn('PMTiles metadata could not be interpreted as TileJSON', error);\n }\n }\n\n const partialMetadata: Partial<PMTilesMetadata> = {};\n\n if (typeof tilejson?.name === 'string') {\n partialMetadata.name = tilejson.name;\n }\n\n if (typeof tilejson?.htmlAttribution === 'string') {\n partialMetadata.attributions = [tilejson.htmlAttribution];\n }\n\n const metadata: PMTilesMetadata = {\n ...partialMetadata,\n format: 'pmtiles',\n formatVersion: header.specVersion,\n attributions: [],\n tileMIMEType: decodeTileType(header.tileType),\n minZoom: header.minZoom,\n maxZoom: header.maxZoom,\n boundingBox: [\n [header.minLon, header.minLat],\n [header.maxLon, header.maxLat]\n ],\n center: [header.centerLon, header.centerLat],\n centerZoom: header.centerZoom,\n etag: header.etag\n };\n\n if (tilejson) {\n metadata.tilejson = tilejson;\n }\n\n // Application can optionally include the raw header and metadata.\n if (options?.includeFormatHeader) {\n metadata.formatHeader = header;\n metadata.formatMetadata = metadata;\n }\n\n return metadata;\n}\n\n/** Extract a MIME type for tiles from vector tile header */\nfunction decodeTileType(\n tileType: pmtiles.TileType\n):\n | 'application/vnd.mapbox-vector-tile'\n | 'image/png'\n | 'image/jpeg'\n | 'image/webp'\n | 'image/avif'\n | 'application/octet-stream' {\n switch (tileType) {\n case TileType.Mvt:\n return 'application/vnd.mapbox-vector-tile';\n case TileType.Png:\n return 'image/png';\n case TileType.Jpeg:\n return 'image/jpeg';\n case TileType.Webp:\n return 'image/webp';\n case TileType.Avif:\n return 'image/avif';\n default:\n return 'application/octet-stream';\n }\n}\n"],"mappings":"AAMA,SAAQA,cAAc,QAAO,iBAAiB;AAE9C,OAAO,KAAKC,OAAO,MAAM,SAAS;AAClC,MAAM;EAACC;AAAQ,CAAC,GAAGD,OAAO;AAoD1B,OAAO,SAASE,kBAAkBA,CAChCC,MAAsB,EACtBC,eAA+C,EAC/CC,OAAyC,EACzCC,WAA2B,EACV;EAAA,IAAAC,SAAA,EAAAC,UAAA;EAIjB,IAAIC,QAAyB,GAAG,IAAI;EACpC,IAAIL,eAAe,EAAE;IACnB,IAAI;MAAA,IAAAM,qBAAA;MACF,MAAMC,MAAM,GAAGC,IAAI,CAACC,SAAS,CAACT,eAAe,CAAC;MAC9CK,QAAQ,GAAG,EAAAC,qBAAA,GAAAX,cAAc,CAACe,aAAa,cAAAJ,qBAAA,uBAA5BA,qBAAA,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AC9B;EAGA,IAAIJ,OAAO,aAAPA,OAAO,eAAPA,OAAO,CAAEqC,mBAAmB,EAAE;IAChCnB,QAAQ,CAACoB,YAAY,GAAGxC,MAAM;IAC9BoB,QAAQ,CAACqB,cAAc,GAAGrB,QAAQ;EACpC;EAEA,OAAOA,QAAQ;AACjB;AAGA,SAASK,cAAcA,CACrBC,QAA0B,EAOG;EAC7B,QAAQA,QAAQ;IACd,KAAK5B,QAAQ,CAAC4C,GAAG;MACf,OAAO,oCAAoC;IAC7C,KAAK5C,QAAQ,CAAC6C,GAAG;MACf,OAAO,WAAW;IACpB,KAAK7C,QAAQ,CAAC8C,IAAI;MAChB,OAAO,YAAY;IACrB,KAAK9C,QAAQ,CAAC+C,IAAI;MAChB,OAAO,YAAY;IACrB,KAAK/C,QAAQ,CAACgD,IAAI;MAChB,OAAO,YAAY;IACrB;MACE,OAAO,0BAA0B;EACrC;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pmtiles-source.js","names":["DataSource","resolvePath","ImageLoader","MVTLoader","pmtiles","PMTiles","parsePMTilesHeader","BlobSource","VERSION","PMTilesService","name","id","module","version","extensions","mimeTypes","options","createSource","props","PMTilesSource","constructor","data","mimeType","metadata","url","getTileData","bind","getMetadata","pmtilesHeader","getHeader","pmtilesMetadata","includeFormatHeader","loadOptions","attributions","tileMIMEType","getTile","tileParams","x","y","zoom","z","rangeResponse","getZxy","arrayBuffer","index","getVectorTile","layers","getImageTile","parse","_this$loadOptions","shape","mvt","coordinates","tileIndex"],"sources":["../src/pmtiles-source.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {TileLoadParameters, GetTileParameters} from '@loaders.gl/loader-utils';\nimport type {ImageType, DataSourceProps} from '@loaders.gl/loader-utils';\nimport type {ImageTileSource, VectorTileSource} from '@loaders.gl/loader-utils';\nimport {DataSource, resolvePath} from '@loaders.gl/loader-utils';\nimport {ImageLoader, ImageLoaderOptions} from '@loaders.gl/images';\nimport {MVTLoader, MVTLoaderOptions, TileJSONLoaderOptions} from '@loaders.gl/mvt';\n\nimport * as pmtiles from 'pmtiles';\nconst {PMTiles} = pmtiles;\n\nimport type {PMTilesMetadata} from './lib/parse-pmtiles';\nimport {parsePMTilesHeader} from './lib/parse-pmtiles';\nimport {BlobSource} from './lib/blob-source';\n\nconst VERSION = '1.0.0';\n\nexport type Service = {\n name: string;\n id: string;\n module: string;\n version: string;\n extensions: string[];\n mimeTypes: string[];\n options: Record<string, unknown>;\n};\n\nexport type ServiceWithSource<SourceT, SourcePropsT> = Service & {\n _source?: SourceT;\n _sourceProps?: SourcePropsT;\n createSource: (props: SourcePropsT) => SourceT;\n};\n\nexport const PMTilesService: ServiceWithSource<PMTilesSource, PMTilesSourceProps> = {\n name: 'PMTiles',\n id: 'pmtiles',\n module: 'pmtiles',\n version: VERSION,\n extensions: ['pmtiles'],\n mimeTypes: ['application/octet-stream'],\n options: {\n pmtiles: {}\n },\n createSource: (props: PMTilesSourceProps) => new PMTilesSource(props)\n};\n\nexport type PMTilesSourceProps = DataSourceProps & {\n url: string | Blob;\n attributions?: string[];\n loadOptions?: TileJSONLoaderOptions & MVTLoaderOptions & ImageLoaderOptions;\n};\n\n/**\n * A PMTiles data source\n * @note Can be either a raster or vector tile source depending on the contents of the PMTiles file.\n */\nexport class PMTilesSource extends DataSource implements ImageTileSource, VectorTileSource {\n data: string | Blob;\n props: PMTilesSourceProps;\n mimeType: string | null = null;\n pmtiles: pmtiles.PMTiles;\n metadata: Promise<PMTilesMetadata>;\n\n constructor(props: PMTilesSourceProps) {\n super(props);\n this.props = props;\n const url =\n typeof props.url === 'string' ? resolvePath(props.url) : new BlobSource(props.url, 'pmtiles');\n this.data = props.url;\n this.pmtiles = new PMTiles(url);\n this.getTileData = this.getTileData.bind(this);\n this.metadata = this.getMetadata();\n }\n\n async getMetadata(): Promise<PMTilesMetadata> {\n const pmtilesHeader = await this.pmtiles.getHeader();\n const pmtilesMetadata = await this.pmtiles.getMetadata();\n const metadata: PMTilesMetadata = parsePMTilesHeader(\n pmtilesHeader,\n pmtilesMetadata,\n {includeFormatHeader: false},\n this.loadOptions\n );\n // Add additional attribution if necessary\n if (this.props.attributions) {\n metadata.attributions = [...this.props.attributions, ...(metadata.attributions || [])];\n }\n if (metadata?.tileMIMEType) {\n this.mimeType = metadata?.tileMIMEType;\n }\n // TODO - do we need to allow tileSize to be overridden? Some PMTiles examples seem to suggest it.\n return metadata;\n }\n\n async getTile(tileParams: GetTileParameters): Promise<ArrayBuffer | null> {\n const {x, y, zoom: z} = tileParams;\n const rangeResponse = await this.pmtiles.getZxy(z, x, y);\n const arrayBuffer = rangeResponse?.data;\n if (!arrayBuffer) {\n // console.error('No arrayBuffer', tileParams);\n return null;\n }\n return arrayBuffer;\n }\n\n // Tile Source interface implementation: deck.gl compatible API\n // TODO - currently only handles image tiles, not vector tiles\n\n async getTileData(tileParams: TileLoadParameters): Promise<unknown | null> {\n const {x, y, z} = tileParams.index;\n const metadata = await this.metadata;\n switch (metadata.tileMIMEType) {\n case 'application/vnd.mapbox-vector-tile':\n return await this.getVectorTile({x, y, zoom: z, layers: []});\n default:\n return await this.getImageTile({x, y, zoom: z, layers: []});\n }\n }\n\n // ImageTileSource interface implementation\n\n async getImageTile(tileParams: GetTileParameters): Promise<ImageType | null> {\n const arrayBuffer = await this.getTile(tileParams);\n return arrayBuffer ? await ImageLoader.parse(arrayBuffer, this.loadOptions) : null;\n }\n\n // VectorTileSource interface implementation\n\n async getVectorTile(tileParams: GetTileParameters): Promise<unknown | null> {\n const arrayBuffer = await this.getTile(tileParams);\n const loadOptions: MVTLoaderOptions = {\n shape: 'geojson-table',\n mvt: {\n coordinates: 'wgs84',\n tileIndex: {x: tileParams.x, y: tileParams.y, z: tileParams.zoom},\n ...(this.loadOptions as MVTLoaderOptions)?.mvt\n },\n ...this.loadOptions\n };\n\n return arrayBuffer ? await MVTLoader.parse(arrayBuffer, loadOptions) :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