@versatiles/versatiles-rs 3.0.2 → 3.0.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/README.md +109 -77
- package/index.cjs +580 -0
- package/index.d.ts +1141 -0
- package/index.js +584 -0
- package/package.json +14 -10
- package/versatiles.linux-x64-gnu.node +0 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,1141 @@
|
|
|
1
|
+
/* auto-generated by NAPI-RS */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* Progress monitor for long-running operations
|
|
5
|
+
*
|
|
6
|
+
* This class allows monitoring the progress of tile conversion and other
|
|
7
|
+
* long-running operations through event listeners.
|
|
8
|
+
*/
|
|
9
|
+
export declare class Progress {
|
|
10
|
+
/**
|
|
11
|
+
* Register a progress event listener
|
|
12
|
+
*
|
|
13
|
+
* The callback receives ProgressData with position, total, percentage, speed, eta, and message.
|
|
14
|
+
* The eta field is a JavaScript Date object representing the estimated time of completion.
|
|
15
|
+
*/
|
|
16
|
+
onProgress(callback: (data: ProgressData) => void): this
|
|
17
|
+
/**
|
|
18
|
+
* Register a message event listener for step, warning, and error messages
|
|
19
|
+
*
|
|
20
|
+
* The callback receives (type, message) where type is 'step', 'warning', or 'error'
|
|
21
|
+
*/
|
|
22
|
+
onMessage(callback: (type: string, message: string) => void): this
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Information about the tile source type and origin
|
|
27
|
+
*
|
|
28
|
+
* Provides metadata about how the tile source was created and what it represents.
|
|
29
|
+
* This is useful for debugging and understanding the source of tiles being served.
|
|
30
|
+
*
|
|
31
|
+
* # Source Kinds
|
|
32
|
+
*
|
|
33
|
+
* - **Container**: A file-based tile container (MBTiles, PMTiles, VersaTiles, TAR, or directory)
|
|
34
|
+
* - **Processor**: A tile source with transformations applied (e.g., from VPL pipelines)
|
|
35
|
+
* - **Composite**: Multiple tile sources combined together
|
|
36
|
+
*
|
|
37
|
+
* # Properties
|
|
38
|
+
*
|
|
39
|
+
* All source types have:
|
|
40
|
+
* - `kind`: The type of source ("container", "processor", or "composite")
|
|
41
|
+
* - `name`: A descriptive name for the source
|
|
42
|
+
*
|
|
43
|
+
* Container sources also have:
|
|
44
|
+
* - `uri`: The file path or URL of the container
|
|
45
|
+
*
|
|
46
|
+
* Processor sources also have:
|
|
47
|
+
* - `input`: The source being processed
|
|
48
|
+
*
|
|
49
|
+
* Composite sources also have:
|
|
50
|
+
* - `inputs`: Array of combined sources
|
|
51
|
+
*/
|
|
52
|
+
export declare class SourceType {
|
|
53
|
+
/**
|
|
54
|
+
* Get the kind of source
|
|
55
|
+
*
|
|
56
|
+
* Returns one of:
|
|
57
|
+
* - `"container"`: File-based tile container
|
|
58
|
+
* - `"processor"`: Transformed tile source (e.g., VPL pipeline)
|
|
59
|
+
* - `"composite"`: Multiple sources combined
|
|
60
|
+
*/
|
|
61
|
+
get kind(): string
|
|
62
|
+
/**
|
|
63
|
+
* Get the name of the source
|
|
64
|
+
*
|
|
65
|
+
* Returns a descriptive name indicating the source format or type.
|
|
66
|
+
* For containers, this is typically the format name (e.g., "MBTiles", "PMTiles").
|
|
67
|
+
* For processors, this describes the transformation (e.g., "filter", "transform").
|
|
68
|
+
*/
|
|
69
|
+
get name(): string
|
|
70
|
+
/**
|
|
71
|
+
* Get the file path or URL (for Container sources only)
|
|
72
|
+
*
|
|
73
|
+
* Returns the full path or URL of the tile container file.
|
|
74
|
+
* Returns `null` for Processor and Composite sources.
|
|
75
|
+
*
|
|
76
|
+
* # Example
|
|
77
|
+
*
|
|
78
|
+
* ```javascript
|
|
79
|
+
* const source = await TileSource.open('tiles.mbtiles');
|
|
80
|
+
* const type = source.sourceType();
|
|
81
|
+
* console.log(type.uri); // "/path/to/tiles.mbtiles"
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
get uri(): string | null
|
|
85
|
+
/**
|
|
86
|
+
* Get the input source being processed (for Processor sources only)
|
|
87
|
+
*
|
|
88
|
+
* Returns the source that this processor is transforming.
|
|
89
|
+
* Returns `null` for Container and Composite sources.
|
|
90
|
+
*
|
|
91
|
+
* # Example
|
|
92
|
+
*
|
|
93
|
+
* ```javascript
|
|
94
|
+
* const source = await TileSource.fromVpl(
|
|
95
|
+
* 'from_container filename="tiles.mbtiles" | filter level_min=5',
|
|
96
|
+
* '.'
|
|
97
|
+
* );
|
|
98
|
+
* const type = source.sourceType();
|
|
99
|
+
* console.log(type.kind); // "processor"
|
|
100
|
+
* console.log(type.name); // "filter"
|
|
101
|
+
* const inputType = type.input;
|
|
102
|
+
* console.log(inputType.kind); // "container"
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
get input(): SourceType | null
|
|
106
|
+
/**
|
|
107
|
+
* Get the array of combined sources (for Composite sources only)
|
|
108
|
+
*
|
|
109
|
+
* Returns an array of all sources that have been combined together.
|
|
110
|
+
* Returns `null` for Container and Processor sources.
|
|
111
|
+
*
|
|
112
|
+
* # Example
|
|
113
|
+
*
|
|
114
|
+
* ```javascript
|
|
115
|
+
* // For a composite source combining multiple tile sets
|
|
116
|
+
* const type = source.sourceType();
|
|
117
|
+
* if (type.kind === 'composite') {
|
|
118
|
+
* const sources = type.inputs;
|
|
119
|
+
* console.log(`Combined ${sources.length} tile sources`);
|
|
120
|
+
* }
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
get inputs(): Array<SourceType> | null
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Tile coordinate in the Web Mercator tile grid
|
|
128
|
+
*
|
|
129
|
+
* Represents a specific tile in the standard Web Mercator (EPSG:3857) tiling scheme.
|
|
130
|
+
* Uses XYZ coordinate convention where:
|
|
131
|
+
* - **z** (zoom): Zoom level (0-32), where 0 is the world in one tile
|
|
132
|
+
* - **x** (column): Tile column, from 0 (west) to 2^z - 1 (east)
|
|
133
|
+
* - **y** (row): Tile row, from 0 (north) to 2^z - 1 (south)
|
|
134
|
+
*
|
|
135
|
+
* # Coordinate System
|
|
136
|
+
*
|
|
137
|
+
* This implementation uses the **XYZ** (Slippy Map) convention:
|
|
138
|
+
* - Origin (0,0) is at the top-left (north-west)
|
|
139
|
+
* - Y increases going south
|
|
140
|
+
* - X increases going east
|
|
141
|
+
*
|
|
142
|
+
* Note: This differs from **TMS** (Tile Map Service) where Y increases going north.
|
|
143
|
+
* Use the `flipY` option in conversion if you need TMS coordinates.
|
|
144
|
+
*/
|
|
145
|
+
export declare class TileCoord {
|
|
146
|
+
/**
|
|
147
|
+
* Create a new tile coordinate
|
|
148
|
+
*
|
|
149
|
+
* # Arguments
|
|
150
|
+
*
|
|
151
|
+
* * `z` - Zoom level (0-32)
|
|
152
|
+
* * `x` - Tile column (0 to 2^z - 1)
|
|
153
|
+
* * `y` - Tile row (0 to 2^z - 1)
|
|
154
|
+
*
|
|
155
|
+
* # Errors
|
|
156
|
+
*
|
|
157
|
+
* Returns an error if coordinates are out of valid range for the zoom level.
|
|
158
|
+
* At zoom level z, valid coordinates are:
|
|
159
|
+
* - x: 0 to 2^z - 1
|
|
160
|
+
* - y: 0 to 2^z - 1
|
|
161
|
+
*
|
|
162
|
+
* # Examples
|
|
163
|
+
*
|
|
164
|
+
* ```javascript
|
|
165
|
+
* // Berlin tile at zoom 10
|
|
166
|
+
* const tile = new TileCoord(10, 550, 335);
|
|
167
|
+
*
|
|
168
|
+
* // World tile at zoom 0
|
|
169
|
+
* const world = new TileCoord(0, 0, 0);
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
constructor(z: number, x: number, y: number)
|
|
173
|
+
/**
|
|
174
|
+
* Create a tile coordinate from geographic coordinates
|
|
175
|
+
*
|
|
176
|
+
* Converts WGS84 latitude/longitude to the tile containing that point.
|
|
177
|
+
*
|
|
178
|
+
* # Arguments
|
|
179
|
+
*
|
|
180
|
+
* * `lon` - Longitude in decimal degrees (-180 to 180)
|
|
181
|
+
* * `lat` - Latitude in decimal degrees (-85.0511 to 85.0511)
|
|
182
|
+
* * `z` - Zoom level (0-32)
|
|
183
|
+
*
|
|
184
|
+
* # Returns
|
|
185
|
+
*
|
|
186
|
+
* The tile coordinate containing the specified geographic point
|
|
187
|
+
*
|
|
188
|
+
* # Errors
|
|
189
|
+
*
|
|
190
|
+
* Returns an error if coordinates are outside valid Web Mercator range.
|
|
191
|
+
* Valid latitude range is approximately ±85.05° (Web Mercator limit).
|
|
192
|
+
*
|
|
193
|
+
* # Examples
|
|
194
|
+
*
|
|
195
|
+
* ```javascript
|
|
196
|
+
* // Find tile containing Berlin city center
|
|
197
|
+
* const berlin = TileCoord.fromGeo(13.405, 52.520, 10);
|
|
198
|
+
* console.log(`Tile: ${berlin.z}/${berlin.x}/${berlin.y}`);
|
|
199
|
+
*
|
|
200
|
+
* // Find tile for New York City
|
|
201
|
+
* const nyc = TileCoord.fromGeo(-74.006, 40.7128, 12);
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
static fromGeo(lon: number, lat: number, z: number): TileCoord
|
|
205
|
+
/**
|
|
206
|
+
* Get the geographic center point of this tile
|
|
207
|
+
*
|
|
208
|
+
* Returns the WGS84 coordinates of the tile's center point.
|
|
209
|
+
*
|
|
210
|
+
* # Returns
|
|
211
|
+
*
|
|
212
|
+
* Array of `[longitude, latitude]` in decimal degrees
|
|
213
|
+
*
|
|
214
|
+
* # Examples
|
|
215
|
+
*
|
|
216
|
+
* ```javascript
|
|
217
|
+
* const tile = new TileCoord(10, 550, 335);
|
|
218
|
+
* const [lon, lat] = tile.toGeo();
|
|
219
|
+
* console.log(`Center: ${lat.toFixed(4)}°N, ${lon.toFixed(4)}°E`);
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
toGeo(): Array<number>
|
|
223
|
+
/**
|
|
224
|
+
* Get the geographic bounding box of this tile
|
|
225
|
+
*
|
|
226
|
+
* Returns the geographic extent of the tile in WGS84 coordinates.
|
|
227
|
+
*
|
|
228
|
+
* # Returns
|
|
229
|
+
*
|
|
230
|
+
* Array of `[west, south, east, north]` in decimal degrees:
|
|
231
|
+
* - **west**: Minimum longitude (left edge)
|
|
232
|
+
* - **south**: Minimum latitude (bottom edge)
|
|
233
|
+
* - **east**: Maximum longitude (right edge)
|
|
234
|
+
* - **north**: Maximum latitude (top edge)
|
|
235
|
+
*
|
|
236
|
+
* # Examples
|
|
237
|
+
*
|
|
238
|
+
* ```javascript
|
|
239
|
+
* const tile = new TileCoord(10, 550, 335);
|
|
240
|
+
* const [west, south, east, north] = tile.toGeoBbox();
|
|
241
|
+
* console.log(`Bbox: ${west},${south},${east},${north}`);
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
toGeoBbox(): Array<number>
|
|
245
|
+
/**
|
|
246
|
+
* Get the zoom level (0-32)
|
|
247
|
+
*
|
|
248
|
+
* Returns the tile's zoom level. At zoom 0, the entire world is one tile.
|
|
249
|
+
* Each zoom level doubles the number of tiles in each dimension.
|
|
250
|
+
*/
|
|
251
|
+
get z(): number
|
|
252
|
+
/**
|
|
253
|
+
* Get the tile column (x coordinate)
|
|
254
|
+
*
|
|
255
|
+
* Returns the horizontal position in the tile grid (0 to 2^z - 1).
|
|
256
|
+
* Lower values are further west, higher values are further east.
|
|
257
|
+
*/
|
|
258
|
+
get x(): number
|
|
259
|
+
/**
|
|
260
|
+
* Get the tile row (y coordinate)
|
|
261
|
+
*
|
|
262
|
+
* Returns the vertical position in the tile grid (0 to 2^z - 1).
|
|
263
|
+
* In XYZ convention: lower values are further north, higher values are further south.
|
|
264
|
+
*/
|
|
265
|
+
get y(): number
|
|
266
|
+
/**
|
|
267
|
+
* Convert to JSON string representation
|
|
268
|
+
*
|
|
269
|
+
* Returns a JSON object with z, x, and y properties.
|
|
270
|
+
*
|
|
271
|
+
* # Examples
|
|
272
|
+
*
|
|
273
|
+
* ```javascript
|
|
274
|
+
* const tile = new TileCoord(10, 550, 335);
|
|
275
|
+
* console.log(tile.toJson()); // '{"z":10,"x":550,"y":335}'
|
|
276
|
+
* ```
|
|
277
|
+
*/
|
|
278
|
+
toJson(): string
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* HTTP tile server for serving tiles and static content
|
|
283
|
+
*
|
|
284
|
+
* A high-performance HTTP server for serving map tiles and static files.
|
|
285
|
+
* Supports multiple tile sources with hot-reload capability, allowing you
|
|
286
|
+
* to add or remove tile sources without restarting the server.
|
|
287
|
+
*
|
|
288
|
+
* # URL Endpoints
|
|
289
|
+
*
|
|
290
|
+
* When a tile source named "osm" is added, the following endpoints become available:
|
|
291
|
+
* - `GET /tiles/osm/{z}/{x}/{y}` - Retrieve a tile
|
|
292
|
+
* - `GET /tiles/osm/tiles.json` - TileJSON metadata
|
|
293
|
+
*
|
|
294
|
+
* Static files are served according to their configured URL prefix.
|
|
295
|
+
*
|
|
296
|
+
* # Examples
|
|
297
|
+
*
|
|
298
|
+
* ```javascript
|
|
299
|
+
* const server = new TileServer({ port: 8080 });
|
|
300
|
+
*
|
|
301
|
+
* // Add tile sources
|
|
302
|
+
* await server.addTileSource('osm', 'tiles/osm.versatiles');
|
|
303
|
+
* await server.addTileSource('terrain', 'tiles/terrain.mbtiles');
|
|
304
|
+
*
|
|
305
|
+
* // Add static content
|
|
306
|
+
* await server.addStaticSource('public/', '/');
|
|
307
|
+
*
|
|
308
|
+
* // Start the server
|
|
309
|
+
* await server.start();
|
|
310
|
+
* console.log(`Server running on port ${await server.port}`);
|
|
311
|
+
*
|
|
312
|
+
* // Hot reload: add more sources while running
|
|
313
|
+
* await server.addTileSource('satellite', 'tiles/satellite.pmtiles');
|
|
314
|
+
*
|
|
315
|
+
* // Clean up
|
|
316
|
+
* await server.stop();
|
|
317
|
+
* ```
|
|
318
|
+
*/
|
|
319
|
+
export declare class TileServer {
|
|
320
|
+
/**
|
|
321
|
+
* Create a new tile server
|
|
322
|
+
*
|
|
323
|
+
* Creates a new HTTP tile server with the specified configuration.
|
|
324
|
+
* The server is not started until `start()` is called.
|
|
325
|
+
*
|
|
326
|
+
* # Arguments
|
|
327
|
+
*
|
|
328
|
+
* * `options` - Optional server configuration
|
|
329
|
+
* - `ip`: IP address to bind to (default: "0.0.0.0")
|
|
330
|
+
* - `port`: Port to listen on (default: 8080)
|
|
331
|
+
* - `minimalRecompression`: Use minimal recompression for better performance (default: false)
|
|
332
|
+
*
|
|
333
|
+
* # Examples
|
|
334
|
+
*
|
|
335
|
+
* ```javascript
|
|
336
|
+
* // Default settings (0.0.0.0:8080)
|
|
337
|
+
* const server = new TileServer();
|
|
338
|
+
*
|
|
339
|
+
* // Custom port
|
|
340
|
+
* const server = new TileServer({ port: 3000 });
|
|
341
|
+
*
|
|
342
|
+
* // Custom IP and port with minimal recompression
|
|
343
|
+
* const server = new TileServer({
|
|
344
|
+
* ip: '127.0.0.1',
|
|
345
|
+
* port: 8080,
|
|
346
|
+
* minimalRecompression: true
|
|
347
|
+
* });
|
|
348
|
+
* ```
|
|
349
|
+
*/
|
|
350
|
+
constructor(options?: ServerOptions | undefined | null)
|
|
351
|
+
/**
|
|
352
|
+
* Add a tile source to the server from a TileSource object
|
|
353
|
+
*
|
|
354
|
+
* The tiles will be served at /tiles/{name}/...
|
|
355
|
+
*
|
|
356
|
+
* This method supports all types of TileSources:
|
|
357
|
+
* - File-based sources (MBTiles, PMTiles, VersaTiles, TAR, directories) - support hot reload and server restart
|
|
358
|
+
* - VPL pipeline sources (e.g., filtered or transformed tiles) - must be added before server starts
|
|
359
|
+
*
|
|
360
|
+
* File-based sources can be added before or after starting the server (hot reload).
|
|
361
|
+
* VPL sources must be added before calling start() and will be consumed when the server starts.
|
|
362
|
+
*/
|
|
363
|
+
addTileSource(name: string, source: TileSource): Promise<void>
|
|
364
|
+
/**
|
|
365
|
+
* Add a tile source to the server from a file path
|
|
366
|
+
*
|
|
367
|
+
* The tiles will be served at /tiles/{name}/...
|
|
368
|
+
* Sources can be added before or after starting the server.
|
|
369
|
+
* Changes take effect immediately without requiring a restart (hot reload).
|
|
370
|
+
*/
|
|
371
|
+
addTileSourceFromPath(name: string, path: string): Promise<void>
|
|
372
|
+
/**
|
|
373
|
+
* Remove a tile source from the server
|
|
374
|
+
*
|
|
375
|
+
* Changes take effect immediately without requiring a restart (hot reload).
|
|
376
|
+
* Returns true if the source was found and removed, false otherwise.
|
|
377
|
+
*/
|
|
378
|
+
removeTileSource(name: string): Promise<boolean>
|
|
379
|
+
/**
|
|
380
|
+
* Add a static file source to the server
|
|
381
|
+
*
|
|
382
|
+
* Serves static files from a path (can be a .tar or directory)
|
|
383
|
+
* Changes take effect immediately without requiring a restart (hot reload).
|
|
384
|
+
*/
|
|
385
|
+
addStaticSource(path: string, urlPrefix?: string | undefined | null): Promise<void>
|
|
386
|
+
/**
|
|
387
|
+
* Remove a static file source from the server by URL prefix
|
|
388
|
+
*
|
|
389
|
+
* Changes take effect immediately without requiring a restart (hot reload).
|
|
390
|
+
* Returns true if the source was found and removed, false otherwise.
|
|
391
|
+
*/
|
|
392
|
+
removeStaticSource(urlPrefix: string): Promise<boolean>
|
|
393
|
+
/**
|
|
394
|
+
* Start the HTTP server
|
|
395
|
+
*
|
|
396
|
+
* Starts the HTTP server and begins listening for requests on the configured
|
|
397
|
+
* IP address and port. All tile and static sources that have been added will
|
|
398
|
+
* be immediately available.
|
|
399
|
+
*
|
|
400
|
+
* # Returns
|
|
401
|
+
*
|
|
402
|
+
* Returns `Ok(())` if the server started successfully
|
|
403
|
+
*
|
|
404
|
+
* # Errors
|
|
405
|
+
*
|
|
406
|
+
* Returns an error if:
|
|
407
|
+
* - The server is already running
|
|
408
|
+
* - The port is already in use
|
|
409
|
+
* - Unable to bind to the specified IP address
|
|
410
|
+
* - Configuration is invalid
|
|
411
|
+
*
|
|
412
|
+
* # Examples
|
|
413
|
+
*
|
|
414
|
+
* ```javascript
|
|
415
|
+
* const server = new TileServer({ port: 8080 });
|
|
416
|
+
* await server.addTileSource('osm', 'tiles.versatiles');
|
|
417
|
+
* await server.start();
|
|
418
|
+
* console.log('Server started successfully');
|
|
419
|
+
* ```
|
|
420
|
+
*/
|
|
421
|
+
start(): Promise<void>
|
|
422
|
+
/**
|
|
423
|
+
* Stop the HTTP server gracefully
|
|
424
|
+
*
|
|
425
|
+
* Gracefully shuts down the HTTP server, completing any in-flight requests
|
|
426
|
+
* before closing. After stopping, the server can be restarted by calling
|
|
427
|
+
* `start()` again.
|
|
428
|
+
*
|
|
429
|
+
* If the server is not running, this method does nothing and returns successfully.
|
|
430
|
+
*
|
|
431
|
+
* # Examples
|
|
432
|
+
*
|
|
433
|
+
* ```javascript
|
|
434
|
+
* await server.start();
|
|
435
|
+
* // ... server is running ...
|
|
436
|
+
* await server.stop();
|
|
437
|
+
* console.log('Server stopped');
|
|
438
|
+
*
|
|
439
|
+
* // Can restart later
|
|
440
|
+
* await server.start();
|
|
441
|
+
* ```
|
|
442
|
+
*/
|
|
443
|
+
stop(): Promise<void>
|
|
444
|
+
/**
|
|
445
|
+
* Get the port the server is listening on
|
|
446
|
+
*
|
|
447
|
+
* Returns the port number the server is configured to use or is currently
|
|
448
|
+
* listening on. If the server was configured with port 0 (ephemeral port),
|
|
449
|
+
* this will return the actual port assigned by the operating system after
|
|
450
|
+
* the server has started.
|
|
451
|
+
*
|
|
452
|
+
* # Returns
|
|
453
|
+
*
|
|
454
|
+
* The port number (1-65535)
|
|
455
|
+
*
|
|
456
|
+
* # Examples
|
|
457
|
+
*
|
|
458
|
+
* ```javascript
|
|
459
|
+
* const server = new TileServer({ port: 8080 });
|
|
460
|
+
* console.log(`Configured port: ${await server.port}`); // 8080
|
|
461
|
+
*
|
|
462
|
+
* await server.start();
|
|
463
|
+
* console.log(`Server listening on port: ${await server.port}`); // 8080
|
|
464
|
+
* ```
|
|
465
|
+
*/
|
|
466
|
+
get port(): Promise<number>
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* Container reader for accessing tile data from various formats
|
|
471
|
+
*
|
|
472
|
+
* Provides async methods to read tiles and metadata from supported container formats.
|
|
473
|
+
* All operations are thread-safe and can be called concurrently from multiple tasks.
|
|
474
|
+
*
|
|
475
|
+
* # Supported Formats
|
|
476
|
+
*
|
|
477
|
+
* **Local files:**
|
|
478
|
+
* - `.versatiles` - VersaTiles native format
|
|
479
|
+
* - `.mbtiles` - MBTiles (SQLite-based)
|
|
480
|
+
* - `.pmtiles` - PMTiles (cloud-optimized)
|
|
481
|
+
* - `.tar` - TAR archives
|
|
482
|
+
* - Directories - Standard tile directory structure
|
|
483
|
+
*
|
|
484
|
+
* **Remote URLs:**
|
|
485
|
+
* - `.versatiles` files via HTTP/HTTPS
|
|
486
|
+
* - `.pmtiles` files via HTTP/HTTPS (with range request support)
|
|
487
|
+
*/
|
|
488
|
+
export declare class TileSource {
|
|
489
|
+
/**
|
|
490
|
+
* Open a tile container from a file path or URL
|
|
491
|
+
*
|
|
492
|
+
* Automatically detects the container format based on the file extension
|
|
493
|
+
* or content. Supports both local files and remote URLs.
|
|
494
|
+
*
|
|
495
|
+
* # Arguments
|
|
496
|
+
*
|
|
497
|
+
* * `path` - File path or URL to the tile container
|
|
498
|
+
*
|
|
499
|
+
* # Returns
|
|
500
|
+
*
|
|
501
|
+
* A `ContainerReader` instance ready to read tiles
|
|
502
|
+
*
|
|
503
|
+
* # Errors
|
|
504
|
+
*
|
|
505
|
+
* Returns an error if:
|
|
506
|
+
* - The file or URL doesn't exist or is inaccessible
|
|
507
|
+
* - The format is not recognized or supported
|
|
508
|
+
* - The file is corrupted or invalid
|
|
509
|
+
*
|
|
510
|
+
* # Examples
|
|
511
|
+
*
|
|
512
|
+
* ```javascript
|
|
513
|
+
* // Open local file
|
|
514
|
+
* const reader = await ContainerReader.open('tiles.versatiles');
|
|
515
|
+
*
|
|
516
|
+
* // Open remote file
|
|
517
|
+
* const reader = await ContainerReader.open('https://example.com/tiles.pmtiles');
|
|
518
|
+
* ```
|
|
519
|
+
*/
|
|
520
|
+
static open(path: string): Promise<TileSource>
|
|
521
|
+
/**
|
|
522
|
+
* Create a TileSource from a VPL (VersaTiles Pipeline Language) string
|
|
523
|
+
*
|
|
524
|
+
* VPL allows you to define tile processing pipelines that can filter, transform,
|
|
525
|
+
* and combine tile sources. This is useful for on-the-fly tile manipulation without
|
|
526
|
+
* creating intermediate files.
|
|
527
|
+
*
|
|
528
|
+
* # Arguments
|
|
529
|
+
*
|
|
530
|
+
* * `vpl` - VPL pipeline definition string
|
|
531
|
+
* * `dir` - Optional base directory for resolving relative file paths in the VPL.
|
|
532
|
+
* Defaults to the current working directory if not specified.
|
|
533
|
+
*
|
|
534
|
+
* # VPL Operations
|
|
535
|
+
*
|
|
536
|
+
* Common VPL operations include:
|
|
537
|
+
* - `from_container filename="..."` - Load tiles from a container file
|
|
538
|
+
* - `filter level_min=X level_max=Y` - Filter by zoom levels
|
|
539
|
+
* - `filter bbox=[west,south,east,north]` - Filter by geographic bounds
|
|
540
|
+
* - Pipeline operators can be chained with `|`
|
|
541
|
+
*
|
|
542
|
+
* # Returns
|
|
543
|
+
*
|
|
544
|
+
* A `TileSource` instance representing the VPL pipeline
|
|
545
|
+
*
|
|
546
|
+
* # Errors
|
|
547
|
+
*
|
|
548
|
+
* Returns an error if:
|
|
549
|
+
* - The VPL syntax is invalid
|
|
550
|
+
* - Referenced files don't exist or are inaccessible
|
|
551
|
+
* - Pipeline operations are incompatible
|
|
552
|
+
*
|
|
553
|
+
* # Examples
|
|
554
|
+
*
|
|
555
|
+
* ```javascript
|
|
556
|
+
* // Simple container loading with explicit directory
|
|
557
|
+
* const source = await TileSource.fromVpl(
|
|
558
|
+
* 'from_container filename="tiles.mbtiles"',
|
|
559
|
+
* '/path/to/tiles'
|
|
560
|
+
* );
|
|
561
|
+
*
|
|
562
|
+
* // Using current directory (omit second argument)
|
|
563
|
+
* const source2 = await TileSource.fromVpl(
|
|
564
|
+
* 'from_container filename="tiles.mbtiles"'
|
|
565
|
+
* );
|
|
566
|
+
*
|
|
567
|
+
* // Filter by zoom level
|
|
568
|
+
* const filtered = await TileSource.fromVpl(
|
|
569
|
+
* 'from_container filename="tiles.mbtiles" | filter level_min=5 level_max=10',
|
|
570
|
+
* '/path/to/tiles'
|
|
571
|
+
* );
|
|
572
|
+
*
|
|
573
|
+
* // Filter by geographic area
|
|
574
|
+
* const berlin = await TileSource.fromVpl(
|
|
575
|
+
* 'from_container filename="world.mbtiles" | filter bbox=[13.0,52.0,14.0,53.0]',
|
|
576
|
+
* '/path/to/tiles'
|
|
577
|
+
* );
|
|
578
|
+
* ```
|
|
579
|
+
*
|
|
580
|
+
* # Note
|
|
581
|
+
*
|
|
582
|
+
* VPL sources cannot be converted using `convertTo()` since they may represent
|
|
583
|
+
* complex pipelines. To convert VPL output, use the `convert()` function instead.
|
|
584
|
+
*/
|
|
585
|
+
static fromVpl(vpl: string, dir?: string | undefined | null): Promise<TileSource>
|
|
586
|
+
/**
|
|
587
|
+
* Convert this tile source to another format
|
|
588
|
+
*
|
|
589
|
+
* Converts the current tile source to a different container format with optional
|
|
590
|
+
* filtering, transformation, and compression changes. Supports real-time progress
|
|
591
|
+
* monitoring through callback functions.
|
|
592
|
+
*
|
|
593
|
+
* # Arguments
|
|
594
|
+
*
|
|
595
|
+
* * `output` - Path to the output tile container
|
|
596
|
+
* * `options` - Optional conversion options (zoom range, bbox, compression, etc.)
|
|
597
|
+
* * `on_progress` - Optional callback for progress updates
|
|
598
|
+
* * `on_message` - Optional callback for step/warning/error messages
|
|
599
|
+
*
|
|
600
|
+
* # Conversion Options
|
|
601
|
+
*
|
|
602
|
+
* - `minZoom` / `maxZoom`: Filter to specific zoom levels
|
|
603
|
+
* - `bbox`: Geographic bounding box `[west, south, east, north]`
|
|
604
|
+
* - `bboxBorder`: Add border tiles around bbox (in tile units)
|
|
605
|
+
* - `compress`: Output compression ("gzip", "brotli", "uncompressed")
|
|
606
|
+
* - `flipY`: Flip tiles vertically (TMS ↔ XYZ coordinate systems)
|
|
607
|
+
* - `swapXY`: Swap X and Y tile coordinates
|
|
608
|
+
*
|
|
609
|
+
* # Progress Callbacks
|
|
610
|
+
*
|
|
611
|
+
* **onProgress callback** receives:
|
|
612
|
+
* - `position`: Current tile count
|
|
613
|
+
* - `total`: Total tile count
|
|
614
|
+
* - `percentage`: Progress percentage (0-100)
|
|
615
|
+
* - `speed`: Processing speed (tiles/second)
|
|
616
|
+
* - `eta`: Estimated completion time (as JavaScript Date)
|
|
617
|
+
*
|
|
618
|
+
* **onMessage callback** receives:
|
|
619
|
+
* - `type`: Message type ("step", "warning", or "error")
|
|
620
|
+
* - `message`: The message text
|
|
621
|
+
*
|
|
622
|
+
* # Returns
|
|
623
|
+
*
|
|
624
|
+
* A Promise that resolves when conversion is complete
|
|
625
|
+
*
|
|
626
|
+
* # Errors
|
|
627
|
+
*
|
|
628
|
+
* Returns an error if:
|
|
629
|
+
* - Output path is invalid or not writable
|
|
630
|
+
* - Bbox coordinates are invalid (must be `[west, south, east, north]`)
|
|
631
|
+
* - Compression format is not recognized
|
|
632
|
+
* - An I/O error occurs during conversion
|
|
633
|
+
*
|
|
634
|
+
* # Examples
|
|
635
|
+
*
|
|
636
|
+
* ```javascript
|
|
637
|
+
* const source = await TileSource.open('input.mbtiles');
|
|
638
|
+
*
|
|
639
|
+
* // Simple conversion
|
|
640
|
+
* await source.convertTo('output.versatiles');
|
|
641
|
+
*
|
|
642
|
+
* // Convert with compression
|
|
643
|
+
* await source.convertTo('output.versatiles', {
|
|
644
|
+
* compress: 'brotli'
|
|
645
|
+
* });
|
|
646
|
+
*
|
|
647
|
+
* // Convert specific area and zoom range
|
|
648
|
+
* await source.convertTo('europe.versatiles', {
|
|
649
|
+
* minZoom: 0,
|
|
650
|
+
* maxZoom: 14,
|
|
651
|
+
* bbox: [-10, 35, 40, 70], // Europe
|
|
652
|
+
* bboxBorder: 1
|
|
653
|
+
* });
|
|
654
|
+
*
|
|
655
|
+
* // With progress monitoring
|
|
656
|
+
* await source.convertTo('output.versatiles', null,
|
|
657
|
+
* (progress) => {
|
|
658
|
+
* console.log(`${progress.percentage.toFixed(1)}% complete`);
|
|
659
|
+
* },
|
|
660
|
+
* (type, message) => {
|
|
661
|
+
* if (type === 'error') console.error(message);
|
|
662
|
+
* }
|
|
663
|
+
* );
|
|
664
|
+
* ```
|
|
665
|
+
*/
|
|
666
|
+
convertTo(output: string, options?: ConvertOptions | undefined | null, onProgress?: (((arg: ProgressData) => unknown)) | undefined | null, onMessage?: (((arg: MessageData) => unknown)) | undefined | null): Promise<void>
|
|
667
|
+
/**
|
|
668
|
+
* Get a single tile at the specified coordinates
|
|
669
|
+
*
|
|
670
|
+
* Retrieves the tile data for the given zoom level (z) and tile coordinates (x, y).
|
|
671
|
+
* The tile is automatically decompressed and returned as a Buffer.
|
|
672
|
+
*
|
|
673
|
+
* # Arguments
|
|
674
|
+
*
|
|
675
|
+
* * `z` - Zoom level (0-32)
|
|
676
|
+
* * `x` - Tile column (0 to 2^z - 1)
|
|
677
|
+
* * `y` - Tile row (0 to 2^z - 1)
|
|
678
|
+
*
|
|
679
|
+
* # Returns
|
|
680
|
+
*
|
|
681
|
+
* - `Some(Buffer)` containing the uncompressed tile data if the tile exists
|
|
682
|
+
* - `None` if the tile doesn't exist at these coordinates
|
|
683
|
+
*
|
|
684
|
+
* # Errors
|
|
685
|
+
*
|
|
686
|
+
* Returns an error if:
|
|
687
|
+
* - The coordinates are invalid (out of bounds for the zoom level)
|
|
688
|
+
* - An I/O error occurs while reading the tile
|
|
689
|
+
*
|
|
690
|
+
* # Examples
|
|
691
|
+
*
|
|
692
|
+
* ```javascript
|
|
693
|
+
* const tile = await reader.getTile(10, 512, 384);
|
|
694
|
+
* if (tile) {
|
|
695
|
+
* console.log(`Tile size: ${tile.length} bytes`);
|
|
696
|
+
* }
|
|
697
|
+
* ```
|
|
698
|
+
*/
|
|
699
|
+
getTile(z: number, x: number, y: number): Promise<Buffer | null>
|
|
700
|
+
/**
|
|
701
|
+
* Get TileJSON metadata as a JSON string
|
|
702
|
+
*
|
|
703
|
+
* Returns the container's metadata in TileJSON format, which includes
|
|
704
|
+
* information about tile bounds, zoom levels, attribution, and more.
|
|
705
|
+
*
|
|
706
|
+
* # Returns
|
|
707
|
+
*
|
|
708
|
+
* A JSON string containing TileJSON metadata
|
|
709
|
+
*
|
|
710
|
+
* # Examples
|
|
711
|
+
*
|
|
712
|
+
* ```javascript
|
|
713
|
+
* const tileJson = await reader.tileJson();
|
|
714
|
+
* const metadata = JSON.parse(tileJson);
|
|
715
|
+
* console.log(`Zoom range: ${metadata.minzoom} - ${metadata.maxzoom}`);
|
|
716
|
+
* ```
|
|
717
|
+
*/
|
|
718
|
+
tileJson(): TileJSON
|
|
719
|
+
/**
|
|
720
|
+
* Get reader metadata
|
|
721
|
+
*
|
|
722
|
+
* Returns detailed technical metadata about the tile container including
|
|
723
|
+
* format, compression, and available zoom levels.
|
|
724
|
+
*
|
|
725
|
+
* # Returns
|
|
726
|
+
*
|
|
727
|
+
* A [`SourceMetadata`] object containing:
|
|
728
|
+
* - `tileFormat`: The tile format (e.g., "png", "jpg", "mvt")
|
|
729
|
+
* - `tileCompression`: The compression method (e.g., "gzip", "brotli", "uncompressed")
|
|
730
|
+
* - `minZoom`: Minimum available zoom level
|
|
731
|
+
* - `maxZoom`: Maximum available zoom level
|
|
732
|
+
*
|
|
733
|
+
* # Examples
|
|
734
|
+
*
|
|
735
|
+
* ```javascript
|
|
736
|
+
* const metadata = await reader.metadata();
|
|
737
|
+
* console.log(`Format: ${metadata.tileFormat}`);
|
|
738
|
+
* console.log(`Compression: ${metadata.tileCompression}`);
|
|
739
|
+
* console.log(`Zoom: ${metadata.minZoom}-${metadata.maxZoom}`);
|
|
740
|
+
* ```
|
|
741
|
+
*/
|
|
742
|
+
metadata(): SourceMetadata
|
|
743
|
+
/**
|
|
744
|
+
* Get the source type
|
|
745
|
+
*
|
|
746
|
+
* Returns the name or path of the data source being read.
|
|
747
|
+
*
|
|
748
|
+
* # Returns
|
|
749
|
+
*
|
|
750
|
+
* The source type (typically the file path or URL)
|
|
751
|
+
*
|
|
752
|
+
* # Examples
|
|
753
|
+
*
|
|
754
|
+
* ```javascript
|
|
755
|
+
* const sourceType = await reader.sourceType();
|
|
756
|
+
* console.log(sourceType.kind); // "container", "processor", or "composite"
|
|
757
|
+
* console.log(sourceType.name); // e.g., "mbtiles"
|
|
758
|
+
* if (sourceType.kind === "container") {
|
|
759
|
+
* console.log(sourceType.uri); // file path or URL
|
|
760
|
+
* }
|
|
761
|
+
* ```
|
|
762
|
+
*/
|
|
763
|
+
sourceType(): SourceType
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
/**
|
|
767
|
+
* Convert tiles from one container format to another
|
|
768
|
+
*
|
|
769
|
+
* Converts tiles between different container formats with optional filtering,
|
|
770
|
+
* transformation, and compression changes. Supports real-time progress monitoring
|
|
771
|
+
* through callback functions.
|
|
772
|
+
*
|
|
773
|
+
* # Arguments
|
|
774
|
+
*
|
|
775
|
+
* * `input` - Path or URL to the input tile container
|
|
776
|
+
* * `output` - Path to the output tile container
|
|
777
|
+
* * `options` - Optional conversion options (zoom range, bbox, compression, etc.)
|
|
778
|
+
* * `on_progress` - Optional callback for progress updates
|
|
779
|
+
* * `on_message` - Optional callback for step/warning/error messages
|
|
780
|
+
*
|
|
781
|
+
* # Conversion Options
|
|
782
|
+
*
|
|
783
|
+
* - `minZoom` / `maxZoom`: Filter to specific zoom levels
|
|
784
|
+
* - `bbox`: Geographic bounding box `[west, south, east, north]`
|
|
785
|
+
* - `bboxBorder`: Add border tiles around bbox (in tile units)
|
|
786
|
+
* - `compress`: Output compression ("gzip", "brotli", "uncompressed")
|
|
787
|
+
* - `flipY`: Flip tiles vertically (TMS ↔ XYZ coordinate systems)
|
|
788
|
+
* - `swapXY`: Swap X and Y tile coordinates
|
|
789
|
+
*
|
|
790
|
+
* # Progress Callbacks
|
|
791
|
+
*
|
|
792
|
+
* **onProgress callback** receives:
|
|
793
|
+
* - `position`: Current tile count
|
|
794
|
+
* - `total`: Total tile count
|
|
795
|
+
* - `percentage`: Progress percentage (0-100)
|
|
796
|
+
* - `speed`: Processing speed (tiles/second)
|
|
797
|
+
* - `eta`: Estimated completion time (as JavaScript Date)
|
|
798
|
+
*
|
|
799
|
+
* **onMessage callback** receives:
|
|
800
|
+
* - `type`: Message type ("step", "warning", or "error")
|
|
801
|
+
* - `message`: The message text
|
|
802
|
+
*
|
|
803
|
+
* # Returns
|
|
804
|
+
*
|
|
805
|
+
* A Promise that resolves when conversion is complete
|
|
806
|
+
*
|
|
807
|
+
* # Errors
|
|
808
|
+
*
|
|
809
|
+
* Returns an error if:
|
|
810
|
+
* - Input file/URL doesn't exist or is inaccessible
|
|
811
|
+
* - Output path is invalid or not writable
|
|
812
|
+
* - Bbox coordinates are invalid (must be `[west, south, east, north]`)
|
|
813
|
+
* - Compression format is not recognized
|
|
814
|
+
* - An I/O error occurs during conversion
|
|
815
|
+
*
|
|
816
|
+
* # Examples
|
|
817
|
+
*
|
|
818
|
+
* ```javascript
|
|
819
|
+
* // Simple conversion
|
|
820
|
+
* await convert('input.mbtiles', 'output.versatiles');
|
|
821
|
+
*
|
|
822
|
+
* // Convert with compression
|
|
823
|
+
* await convert('input.pmtiles', 'output.versatiles', {
|
|
824
|
+
* compress: 'brotli'
|
|
825
|
+
* });
|
|
826
|
+
*
|
|
827
|
+
* // Convert specific area and zoom range
|
|
828
|
+
* await convert('world.mbtiles', 'europe.versatiles', {
|
|
829
|
+
* minZoom: 0,
|
|
830
|
+
* maxZoom: 14,
|
|
831
|
+
* bbox: [-10, 35, 40, 70], // Europe
|
|
832
|
+
* bboxBorder: 1
|
|
833
|
+
* });
|
|
834
|
+
*
|
|
835
|
+
* // With progress monitoring
|
|
836
|
+
* await convert('input.tar', 'output.versatiles', null,
|
|
837
|
+
* (progress) => {
|
|
838
|
+
* console.log(`${progress.percentage.toFixed(1)}% complete`);
|
|
839
|
+
* console.log(`Speed: ${progress.speed.toFixed(0)} tiles/sec`);
|
|
840
|
+
* console.log(`ETA: ${new Date(progress.eta)}`);
|
|
841
|
+
* },
|
|
842
|
+
* (type, message) => {
|
|
843
|
+
* if (type === 'error') console.error(message);
|
|
844
|
+
* else if (type === 'warning') console.warn(message);
|
|
845
|
+
* else console.log(message);
|
|
846
|
+
* }
|
|
847
|
+
* );
|
|
848
|
+
* ```
|
|
849
|
+
*/
|
|
850
|
+
export declare function convert(input: string, output: string, options?: ConvertOptions | undefined | null, onProgress?: (((arg: ProgressData) => unknown)) | undefined | null, onMessage?: (((arg: MessageData) => unknown)) | undefined | null): Promise<void>
|
|
851
|
+
|
|
852
|
+
/**
|
|
853
|
+
* Options for tile conversion
|
|
854
|
+
*
|
|
855
|
+
* Configure how tiles are filtered, transformed, and compressed during conversion.
|
|
856
|
+
* All fields are optional - only specify the options you want to apply.
|
|
857
|
+
*/
|
|
858
|
+
export interface ConvertOptions {
|
|
859
|
+
/**
|
|
860
|
+
* Minimum zoom level to include (0-32)
|
|
861
|
+
*
|
|
862
|
+
* Tiles with zoom levels below this value will be excluded from the output.
|
|
863
|
+
* Must be less than or equal to `max_zoom` if both are specified.
|
|
864
|
+
*
|
|
865
|
+
* **Default:** No minimum filter (all zoom levels included)
|
|
866
|
+
*/
|
|
867
|
+
minZoom?: number
|
|
868
|
+
/**
|
|
869
|
+
* Maximum zoom level to include (0-32)
|
|
870
|
+
*
|
|
871
|
+
* Tiles with zoom levels above this value will be excluded from the output.
|
|
872
|
+
* Must be greater than or equal to `min_zoom` if both are specified.
|
|
873
|
+
*
|
|
874
|
+
* **Default:** No maximum filter (all zoom levels included)
|
|
875
|
+
*/
|
|
876
|
+
maxZoom?: number
|
|
877
|
+
/**
|
|
878
|
+
* Geographic bounding box filter in WGS84 coordinates
|
|
879
|
+
*
|
|
880
|
+
* Must be an array of exactly 4 numbers: `[west, south, east, north]`
|
|
881
|
+
* - **west**: Minimum longitude (-180 to 180)
|
|
882
|
+
* - **south**: Minimum latitude (-85.0511 to 85.0511)
|
|
883
|
+
* - **east**: Maximum longitude (-180 to 180)
|
|
884
|
+
* - **north**: Maximum latitude (-85.0511 to 85.0511)
|
|
885
|
+
*
|
|
886
|
+
* Only tiles that intersect this bounding box will be included.
|
|
887
|
+
* Coordinate system is WGS84 (EPSG:4326).
|
|
888
|
+
*
|
|
889
|
+
* **Example:** `[13.0, 52.0, 14.0, 53.0]` for Berlin area
|
|
890
|
+
*
|
|
891
|
+
* **Default:** No bounding box filter (world coverage)
|
|
892
|
+
*/
|
|
893
|
+
bbox?: Array<number>
|
|
894
|
+
/**
|
|
895
|
+
* Number of extra tiles to include around the bounding box
|
|
896
|
+
*
|
|
897
|
+
* Adds a buffer of tiles around the `bbox` at each zoom level.
|
|
898
|
+
* The value is in tile units, not geographic degrees.
|
|
899
|
+
* Useful for ensuring smooth rendering at the edges of the bounding box.
|
|
900
|
+
*
|
|
901
|
+
* **Example:** A value of `1` adds one tile border on each side
|
|
902
|
+
*
|
|
903
|
+
* **Default:** `0` (no border)
|
|
904
|
+
*/
|
|
905
|
+
bboxBorder?: number
|
|
906
|
+
/**
|
|
907
|
+
* Output tile compression format
|
|
908
|
+
*
|
|
909
|
+
* Valid values:
|
|
910
|
+
* - `"gzip"`: Good compression ratio, widely supported
|
|
911
|
+
* - `"brotli"`: Better compression than gzip, modern browsers only
|
|
912
|
+
* - `"uncompressed"`: No compression, fastest but largest files
|
|
913
|
+
*
|
|
914
|
+
* **Default:** Preserves the source compression format
|
|
915
|
+
*/
|
|
916
|
+
compress?: string
|
|
917
|
+
/**
|
|
918
|
+
* Flip tiles vertically (swap TMS ↔ XYZ coordinate systems)
|
|
919
|
+
*
|
|
920
|
+
* - **TMS** (Tile Map Service): Y increases from south to north (origin at bottom-left)
|
|
921
|
+
* - **XYZ**: Y increases from north to south (origin at top-left)
|
|
922
|
+
*
|
|
923
|
+
* Set to `true` to convert between these coordinate systems.
|
|
924
|
+
*
|
|
925
|
+
* **Default:** `false` (no flipping)
|
|
926
|
+
*/
|
|
927
|
+
flipY?: boolean
|
|
928
|
+
/**
|
|
929
|
+
* Swap X and Y tile coordinates
|
|
930
|
+
*
|
|
931
|
+
* Exchanges the column (x) and row (y) coordinates of each tile.
|
|
932
|
+
* Rarely needed except for specialized coordinate transformations.
|
|
933
|
+
*
|
|
934
|
+
* **Default:** `false` (no swapping)
|
|
935
|
+
*/
|
|
936
|
+
swapXy?: boolean
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
/**
|
|
940
|
+
* Status or diagnostic message from an operation
|
|
941
|
+
*
|
|
942
|
+
* Provides step updates, warnings, and errors during processing.
|
|
943
|
+
*/
|
|
944
|
+
export interface MessageData {
|
|
945
|
+
/**
|
|
946
|
+
* Message type
|
|
947
|
+
*
|
|
948
|
+
* One of:
|
|
949
|
+
* - `"step"`: Normal progress step or status update
|
|
950
|
+
* - `"warning"`: Non-fatal issue that doesn't stop the operation
|
|
951
|
+
* - `"error"`: Fatal error that causes operation failure
|
|
952
|
+
*/
|
|
953
|
+
type: string
|
|
954
|
+
/**
|
|
955
|
+
* The message text
|
|
956
|
+
*
|
|
957
|
+
* Human-readable description of the step, warning, or error.
|
|
958
|
+
*/
|
|
959
|
+
message: string
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
/** Probe result with container information */
|
|
963
|
+
export interface ProbeResult {
|
|
964
|
+
/** Source name or path */
|
|
965
|
+
sourceName: string
|
|
966
|
+
/** Container type (e.g., "mbtiles", "versatiles") */
|
|
967
|
+
containerName: string
|
|
968
|
+
/** TileJSON metadata as JSON string */
|
|
969
|
+
tileJson: string
|
|
970
|
+
/** Reader parameters */
|
|
971
|
+
parameters: SourceMetadata
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
/**
|
|
975
|
+
* Progress information for long-running operations
|
|
976
|
+
*
|
|
977
|
+
* Provides real-time progress updates during tile conversion and other
|
|
978
|
+
* operations. All numeric values are floating-point for precision.
|
|
979
|
+
*/
|
|
980
|
+
export interface ProgressData {
|
|
981
|
+
/**
|
|
982
|
+
* Current position in the operation
|
|
983
|
+
*
|
|
984
|
+
* Number of items (tiles, bytes, etc.) that have been processed so far.
|
|
985
|
+
* Compare with `total` to determine progress.
|
|
986
|
+
*/
|
|
987
|
+
position: number
|
|
988
|
+
/**
|
|
989
|
+
* Total number of items to process
|
|
990
|
+
*
|
|
991
|
+
* The expected total number of items for the complete operation.
|
|
992
|
+
* May be an estimate and could change during processing.
|
|
993
|
+
*/
|
|
994
|
+
total: number
|
|
995
|
+
/**
|
|
996
|
+
* Completion percentage (0-100)
|
|
997
|
+
*
|
|
998
|
+
* Calculated as `(position / total) * 100`.
|
|
999
|
+
* Useful for displaying progress bars.
|
|
1000
|
+
*
|
|
1001
|
+
* **Example:** `50.5` means 50.5% complete
|
|
1002
|
+
*/
|
|
1003
|
+
percentage: number
|
|
1004
|
+
/**
|
|
1005
|
+
* Processing speed in items per second
|
|
1006
|
+
*
|
|
1007
|
+
* Average speed calculated from operation start.
|
|
1008
|
+
* Units match the operation (tiles/sec, bytes/sec, etc.).
|
|
1009
|
+
*
|
|
1010
|
+
* **Example:** `1523.4` means 1523.4 items per second
|
|
1011
|
+
*/
|
|
1012
|
+
speed: number
|
|
1013
|
+
/**
|
|
1014
|
+
* Estimated seconds until completion
|
|
1015
|
+
*
|
|
1016
|
+
* Time remaining based on current speed and remaining items.
|
|
1017
|
+
* Returns `null` if insufficient data to estimate (early in operation).
|
|
1018
|
+
*
|
|
1019
|
+
* **Example:** `45.2` means approximately 45 seconds remaining
|
|
1020
|
+
*/
|
|
1021
|
+
estimatedSecondsRemaining?: number
|
|
1022
|
+
/**
|
|
1023
|
+
* Estimated completion time as JavaScript Date
|
|
1024
|
+
*
|
|
1025
|
+
* Timestamp in milliseconds since UNIX epoch (January 1, 1970).
|
|
1026
|
+
* Can be converted to a JavaScript Date object with `new Date(eta)`.
|
|
1027
|
+
* Returns `null` if insufficient data to estimate.
|
|
1028
|
+
*
|
|
1029
|
+
* **Example:**
|
|
1030
|
+
* ```javascript
|
|
1031
|
+
* if (progress.eta) {
|
|
1032
|
+
* const completionTime = new Date(progress.eta);
|
|
1033
|
+
* console.log(`Expected completion: ${completionTime.toLocaleTimeString()}`);
|
|
1034
|
+
* }
|
|
1035
|
+
* ```
|
|
1036
|
+
*/
|
|
1037
|
+
eta?: number
|
|
1038
|
+
/**
|
|
1039
|
+
* Current operation step or status message
|
|
1040
|
+
*
|
|
1041
|
+
* Descriptive text about what the operation is currently doing.
|
|
1042
|
+
*
|
|
1043
|
+
* **Examples:**
|
|
1044
|
+
* - `"Reading tiles"`
|
|
1045
|
+
* - `"Compressing data"`
|
|
1046
|
+
* - `"Writing output"`
|
|
1047
|
+
*/
|
|
1048
|
+
message?: string
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
/**
|
|
1052
|
+
* Configuration options for the tile server
|
|
1053
|
+
*
|
|
1054
|
+
* All fields are optional and will use sensible defaults if not specified.
|
|
1055
|
+
*/
|
|
1056
|
+
export interface ServerOptions {
|
|
1057
|
+
/**
|
|
1058
|
+
* IP address or hostname to bind to
|
|
1059
|
+
*
|
|
1060
|
+
* Determines which network interface the server listens on:
|
|
1061
|
+
* - `"0.0.0.0"`: Listen on all network interfaces (accessible from any network)
|
|
1062
|
+
* - `"127.0.0.1"`: Listen only on localhost (local access only)
|
|
1063
|
+
* - Specific IP: Listen only on that interface
|
|
1064
|
+
*
|
|
1065
|
+
* **Security Note:** Using `"0.0.0.0"` makes the server accessible from the network.
|
|
1066
|
+
* Use `"127.0.0.1"` for development or when using a reverse proxy.
|
|
1067
|
+
*
|
|
1068
|
+
* **Default:** `"0.0.0.0"` (all interfaces)
|
|
1069
|
+
*/
|
|
1070
|
+
ip?: string
|
|
1071
|
+
/**
|
|
1072
|
+
* TCP port number to listen on (1-65535)
|
|
1073
|
+
*
|
|
1074
|
+
* The port where the HTTP server will accept connections.
|
|
1075
|
+
* - Use `0` to let the OS assign an available port automatically (ephemeral port)
|
|
1076
|
+
* - Ports below 1024 typically require administrator/root privileges
|
|
1077
|
+
* - Common choices: 8080, 3000, 8000
|
|
1078
|
+
*
|
|
1079
|
+
* **Default:** `8080`
|
|
1080
|
+
*/
|
|
1081
|
+
port?: number
|
|
1082
|
+
/**
|
|
1083
|
+
* Enable minimal recompression for improved performance
|
|
1084
|
+
*
|
|
1085
|
+
* When enabled, the server performs minimal tile recompression to match
|
|
1086
|
+
* client requirements, favoring speed over optimal compression ratio:
|
|
1087
|
+
* - Tiles are served with their original compression when possible
|
|
1088
|
+
* - Only recompresses when absolutely necessary for client compatibility
|
|
1089
|
+
* - Reduces CPU usage and improves response times
|
|
1090
|
+
* - May result in slightly larger tile sizes sent to clients
|
|
1091
|
+
*
|
|
1092
|
+
* When disabled (default), the server optimally recompresses tiles to match
|
|
1093
|
+
* the client's preferred compression format, which provides better bandwidth
|
|
1094
|
+
* efficiency but uses more CPU.
|
|
1095
|
+
*
|
|
1096
|
+
* **Recommended:** Enable for high-traffic servers or when CPU is limited.
|
|
1097
|
+
*
|
|
1098
|
+
* **Default:** `false` (optimal recompression)
|
|
1099
|
+
*/
|
|
1100
|
+
minimalRecompression?: boolean
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
/** Tile source metadata describing output characteristics */
|
|
1104
|
+
export interface SourceMetadata {
|
|
1105
|
+
/** Tile format (e.g., "png", "jpg", "mvt") */
|
|
1106
|
+
tileFormat: string
|
|
1107
|
+
/** Tile compression (e.g., "gzip", "brotli", "uncompressed") */
|
|
1108
|
+
tileCompression: string
|
|
1109
|
+
/** Minimum zoom level available */
|
|
1110
|
+
minZoom: number
|
|
1111
|
+
/** Maximum zoom level available */
|
|
1112
|
+
maxZoom: number
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
export interface TileJSON {
|
|
1116
|
+
tilejson: string
|
|
1117
|
+
minzoom: number
|
|
1118
|
+
maxzoom: number
|
|
1119
|
+
/** Geographic bounding box. If `Some`, `[west, south, east, north]`. */
|
|
1120
|
+
bounds?: Array<number>
|
|
1121
|
+
/** Geographic center. If `Some`, `[longitude, latitude, zoom_level]`. */
|
|
1122
|
+
center?: Array<number>
|
|
1123
|
+
/** The collection of vector layers, if any. */
|
|
1124
|
+
vectorLayers?: Array<VectorLayer>
|
|
1125
|
+
/** Optional tile content type derived from format (raster/vector/unknown). */
|
|
1126
|
+
tileType?: string
|
|
1127
|
+
/** Optional tile format (e.g., "image/png", "application/x-protobuf"). */
|
|
1128
|
+
tileFormat?: string
|
|
1129
|
+
/** Optional tile schema describing the expected layer/attribute structure. */
|
|
1130
|
+
tileSchema?: string
|
|
1131
|
+
/** Optional tile size in pixels (typically 256 or 512). */
|
|
1132
|
+
tileSize?: number
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
export interface VectorLayer {
|
|
1136
|
+
id: string
|
|
1137
|
+
fields: Record<string, string>
|
|
1138
|
+
description?: string
|
|
1139
|
+
minzoom?: number
|
|
1140
|
+
maxzoom?: number
|
|
1141
|
+
}
|