@loaders.gl/pmtiles 4.0.0-beta.1 → 4.0.0-beta.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.
- package/dist/{dist.min.js → dist.dev.js} +3645 -3305
- package/dist/index.cjs +182 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/parse-pmtiles.d.ts +6 -6
- package/dist/lib/parse-pmtiles.d.ts.map +1 -1
- package/dist/{esm/lib → lib}/parse-pmtiles.js +5 -1
- package/dist/lib/parse-pmtiles.js.map +1 -0
- package/dist/pmtiles-source.d.ts +20 -24
- package/dist/pmtiles-source.d.ts.map +1 -1
- package/dist/{esm/pmtiles-source.js → pmtiles-source.js} +23 -8
- package/dist/pmtiles-source.js.map +1 -0
- package/package.json +18 -10
- package/src/lib/parse-pmtiles.ts +9 -7
- package/src/pmtiles-source.ts +32 -28
- package/dist/bundle.d.ts +0 -2
- package/dist/bundle.d.ts.map +0 -1
- package/dist/es5/bundle.js +0 -6
- package/dist/es5/bundle.js.map +0 -1
- package/dist/es5/index.js +0 -13
- package/dist/es5/index.js.map +0 -1
- package/dist/es5/lib/parse-pmtiles.js +0 -126
- package/dist/es5/lib/parse-pmtiles.js.map +0 -1
- package/dist/es5/lib/sources.js +0 -2
- package/dist/es5/lib/sources.js.map +0 -1
- package/dist/es5/pmtiles-source.js +0 -289
- package/dist/es5/pmtiles-source.js.map +0 -1
- package/dist/esm/bundle.js +0 -4
- package/dist/esm/bundle.js.map +0 -1
- package/dist/esm/index.js +0 -2
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/lib/parse-pmtiles.js.map +0 -1
- package/dist/esm/lib/sources.js +0 -2
- package/dist/esm/lib/sources.js.map +0 -1
- package/dist/esm/pmtiles-source.js.map +0 -1
- package/dist/lib/sources.d.ts +0 -1
- package/dist/lib/sources.d.ts.map +0 -1
- package/src/bundle.ts +0 -4
- package/src/lib/sources.ts +0 -150
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
PMTilesSource: () => PMTilesSource
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(src_exports);
|
|
36
|
+
|
|
37
|
+
// src/pmtiles-source.ts
|
|
38
|
+
var import_loader_utils = require("@loaders.gl/loader-utils");
|
|
39
|
+
var import_images = require("@loaders.gl/images");
|
|
40
|
+
var import_mvt2 = require("@loaders.gl/mvt");
|
|
41
|
+
|
|
42
|
+
// src/lib/parse-pmtiles.ts
|
|
43
|
+
var import_mvt = require("@loaders.gl/mvt");
|
|
44
|
+
var pmtiles = __toESM(require("pmtiles"), 1);
|
|
45
|
+
var { PMTiles, TileType } = pmtiles;
|
|
46
|
+
function parsePMTilesHeader(header, tilejsonMetadata, options) {
|
|
47
|
+
var _a, _b;
|
|
48
|
+
const partialMetadata = {};
|
|
49
|
+
if (typeof (tilejsonMetadata == null ? void 0 : tilejsonMetadata.name) === "string") {
|
|
50
|
+
partialMetadata.name = tilejsonMetadata.name;
|
|
51
|
+
}
|
|
52
|
+
if (typeof (tilejsonMetadata == null ? void 0 : tilejsonMetadata.attribution) === "string") {
|
|
53
|
+
partialMetadata.attributions = [tilejsonMetadata.attribution];
|
|
54
|
+
}
|
|
55
|
+
const metadata = {
|
|
56
|
+
...partialMetadata,
|
|
57
|
+
format: "pmtiles",
|
|
58
|
+
formatVersion: header.specVersion,
|
|
59
|
+
mimeType: decodeTileType(header.tileType),
|
|
60
|
+
tileType: header.tileType,
|
|
61
|
+
minZoom: header.minZoom,
|
|
62
|
+
maxZoom: header.maxZoom,
|
|
63
|
+
boundingBox: [
|
|
64
|
+
[header.minLon, header.minLat],
|
|
65
|
+
[header.maxLon, header.maxLat]
|
|
66
|
+
],
|
|
67
|
+
center: [header.centerLon, header.centerLat],
|
|
68
|
+
centerZoom: header.centerZoom,
|
|
69
|
+
etag: header.etag
|
|
70
|
+
};
|
|
71
|
+
if (tilejsonMetadata) {
|
|
72
|
+
try {
|
|
73
|
+
metadata.tileJSON = ((_b = (_a = import_mvt.TileJSONLoader).parseTextSync) == null ? void 0 : _b.call(_a, JSON.stringify(tilejsonMetadata))) || void 0;
|
|
74
|
+
} catch (error) {
|
|
75
|
+
metadata.tilejsonMetadata = tilejsonMetadata;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (options == null ? void 0 : options.includeFormatHeader) {
|
|
79
|
+
metadata.formatHeader = header;
|
|
80
|
+
}
|
|
81
|
+
return metadata;
|
|
82
|
+
}
|
|
83
|
+
function decodeTileType(tileType) {
|
|
84
|
+
switch (tileType) {
|
|
85
|
+
case TileType.Mvt:
|
|
86
|
+
return "application/vnd.mapbox-vector-tile";
|
|
87
|
+
case TileType.Png:
|
|
88
|
+
return "image/png";
|
|
89
|
+
case TileType.Jpeg:
|
|
90
|
+
return "image/jpeg";
|
|
91
|
+
case TileType.Webp:
|
|
92
|
+
return "image/webp";
|
|
93
|
+
case TileType.Avif:
|
|
94
|
+
return "image/avif";
|
|
95
|
+
default:
|
|
96
|
+
return "application/octet-stream";
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// src/pmtiles-source.ts
|
|
101
|
+
var pmtiles2 = __toESM(require("pmtiles"), 1);
|
|
102
|
+
var { PMTiles: PMTiles2 } = pmtiles2;
|
|
103
|
+
var BlobSource = class {
|
|
104
|
+
constructor(blob, key) {
|
|
105
|
+
this.blob = blob;
|
|
106
|
+
this.key = key;
|
|
107
|
+
}
|
|
108
|
+
// TODO - how is this used?
|
|
109
|
+
getKey() {
|
|
110
|
+
return this.blob.url || "";
|
|
111
|
+
}
|
|
112
|
+
async getBytes(offset, length, signal) {
|
|
113
|
+
const slice = this.blob.slice(offset, offset + length);
|
|
114
|
+
const data = await slice.arrayBuffer();
|
|
115
|
+
return {
|
|
116
|
+
data
|
|
117
|
+
// etag: response.headers.get('ETag') || undefined,
|
|
118
|
+
// cacheControl: response.headers.get('Cache-Control') || undefined,
|
|
119
|
+
// expires: response.headers.get('Expires') || undefined
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
var PMTilesSource = class extends import_loader_utils.DataSource {
|
|
124
|
+
constructor(props) {
|
|
125
|
+
super(props);
|
|
126
|
+
this.props = props;
|
|
127
|
+
const url = typeof props.url === "string" ? (0, import_loader_utils.resolvePath)(props.url) : new BlobSource(props.url, "pmtiles");
|
|
128
|
+
this.pmtiles = new PMTiles2(url);
|
|
129
|
+
this.getTileData = this.getTileData.bind(this);
|
|
130
|
+
this.metadata = this.getMetadata();
|
|
131
|
+
}
|
|
132
|
+
async getMetadata() {
|
|
133
|
+
const pmtilesHeader = await this.pmtiles.getHeader();
|
|
134
|
+
const pmtilesMetadata = await this.pmtiles.getMetadata();
|
|
135
|
+
const metadata = parsePMTilesHeader(pmtilesHeader, pmtilesMetadata);
|
|
136
|
+
if (this.props.attributions) {
|
|
137
|
+
metadata.attributions = [...this.props.attributions, ...metadata.attributions || []];
|
|
138
|
+
}
|
|
139
|
+
return metadata;
|
|
140
|
+
}
|
|
141
|
+
async getTile(tileParams) {
|
|
142
|
+
const { x, y, zoom: z } = tileParams;
|
|
143
|
+
const rangeResponse = await this.pmtiles.getZxy(z, x, y);
|
|
144
|
+
const arrayBuffer = rangeResponse == null ? void 0 : rangeResponse.data;
|
|
145
|
+
if (!arrayBuffer) {
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
return arrayBuffer;
|
|
149
|
+
}
|
|
150
|
+
// Tile Source interface implementation: deck.gl compatible API
|
|
151
|
+
// TODO - currently only handles image tiles, not vector tiles
|
|
152
|
+
async getTileData(tileParams) {
|
|
153
|
+
const { x, y, z } = tileParams.index;
|
|
154
|
+
const metadata = await this.metadata;
|
|
155
|
+
switch (metadata.mimeType) {
|
|
156
|
+
case "application/vnd.mapbox-vector-tile":
|
|
157
|
+
return await this.getVectorTile({ x, y, zoom: z, layers: [] });
|
|
158
|
+
default:
|
|
159
|
+
return await this.getImageTile({ x, y, zoom: z, layers: [] });
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
// ImageTileSource interface implementation
|
|
163
|
+
async getImageTile(tileParams) {
|
|
164
|
+
const arrayBuffer = await this.getTile(tileParams);
|
|
165
|
+
return arrayBuffer ? await import_images.ImageLoader.parse(arrayBuffer, this.loadOptions) : null;
|
|
166
|
+
}
|
|
167
|
+
// VectorTileSource interface implementation
|
|
168
|
+
async getVectorTile(tileParams) {
|
|
169
|
+
var _a;
|
|
170
|
+
const arrayBuffer = await this.getTile(tileParams);
|
|
171
|
+
const loadOptions = {
|
|
172
|
+
shape: "geojson-table",
|
|
173
|
+
mvt: {
|
|
174
|
+
coordinates: "wgs84",
|
|
175
|
+
tileIndex: { x: tileParams.x, y: tileParams.y, z: tileParams.zoom },
|
|
176
|
+
...(_a = this.loadOptions) == null ? void 0 : _a.mvt
|
|
177
|
+
},
|
|
178
|
+
...this.loadOptions
|
|
179
|
+
};
|
|
180
|
+
return arrayBuffer ? await import_mvt2.MVTLoader.parse(arrayBuffer, loadOptions) : null;
|
|
181
|
+
}
|
|
182
|
+
};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["PMTilesSource"],"sources":["../src/index.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nexport type {PMTilesMetadata} from './lib/parse-pmtiles';\nexport type {PMTilesSourceProps} from './pmtiles-source';\nexport {PMTilesSource} from './pmtiles-source';\n"],"mappings":"SAIQA,aAAa"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Source, Header, TileType } from 'pmtiles';
|
|
2
1
|
import type { TileJSON } from '@loaders.gl/mvt';
|
|
2
|
+
import * as pmtiles from 'pmtiles';
|
|
3
3
|
/** Metadata describing a PMTiles file */
|
|
4
4
|
export type PMTilesMetadata = {
|
|
5
5
|
/** Name of the tileset (extracted from JSON metadata if available) */
|
|
@@ -10,11 +10,11 @@ export type PMTilesMetadata = {
|
|
|
10
10
|
/** Version of pm tiles format used by this tileset */
|
|
11
11
|
formatVersion: number;
|
|
12
12
|
/** PMTiles format specific header */
|
|
13
|
-
formatHeader?: Header;
|
|
13
|
+
formatHeader?: pmtiles.Header;
|
|
14
14
|
/** MIME type for tile contents. Unknown tile types will return 'application/octet-stream */
|
|
15
15
|
mimeType: 'application/vnd.mapbox-vector-tile' | 'image/png' | 'image/jpeg' | 'image/webp' | 'image/avif' | 'application/octet-stream';
|
|
16
16
|
/** The original numeric tile type constant specified in the PMTiles tileset */
|
|
17
|
-
tileType: TileType;
|
|
17
|
+
tileType: pmtiles.TileType;
|
|
18
18
|
/** Minimal zoom level of tiles in this tileset */
|
|
19
19
|
minZoom: number;
|
|
20
20
|
/** Maximal zoom level of tiles in this tileset */
|
|
@@ -34,9 +34,9 @@ export type PMTilesMetadata = {
|
|
|
34
34
|
export type ParsePMTilesOptions = {
|
|
35
35
|
tileZxy?: [number, number, number];
|
|
36
36
|
};
|
|
37
|
-
export declare function loadPMTilesHeader(source: Source): Promise<PMTilesMetadata>;
|
|
38
|
-
export declare function loadPMTile(source: Source, options: ParsePMTilesOptions): Promise<ArrayBuffer | undefined>;
|
|
39
|
-
export declare function parsePMTilesHeader(header: Header, tilejsonMetadata: Record<string, unknown> | null, options?: {
|
|
37
|
+
export declare function loadPMTilesHeader(source: pmtiles.Source): Promise<PMTilesMetadata>;
|
|
38
|
+
export declare function loadPMTile(source: pmtiles.Source, options: ParsePMTilesOptions): Promise<ArrayBuffer | undefined>;
|
|
39
|
+
export declare function parsePMTilesHeader(header: pmtiles.Header, tilejsonMetadata: Record<string, unknown> | null, options?: {
|
|
40
40
|
includeFormatHeader?: boolean;
|
|
41
41
|
}): PMTilesMetadata;
|
|
42
42
|
//# 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":"AAEA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"parse-pmtiles.d.ts","sourceRoot":"","sources":["../../src/lib/parse-pmtiles.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,QA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AEF,wBAAsB,iBAAiB,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CASxF;AAED,wBAAsB,UAAU,CAC9B,MAAM,EAAE,OAAO,CAAC,MAAM,EACtB,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CAQlC;AAED,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,OAAO,CAAC,MAAM,EACtB,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,EAChD,OAAO,CAAC,EAAE;IAAC,mBAAmB,CAAC,EAAE,OAAO,CAAA;CAAC,GACxC,eAAe,CA2CjB"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { PMTiles, TileType } from 'pmtiles';
|
|
2
1
|
import { TileJSONLoader } from '@loaders.gl/mvt';
|
|
2
|
+
import * as pmtiles from 'pmtiles';
|
|
3
|
+
const {
|
|
4
|
+
PMTiles,
|
|
5
|
+
TileType
|
|
6
|
+
} = pmtiles;
|
|
3
7
|
export async function loadPMTilesHeader(source) {
|
|
4
8
|
const pmTiles = new PMTiles(source);
|
|
5
9
|
const header = await pmTiles.getHeader();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-pmtiles.js","names":["TileJSONLoader","pmtiles","PMTiles","TileType","loadPMTilesHeader","source","pmTiles","header","getHeader","metadata","getMetadata","tilejsonMetadata","Array","isArray","parsePMTilesHeader","loadPMTile","options","tileZxy","Error","z","x","y","tile","getZxy","data","partialMetadata","name","attribution","attributions","format","formatVersion","specVersion","mimeType","decodeTileType","tileType","minZoom","maxZoom","boundingBox","minLon","minLat","maxLon","maxLat","center","centerLon","centerLat","centerZoom","etag","_TileJSONLoader$parse","tileJSON","parseTextSync","call","JSON","stringify","undefined","error","includeFormatHeader","formatHeader","Mvt","Png","Jpeg","Webp","Avif"],"sources":["../../src/lib/parse-pmtiles.ts"],"sourcesContent":["// loaders.gl, MIT license\n\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 {PMTiles, TileType} = pmtiles;\n\n/** Metadata describing a PMTiles file */\nexport type PMTilesMetadata = {\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 format: 'pmtiles';\n /** Version of pm tiles format used by this tileset */\n formatVersion: number;\n /** PMTiles format specific header */\n formatHeader?: pmtiles.Header;\n /** MIME type for tile contents. Unknown tile types will return 'application/octet-stream */\n mimeType:\n | 'application/vnd.mapbox-vector-tile'\n | 'image/png'\n | 'image/jpeg'\n | 'image/webp'\n | 'image/avif'\n | 'application/octet-stream';\n /** The original numeric tile type constant specified in the PMTiles tileset */\n tileType: pmtiles.TileType;\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 tileJSON?: TileJSON;\n /** Current assumption is that this is a tileJSON style metadata generated by e.g. tippecanoe */\n tilejsonMetadata?: Record<string, unknown>;\n};\n\nexport type ParsePMTilesOptions = {\n tileZxy?: [number, number, number];\n};\n\nexport async function loadPMTilesHeader(source: pmtiles.Source): Promise<PMTilesMetadata> {\n const pmTiles = new PMTiles(source);\n const header = await pmTiles.getHeader();\n const metadata = await pmTiles.getMetadata();\n const tilejsonMetadata =\n metadata && typeof metadata === 'object' && !Array.isArray(metadata)\n ? (metadata as Record<string, unknown>)\n : null;\n return parsePMTilesHeader(header, tilejsonMetadata);\n}\n\nexport async function loadPMTile(\n source: pmtiles.Source,\n options: ParsePMTilesOptions\n): Promise<ArrayBuffer | undefined> {\n const pmTiles = new PMTiles(source);\n if (!options.tileZxy) {\n throw new Error('tile zxy missing');\n }\n const [z, x, y] = options.tileZxy;\n const tile = await pmTiles.getZxy(z, x, y);\n return tile?.data;\n}\n\nexport function parsePMTilesHeader(\n header: pmtiles.Header,\n tilejsonMetadata: Record<string, unknown> | null,\n options?: {includeFormatHeader?: boolean}\n): PMTilesMetadata {\n const partialMetadata: Partial<PMTilesMetadata> = {};\n\n if (typeof tilejsonMetadata?.name === 'string') {\n partialMetadata.name = tilejsonMetadata.name;\n }\n\n if (typeof tilejsonMetadata?.attribution === 'string') {\n partialMetadata.attributions = [tilejsonMetadata.attribution];\n }\n\n const metadata: PMTilesMetadata = {\n ...partialMetadata,\n format: 'pmtiles',\n formatVersion: header.specVersion,\n mimeType: decodeTileType(header.tileType),\n tileType: 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 (tilejsonMetadata) {\n try {\n metadata.tileJSON =\n TileJSONLoader.parseTextSync?.(JSON.stringify(tilejsonMetadata)) || undefined;\n } catch (error) {\n // console.warn('PMTiles invalid tilejson metadata', error);\n metadata.tilejsonMetadata = tilejsonMetadata;\n }\n }\n\n if (options?.includeFormatHeader) {\n metadata.formatHeader = header;\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 '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7C,QAAQ,CAACE,gBAAgB,GAAGA,gBAAgB;IAC9C;EACF;EAEA,IAAIK,OAAO,aAAPA,OAAO,eAAPA,OAAO,CAAEuC,mBAAmB,EAAE;IAChC9C,QAAQ,CAAC+C,YAAY,GAAGjD,MAAM;EAChC;EAEA,OAAOE,QAAQ;AACjB;AAGA,SAASwB,cAAcA,CACrBC,QAA0B,EAOG;EAC7B,QAAQA,QAAQ;IACd,KAAK/B,QAAQ,CAACsD,GAAG;MACf,OAAO,oCAAoC;IAC7C,KAAKtD,QAAQ,CAACuD,GAAG;MACf,OAAO,WAAW;IACpB,KAAKvD,QAAQ,CAACwD,IAAI;MAChB,OAAO,YAAY;IACrB,KAAKxD,QAAQ,CAACyD,IAAI;MAChB,OAAO,YAAY;IACrB,KAAKzD,QAAQ,CAAC0D,IAAI;MAChB,OAAO,YAAY;IACrB;MACE,OAAO,0BAA0B;EACrC;AACF"}
|
package/dist/pmtiles-source.d.ts
CHANGED
|
@@ -1,38 +1,34 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TileLoadParameters, GetTileParameters } from '@loaders.gl/loader-utils';
|
|
2
|
+
import type { ImageType, DataSourceProps } from '@loaders.gl/loader-utils';
|
|
2
3
|
import type { ImageTileSource, VectorTileSource } from '@loaders.gl/loader-utils';
|
|
3
4
|
import { DataSource } from '@loaders.gl/loader-utils';
|
|
4
|
-
import { PMTiles, Source, RangeResponse } from 'pmtiles';
|
|
5
5
|
import type { PMTilesMetadata } from './lib/parse-pmtiles';
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
worker: true,
|
|
16
|
-
extensions: ['pmtiles'],
|
|
17
|
-
mimeTypes: ['application/octet-stream'],
|
|
18
|
-
options: {
|
|
19
|
-
pmtiles: {}
|
|
20
|
-
},
|
|
21
|
-
parse: async (arrayBuffer, options) => {
|
|
22
|
-
throw new Error('not implemented');
|
|
23
|
-
}
|
|
6
|
+
import * as pmtiles from 'pmtiles';
|
|
7
|
+
export type Service = {
|
|
8
|
+
name: string;
|
|
9
|
+
id: string;
|
|
10
|
+
module: string;
|
|
11
|
+
version: string;
|
|
12
|
+
extensions: string[];
|
|
13
|
+
mimeTypes: string[];
|
|
14
|
+
options: Record<string, unknown>;
|
|
24
15
|
};
|
|
25
|
-
|
|
16
|
+
export type ServiceWithSource<SourceT, SourcePropsT> = Service & {
|
|
17
|
+
_source?: SourceT;
|
|
18
|
+
_sourceProps?: SourcePropsT;
|
|
19
|
+
createSource: (props: SourcePropsT) => SourceT;
|
|
20
|
+
};
|
|
21
|
+
export declare const PMTilesService: ServiceWithSource<PMTilesSource, PMTilesSourceProps>;
|
|
26
22
|
export type PMTilesSourceProps = DataSourceProps & {
|
|
27
23
|
url: string | Blob;
|
|
28
24
|
attributions?: string[];
|
|
29
25
|
};
|
|
30
|
-
export declare class BlobSource implements Source {
|
|
26
|
+
export declare class BlobSource implements pmtiles.Source {
|
|
31
27
|
blob: Blob;
|
|
32
28
|
key: string;
|
|
33
29
|
constructor(blob: Blob, key: string);
|
|
34
30
|
getKey(): any;
|
|
35
|
-
getBytes(offset: number, length: number, signal?: AbortSignal): Promise<RangeResponse>;
|
|
31
|
+
getBytes(offset: number, length: number, signal?: AbortSignal): Promise<pmtiles.RangeResponse>;
|
|
36
32
|
}
|
|
37
33
|
/**
|
|
38
34
|
* A PMTiles data source
|
|
@@ -40,7 +36,7 @@ export declare class BlobSource implements Source {
|
|
|
40
36
|
*/
|
|
41
37
|
export declare class PMTilesSource extends DataSource implements ImageTileSource, VectorTileSource {
|
|
42
38
|
props: PMTilesSourceProps;
|
|
43
|
-
pmtiles: PMTiles;
|
|
39
|
+
pmtiles: pmtiles.PMTiles;
|
|
44
40
|
metadata: Promise<PMTilesMetadata>;
|
|
45
41
|
constructor(props: PMTilesSourceProps);
|
|
46
42
|
getMetadata(): Promise<PMTilesMetadata>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pmtiles-source.d.ts","sourceRoot":"","sources":["../src/pmtiles-source.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,
|
|
1
|
+
{"version":3,"file":"pmtiles-source.d.ts","sourceRoot":"","sources":["../src/pmtiles-source.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,kBAAkB,EAAE,iBAAiB,EAAC,MAAM,0BAA0B,CAAC;AACpF,OAAO,KAAK,EAAC,SAAS,EAAE,eAAe,EAAC,MAAM,0BAA0B,CAAC;AACzE,OAAO,KAAK,EAAC,eAAe,EAAE,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAChF,OAAO,EAAC,UAAU,EAAc,MAAM,0BAA0B,CAAC;AAIjE,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,qBAAqB,CAAC;AAGzD,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAKnC,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,iBAAiB,CAAC,OAAO,EAAE,YAAY,IAAI,OAAO,GAAG;IAC/D,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,YAAY,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC;CAChD,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,iBAAiB,CAAC,aAAa,EAAE,kBAAkB,CAW/E,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,eAAe,GAAG;IACjD,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB,CAAC;AAEF,qBAAa,UAAW,YAAW,OAAO,CAAC,MAAM;IAC/C,IAAI,EAAE,IAAI,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;gBAEA,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM;IAMnC,MAAM;IAKA,QAAQ,CACZ,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC;CAUlC;AACD;;;GAGG;AACH,qBAAa,aAAc,SAAQ,UAAW,YAAW,eAAe,EAAE,gBAAgB;IACxF,KAAK,EAAE,kBAAkB,CAAC;IAC1B,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC;IACzB,QAAQ,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;gBAEvB,KAAK,EAAE,kBAAkB;IAU/B,WAAW,IAAI,OAAO,CAAC,eAAe,CAAC;IAUvC,OAAO,CAAC,UAAU,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAcnE,WAAW,CAAC,UAAU,EAAE,kBAAkB,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAapE,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"}
|
|
@@ -1,13 +1,28 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
1
|
import { DataSource, resolvePath } from '@loaders.gl/loader-utils';
|
|
3
2
|
import { ImageLoader } from '@loaders.gl/images';
|
|
4
3
|
import { MVTLoader } from '@loaders.gl/mvt';
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
4
|
+
import { parsePMTilesHeader } from "./lib/parse-pmtiles.js";
|
|
5
|
+
import * as pmtiles from 'pmtiles';
|
|
6
|
+
const {
|
|
7
|
+
PMTiles
|
|
8
|
+
} = pmtiles;
|
|
9
|
+
const VERSION = '1.0.0';
|
|
10
|
+
export const PMTilesService = {
|
|
11
|
+
name: 'PMTiles',
|
|
12
|
+
id: 'pmtiles',
|
|
13
|
+
module: 'pmtiles',
|
|
14
|
+
version: VERSION,
|
|
15
|
+
extensions: ['pmtiles'],
|
|
16
|
+
mimeTypes: ['application/octet-stream'],
|
|
17
|
+
options: {
|
|
18
|
+
pmtiles: {}
|
|
19
|
+
},
|
|
20
|
+
createSource: props => new PMTilesSource(props)
|
|
21
|
+
};
|
|
7
22
|
export class BlobSource {
|
|
8
23
|
constructor(blob, key) {
|
|
9
|
-
|
|
10
|
-
|
|
24
|
+
this.blob = void 0;
|
|
25
|
+
this.key = void 0;
|
|
11
26
|
this.blob = blob;
|
|
12
27
|
this.key = key;
|
|
13
28
|
}
|
|
@@ -25,9 +40,9 @@ export class BlobSource {
|
|
|
25
40
|
export class PMTilesSource extends DataSource {
|
|
26
41
|
constructor(props) {
|
|
27
42
|
super(props);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
43
|
+
this.props = void 0;
|
|
44
|
+
this.pmtiles = void 0;
|
|
45
|
+
this.metadata = void 0;
|
|
31
46
|
this.props = props;
|
|
32
47
|
const url = typeof props.url === 'string' ? resolvePath(props.url) : new BlobSource(props.url, 'pmtiles');
|
|
33
48
|
this.pmtiles = new PMTiles(url);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pmtiles-source.js","names":["DataSource","resolvePath","ImageLoader","MVTLoader","parsePMTilesHeader","pmtiles","PMTiles","VERSION","PMTilesService","name","id","module","version","extensions","mimeTypes","options","createSource","props","PMTilesSource","BlobSource","constructor","blob","key","getKey","url","getBytes","offset","length","signal","slice","data","arrayBuffer","metadata","getTileData","bind","getMetadata","pmtilesHeader","getHeader","pmtilesMetadata","attributions","getTile","tileParams","x","y","zoom","z","rangeResponse","getZxy","index","mimeType","getVectorTile","layers","getImageTile","parse","loadOptions","_this$loadOptions","shape","mvt","coordinates","tileIndex"],"sources":["../src/pmtiles-source.ts"],"sourcesContent":["// loaders.gl, MIT license\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} from '@loaders.gl/images';\nimport {MVTLoader, MVTLoaderOptions} from '@loaders.gl/mvt';\n\nimport type {PMTilesMetadata} from './lib/parse-pmtiles';\nimport {parsePMTilesHeader} from './lib/parse-pmtiles';\n\nimport * as pmtiles from 'pmtiles';\nconst {PMTiles} = pmtiles;\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};\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/**\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 props: PMTilesSourceProps;\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.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 = parsePMTilesHeader(pmtilesHeader, pmtilesMetadata);\n if (this.props.attributions) {\n metadata.attributions = [...this.props.attributions, ...(metadata.attributions || [])];\n }\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.mimeType) {\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) : null;\n }\n}\n"],"mappings":"AAKA,SAAQA,UAAU,EAAEC,WAAW,QAAO,0BAA0B;AAChE,SAAQC,WAAW,QAAO,oBAAoB;AAC9C,SAAQC,SAAS,QAAyB,iBAAiB;AAAC,SAGpDC,kBAAkB;AAE1B,OAAO,KAAKC,OAAO,MAAM,SAAS;AAClC,MAAM;EAACC;AAAO,CAAC,GAAGD,OAAO;AAEzB,MAAME,OAAO,GAAG,OAAO;AAkBvB,OAAO,MAAMC,cAAoE,GAAG;EAClFC,IAAI,EAAE,SAAS;EACfC,EAAE,EAAE,SAAS;EACbC,MAAM,EAAE,SAAS;EACjBC,OAAO,EAAEL,OAAO;EAChBM,UAAU,EAAE,CAAC,SAAS,CAAC;EACvBC,SAAS,EAAE,CAAC,0BAA0B,CAAC;EACvCC,OAAO,EAAE;IACPV,OAAO,EAAE,CAAC;EACZ,CAAC;EACDW,YAAY,EAAGC,KAAyB,IAAK,IAAIC,aAAa,CAACD,KAAK;AACtE,CAAC;AAOD,OAAO,MAAME,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,GAA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,MAAM7B,WAAW,CAACmD,KAAK,CAACtB,WAAW,EAAE,IAAI,CAACuB,WAAW,CAAC,GAAG,IAAI;EACpF;EAIA,MAAMJ,aAAaA,CAACT,UAA6B,EAA2B;IAAA,IAAAc,iBAAA;IAC1E,MAAMxB,WAAW,GAAG,MAAM,IAAI,CAACS,OAAO,CAACC,UAAU,CAAC;IAClD,MAAMa,WAA6B,GAAG;MACpCE,KAAK,EAAE,eAAe;MACtBC,GAAG,EAAE;QACHC,WAAW,EAAE,OAAO;QACpBC,SAAS,EAAE;UAACjB,CAAC,EAAED,UAAU,CAACC,CAAC;UAAEC,CAAC,EAAEF,UAAU,CAACE,CAAC;UAAEE,CAAC,EAAEJ,UAAU,CAACG;QAAI,CAAC;QACjE,KAAAW,iBAAA,GAAI,IAAI,CAACD,WAAW,cAAAC,iBAAA,uBAAjBA,iBAAA,CAAwCE,GAAG;MAChD,CAAC;MACD,GAAG,IAAI,CAACH;IACV,CAAC;IAED,OAAOvB,WAAW,GAAG,MAAM5B,SAAS,CAACkD,KAAK,CAACtB,WAAW,EAAEuB,WAAW,CAAC,GAAG,IAAI;EAC7E;AACF"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/pmtiles",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.3",
|
|
4
4
|
"description": "Framework-independent loader for the pmtiles format",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
6
7
|
"publishConfig": {
|
|
7
8
|
"access": "public"
|
|
8
9
|
},
|
|
@@ -19,8 +20,15 @@
|
|
|
19
20
|
"PCD"
|
|
20
21
|
],
|
|
21
22
|
"types": "dist/index.d.ts",
|
|
22
|
-
"main": "dist/
|
|
23
|
-
"module": "dist/
|
|
23
|
+
"main": "dist/index.cjs",
|
|
24
|
+
"module": "dist/index.js",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"import": "./dist/index.js",
|
|
28
|
+
"require": "./dist/index.cjs",
|
|
29
|
+
"types": "./dist/index.d.ts"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
24
32
|
"sideEffects": false,
|
|
25
33
|
"files": [
|
|
26
34
|
"src",
|
|
@@ -28,15 +36,15 @@
|
|
|
28
36
|
"README.md"
|
|
29
37
|
],
|
|
30
38
|
"scripts": {
|
|
31
|
-
"pre-build": "npm run build-bundle",
|
|
32
|
-
"build-bundle": "
|
|
39
|
+
"pre-build": "npm run build-bundle && npm run build-bundle -- --env=dev",
|
|
40
|
+
"build-bundle": "ocular-bundle ./src/index.ts"
|
|
33
41
|
},
|
|
34
42
|
"dependencies": {
|
|
35
|
-
"@loaders.gl/images": "4.0.0-beta.
|
|
36
|
-
"@loaders.gl/loader-utils": "4.0.0-beta.
|
|
37
|
-
"@loaders.gl/mvt": "4.0.0-beta.
|
|
38
|
-
"@loaders.gl/schema": "4.0.0-beta.
|
|
43
|
+
"@loaders.gl/images": "4.0.0-beta.3",
|
|
44
|
+
"@loaders.gl/loader-utils": "4.0.0-beta.3",
|
|
45
|
+
"@loaders.gl/mvt": "4.0.0-beta.3",
|
|
46
|
+
"@loaders.gl/schema": "4.0.0-beta.3",
|
|
39
47
|
"pmtiles": "^2.7.2"
|
|
40
48
|
},
|
|
41
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "7ba9621cc51c7a26c407086ac86171f35b8712af"
|
|
42
50
|
}
|
package/src/lib/parse-pmtiles.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// loaders.gl, MIT license
|
|
2
2
|
|
|
3
|
-
import {Source, PMTiles, Header, TileType} from 'pmtiles';
|
|
4
3
|
import type {TileJSON} from '@loaders.gl/mvt';
|
|
5
4
|
import {TileJSONLoader} from '@loaders.gl/mvt';
|
|
5
|
+
// import {Source, PMTiles, Header, TileType} from 'pmtiles';
|
|
6
|
+
import * as pmtiles from 'pmtiles';
|
|
7
|
+
const {PMTiles, TileType} = pmtiles;
|
|
6
8
|
|
|
7
9
|
/** Metadata describing a PMTiles file */
|
|
8
10
|
export type PMTilesMetadata = {
|
|
@@ -15,7 +17,7 @@ export type PMTilesMetadata = {
|
|
|
15
17
|
/** Version of pm tiles format used by this tileset */
|
|
16
18
|
formatVersion: number;
|
|
17
19
|
/** PMTiles format specific header */
|
|
18
|
-
formatHeader?: Header;
|
|
20
|
+
formatHeader?: pmtiles.Header;
|
|
19
21
|
/** MIME type for tile contents. Unknown tile types will return 'application/octet-stream */
|
|
20
22
|
mimeType:
|
|
21
23
|
| 'application/vnd.mapbox-vector-tile'
|
|
@@ -25,7 +27,7 @@ export type PMTilesMetadata = {
|
|
|
25
27
|
| 'image/avif'
|
|
26
28
|
| 'application/octet-stream';
|
|
27
29
|
/** The original numeric tile type constant specified in the PMTiles tileset */
|
|
28
|
-
tileType: TileType;
|
|
30
|
+
tileType: pmtiles.TileType;
|
|
29
31
|
/** Minimal zoom level of tiles in this tileset */
|
|
30
32
|
minZoom: number;
|
|
31
33
|
/** Maximal zoom level of tiles in this tileset */
|
|
@@ -47,7 +49,7 @@ export type ParsePMTilesOptions = {
|
|
|
47
49
|
tileZxy?: [number, number, number];
|
|
48
50
|
};
|
|
49
51
|
|
|
50
|
-
export async function loadPMTilesHeader(source: Source): Promise<PMTilesMetadata> {
|
|
52
|
+
export async function loadPMTilesHeader(source: pmtiles.Source): Promise<PMTilesMetadata> {
|
|
51
53
|
const pmTiles = new PMTiles(source);
|
|
52
54
|
const header = await pmTiles.getHeader();
|
|
53
55
|
const metadata = await pmTiles.getMetadata();
|
|
@@ -59,7 +61,7 @@ export async function loadPMTilesHeader(source: Source): Promise<PMTilesMetadata
|
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
export async function loadPMTile(
|
|
62
|
-
source: Source,
|
|
64
|
+
source: pmtiles.Source,
|
|
63
65
|
options: ParsePMTilesOptions
|
|
64
66
|
): Promise<ArrayBuffer | undefined> {
|
|
65
67
|
const pmTiles = new PMTiles(source);
|
|
@@ -72,7 +74,7 @@ export async function loadPMTile(
|
|
|
72
74
|
}
|
|
73
75
|
|
|
74
76
|
export function parsePMTilesHeader(
|
|
75
|
-
header: Header,
|
|
77
|
+
header: pmtiles.Header,
|
|
76
78
|
tilejsonMetadata: Record<string, unknown> | null,
|
|
77
79
|
options?: {includeFormatHeader?: boolean}
|
|
78
80
|
): PMTilesMetadata {
|
|
@@ -122,7 +124,7 @@ export function parsePMTilesHeader(
|
|
|
122
124
|
|
|
123
125
|
/** Extract a MIME type for tiles from vector tile header */
|
|
124
126
|
function decodeTileType(
|
|
125
|
-
tileType: TileType
|
|
127
|
+
tileType: pmtiles.TileType
|
|
126
128
|
):
|
|
127
129
|
| 'application/vnd.mapbox-vector-tile'
|
|
128
130
|
| 'image/png'
|
package/src/pmtiles-source.ts
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
1
|
// loaders.gl, MIT license
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type {TileLoadParameters, GetTileParameters} from '@loaders.gl/loader-utils';
|
|
4
|
+
import type {ImageType, DataSourceProps} from '@loaders.gl/loader-utils';
|
|
4
5
|
import type {ImageTileSource, VectorTileSource} from '@loaders.gl/loader-utils';
|
|
5
6
|
import {DataSource, resolvePath} from '@loaders.gl/loader-utils';
|
|
6
7
|
import {ImageLoader} from '@loaders.gl/images';
|
|
7
8
|
import {MVTLoader, MVTLoaderOptions} from '@loaders.gl/mvt';
|
|
8
9
|
|
|
9
|
-
import {PMTiles, Source, RangeResponse} from 'pmtiles';
|
|
10
|
-
|
|
11
10
|
import type {PMTilesMetadata} from './lib/parse-pmtiles';
|
|
12
11
|
import {parsePMTilesHeader} from './lib/parse-pmtiles';
|
|
13
|
-
import {TileLoadParameters} from 'modules/loader-utils/src/lib/sources/tile-source';
|
|
14
|
-
|
|
15
|
-
// export const PMTilesService: Service = {
|
|
16
|
-
// name: 'PMTiles',
|
|
17
|
-
// id: 'pmtiles',
|
|
18
|
-
// module: 'pmtiles',
|
|
19
|
-
// // version: VERSION,
|
|
20
|
-
// extensions: ['pmtiles'],
|
|
21
|
-
// mimeTypes: ['application/octet-stream'],
|
|
22
|
-
// options: {
|
|
23
|
-
// pmtiles: {}
|
|
24
|
-
// }
|
|
25
|
-
// };
|
|
26
12
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
13
|
+
import * as pmtiles from 'pmtiles';
|
|
14
|
+
const {PMTiles} = pmtiles;
|
|
15
|
+
|
|
16
|
+
const VERSION = '1.0.0';
|
|
17
|
+
|
|
18
|
+
export type Service = {
|
|
19
|
+
name: string;
|
|
20
|
+
id: string;
|
|
21
|
+
module: string;
|
|
22
|
+
version: string;
|
|
23
|
+
extensions: string[];
|
|
24
|
+
mimeTypes: string[];
|
|
25
|
+
options: Record<string, unknown>;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type ServiceWithSource<SourceT, SourcePropsT> = Service & {
|
|
29
|
+
_source?: SourceT;
|
|
30
|
+
_sourceProps?: SourcePropsT;
|
|
31
|
+
createSource: (props: SourcePropsT) => SourceT;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const PMTilesService: ServiceWithSource<PMTilesSource, PMTilesSourceProps> = {
|
|
31
35
|
name: 'PMTiles',
|
|
32
36
|
id: 'pmtiles',
|
|
33
37
|
module: 'pmtiles',
|
|
34
38
|
version: VERSION,
|
|
35
|
-
worker: true,
|
|
36
39
|
extensions: ['pmtiles'],
|
|
37
40
|
mimeTypes: ['application/octet-stream'],
|
|
38
41
|
options: {
|
|
39
42
|
pmtiles: {}
|
|
40
43
|
},
|
|
41
|
-
|
|
42
|
-
throw new Error('not implemented');
|
|
43
|
-
}
|
|
44
|
+
createSource: (props: PMTilesSourceProps) => new PMTilesSource(props)
|
|
44
45
|
};
|
|
45
|
-
*/
|
|
46
46
|
|
|
47
47
|
export type PMTilesSourceProps = DataSourceProps & {
|
|
48
48
|
url: string | Blob;
|
|
49
49
|
attributions?: string[];
|
|
50
50
|
};
|
|
51
51
|
|
|
52
|
-
export class BlobSource implements Source {
|
|
52
|
+
export class BlobSource implements pmtiles.Source {
|
|
53
53
|
blob: Blob;
|
|
54
54
|
key: string;
|
|
55
55
|
|
|
@@ -64,7 +64,11 @@ export class BlobSource implements Source {
|
|
|
64
64
|
return this.blob.url || '';
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
async getBytes(
|
|
67
|
+
async getBytes(
|
|
68
|
+
offset: number,
|
|
69
|
+
length: number,
|
|
70
|
+
signal?: AbortSignal
|
|
71
|
+
): Promise<pmtiles.RangeResponse> {
|
|
68
72
|
const slice = this.blob.slice(offset, offset + length);
|
|
69
73
|
const data = await slice.arrayBuffer();
|
|
70
74
|
return {
|
|
@@ -81,7 +85,7 @@ export class BlobSource implements Source {
|
|
|
81
85
|
*/
|
|
82
86
|
export class PMTilesSource extends DataSource implements ImageTileSource, VectorTileSource {
|
|
83
87
|
props: PMTilesSourceProps;
|
|
84
|
-
pmtiles: PMTiles;
|
|
88
|
+
pmtiles: pmtiles.PMTiles;
|
|
85
89
|
metadata: Promise<PMTilesMetadata>;
|
|
86
90
|
|
|
87
91
|
constructor(props: PMTilesSourceProps) {
|
package/dist/bundle.d.ts
DELETED
package/dist/bundle.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AACA,QAAA,MAAM,aAAa,KAAqB,CAAC"}
|