@versatiles/versatiles-rs 3.0.0
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 +379 -0
- package/package.json +92 -0
package/README.md
ADDED
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
# @versatiles/versatiles-rs
|
|
2
|
+
|
|
3
|
+
Node.js bindings for [VersaTiles](https://github.com/versatiles-org/versatiles-rs) - convert, serve, and process map tiles in various formats.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- π **Fast & Native** - Powered by Rust with zero-copy operations
|
|
8
|
+
- π **Format Conversion** - Convert between MBTiles, PMTiles, VersaTiles, TAR, and directories
|
|
9
|
+
- πΊοΈ **Tile Server** - Built-in HTTP tile server with dynamic source management
|
|
10
|
+
- π **Metadata Access** - Read TileJSON and inspect container details
|
|
11
|
+
- π **Coordinate Utils** - Convert between tile and geographic coordinates
|
|
12
|
+
- β‘ **Async API** - Non-blocking operations with Promise-based interface
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @versatiles/versatiles-rs
|
|
18
|
+
# or
|
|
19
|
+
yarn add @versatiles/versatiles-rs
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Pre-built binaries are available for:
|
|
23
|
+
|
|
24
|
+
- macOS (arm64, x64)
|
|
25
|
+
- Linux (x64, arm64, musl)
|
|
26
|
+
- Windows (x64)
|
|
27
|
+
|
|
28
|
+
## Quick Start
|
|
29
|
+
|
|
30
|
+
### Convert Tiles
|
|
31
|
+
|
|
32
|
+
```javascript
|
|
33
|
+
const { convertTiles } = require('@versatiles/versatiles-rs');
|
|
34
|
+
|
|
35
|
+
await convertTiles('input.mbtiles', 'output.versatiles', {
|
|
36
|
+
minZoom: 0,
|
|
37
|
+
maxZoom: 14,
|
|
38
|
+
bbox: [-180, -85, 180, 85],
|
|
39
|
+
compress: 'gzip',
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Serve Tiles
|
|
44
|
+
|
|
45
|
+
```javascript
|
|
46
|
+
const { TileServer } = require('@versatiles/versatiles-rs');
|
|
47
|
+
|
|
48
|
+
const server = new TileServer({ port: 8080 });
|
|
49
|
+
await server.addTileSource('osm', 'tiles.mbtiles');
|
|
50
|
+
await server.start();
|
|
51
|
+
|
|
52
|
+
console.log(`Server running at http://localhost:${await server.port}`);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Read Tiles
|
|
56
|
+
|
|
57
|
+
```javascript
|
|
58
|
+
const { ContainerReader } = require('@versatiles/versatiles-rs');
|
|
59
|
+
|
|
60
|
+
const reader = await ContainerReader.open('tiles.mbtiles');
|
|
61
|
+
|
|
62
|
+
// Get a single tile
|
|
63
|
+
const tile = await reader.getTile(5, 16, 10);
|
|
64
|
+
if (tile) {
|
|
65
|
+
console.log('Tile size:', tile.length, 'bytes');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Get metadata
|
|
69
|
+
const tileJSON = JSON.parse(await reader.tileJSON);
|
|
70
|
+
console.log('Format:', tileJSON.tile_format);
|
|
71
|
+
|
|
72
|
+
const params = await reader.parameters;
|
|
73
|
+
console.log('Zoom levels:', params.minZoom, '-', params.maxZoom);
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Probe Container
|
|
77
|
+
|
|
78
|
+
```javascript
|
|
79
|
+
const { probeTiles } = require('@versatiles/versatiles-rs');
|
|
80
|
+
|
|
81
|
+
const info = await probeTiles('tiles.mbtiles');
|
|
82
|
+
console.log('Container:', info.containerName);
|
|
83
|
+
console.log('Source:', info.sourceName);
|
|
84
|
+
console.log('Format:', info.parameters.tileFormat);
|
|
85
|
+
console.log('Compression:', info.parameters.tileCompression);
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Coordinate Conversion
|
|
89
|
+
|
|
90
|
+
```javascript
|
|
91
|
+
const { TileCoord } = require('@versatiles/versatiles-rs');
|
|
92
|
+
|
|
93
|
+
// Geographic to tile coordinates
|
|
94
|
+
const coord = TileCoord.fromGeo(13.4, 52.5, 10);
|
|
95
|
+
console.log(`Tile: z=${coord.z}, x=${coord.x}, y=${coord.y}`);
|
|
96
|
+
|
|
97
|
+
// Tile to geographic coordinates
|
|
98
|
+
const tile = new TileCoord(10, 550, 335);
|
|
99
|
+
const [lon, lat] = tile.toGeo();
|
|
100
|
+
console.log(`Location: ${lon}, ${lat}`);
|
|
101
|
+
|
|
102
|
+
// Get bounding box
|
|
103
|
+
const bbox = tile.toGeoBbox();
|
|
104
|
+
console.log('BBox:', bbox); // [west, south, east, north]
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## API Reference
|
|
108
|
+
|
|
109
|
+
### `convertTiles(input, output, options?)`
|
|
110
|
+
|
|
111
|
+
Convert tiles from one format to another.
|
|
112
|
+
|
|
113
|
+
**Parameters:**
|
|
114
|
+
|
|
115
|
+
- `input` (string): Input file path (.versatiles, .mbtiles, .pmtiles, .tar, directory)
|
|
116
|
+
- `output` (string): Output file path
|
|
117
|
+
- `options` (object, optional):
|
|
118
|
+
- `minZoom` (number): Minimum zoom level
|
|
119
|
+
- `maxZoom` (number): Maximum zoom level
|
|
120
|
+
- `bbox` (array): Bounding box `[west, south, east, north]`
|
|
121
|
+
- `bboxBorder` (number): Border around bbox in tiles
|
|
122
|
+
- `compress` (string): Compression `"gzip"`, `"brotli"`, or `"uncompressed"`
|
|
123
|
+
- `flipY` (boolean): Flip tiles vertically
|
|
124
|
+
- `swapXy` (boolean): Swap x and y coordinates
|
|
125
|
+
|
|
126
|
+
**Returns:** `Promise<void>`
|
|
127
|
+
|
|
128
|
+
### `probeTiles(path, depth?)`
|
|
129
|
+
|
|
130
|
+
Inspect a tile container.
|
|
131
|
+
|
|
132
|
+
**Parameters:**
|
|
133
|
+
|
|
134
|
+
- `path` (string): Container file path
|
|
135
|
+
- `depth` (string, optional): Probe depth - currently not implemented
|
|
136
|
+
|
|
137
|
+
**Returns:** `Promise<ProbeResult>`
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
interface ProbeResult {
|
|
141
|
+
sourceName: string;
|
|
142
|
+
containerName: string;
|
|
143
|
+
tileJson: string;
|
|
144
|
+
parameters: ReaderParameters;
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### `class ContainerReader`
|
|
149
|
+
|
|
150
|
+
#### `ContainerReader.open(path)`
|
|
151
|
+
|
|
152
|
+
Open a tile container.
|
|
153
|
+
|
|
154
|
+
**Parameters:**
|
|
155
|
+
|
|
156
|
+
- `path` (string): File path or URL
|
|
157
|
+
|
|
158
|
+
**Returns:** `Promise<ContainerReader>`
|
|
159
|
+
|
|
160
|
+
#### `reader.getTile(z, x, y)`
|
|
161
|
+
|
|
162
|
+
Get a single tile.
|
|
163
|
+
|
|
164
|
+
**Parameters:**
|
|
165
|
+
|
|
166
|
+
- `z` (number): Zoom level
|
|
167
|
+
- `x` (number): Tile column
|
|
168
|
+
- `y` (number): Tile row
|
|
169
|
+
|
|
170
|
+
**Returns:** `Promise<Buffer | null>`
|
|
171
|
+
|
|
172
|
+
#### `reader.tileJSON`
|
|
173
|
+
|
|
174
|
+
Get TileJSON metadata (getter).
|
|
175
|
+
|
|
176
|
+
**Returns:** `Promise<string>`
|
|
177
|
+
|
|
178
|
+
#### `reader.parameters`
|
|
179
|
+
|
|
180
|
+
Get reader parameters (getter).
|
|
181
|
+
|
|
182
|
+
**Returns:** `Promise<ReaderParameters>`
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
interface ReaderParameters {
|
|
186
|
+
tileFormat: string;
|
|
187
|
+
tileCompression: string;
|
|
188
|
+
minZoom: number;
|
|
189
|
+
maxZoom: number;
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
#### `reader.sourceName`
|
|
194
|
+
|
|
195
|
+
Get source name (getter).
|
|
196
|
+
|
|
197
|
+
**Returns:** `Promise<string>`
|
|
198
|
+
|
|
199
|
+
#### `reader.containerName`
|
|
200
|
+
|
|
201
|
+
Get container type (getter).
|
|
202
|
+
|
|
203
|
+
**Returns:** `Promise<string>`
|
|
204
|
+
|
|
205
|
+
#### `reader.convertTo(output, options?)`
|
|
206
|
+
|
|
207
|
+
Convert this container to another format.
|
|
208
|
+
|
|
209
|
+
**Parameters:**
|
|
210
|
+
|
|
211
|
+
- `output` (string): Output file path
|
|
212
|
+
- `options` (ConvertOptions, optional): Same as `convertTiles`
|
|
213
|
+
|
|
214
|
+
**Returns:** `Promise<void>`
|
|
215
|
+
|
|
216
|
+
#### `reader.probe(depth?)`
|
|
217
|
+
|
|
218
|
+
Probe container details.
|
|
219
|
+
|
|
220
|
+
**Parameters:**
|
|
221
|
+
|
|
222
|
+
- `depth` (string, optional): Probe depth
|
|
223
|
+
|
|
224
|
+
**Returns:** `Promise<ProbeResult>`
|
|
225
|
+
|
|
226
|
+
### `class TileServer`
|
|
227
|
+
|
|
228
|
+
#### `new TileServer(options?)`
|
|
229
|
+
|
|
230
|
+
Create a new tile server.
|
|
231
|
+
|
|
232
|
+
**Parameters:**
|
|
233
|
+
|
|
234
|
+
- `options` (object, optional):
|
|
235
|
+
- `ip` (string): IP address to bind (default: `"0.0.0.0"`)
|
|
236
|
+
- `port` (number): Port number (default: `8080`)
|
|
237
|
+
- `minimalRecompression` (boolean): Use minimal recompression
|
|
238
|
+
|
|
239
|
+
#### `server.addTileSource(name, path)`
|
|
240
|
+
|
|
241
|
+
Add a tile source.
|
|
242
|
+
|
|
243
|
+
**Parameters:**
|
|
244
|
+
|
|
245
|
+
- `name` (string): Source name (URL will be `/tiles/{name}/...`)
|
|
246
|
+
- `path` (string): Container file path
|
|
247
|
+
|
|
248
|
+
**Returns:** `Promise<void>`
|
|
249
|
+
|
|
250
|
+
#### `server.addStaticSource(path, urlPrefix?)`
|
|
251
|
+
|
|
252
|
+
Add static file source.
|
|
253
|
+
|
|
254
|
+
**Parameters:**
|
|
255
|
+
|
|
256
|
+
- `path` (string): Directory or .tar file
|
|
257
|
+
- `urlPrefix` (string, optional): URL prefix (default: `"/"`)
|
|
258
|
+
|
|
259
|
+
**Returns:** `Promise<void>`
|
|
260
|
+
|
|
261
|
+
#### `server.start()`
|
|
262
|
+
|
|
263
|
+
Start the HTTP server.
|
|
264
|
+
|
|
265
|
+
**Returns:** `Promise<void>`
|
|
266
|
+
|
|
267
|
+
#### `server.stop()`
|
|
268
|
+
|
|
269
|
+
Stop the HTTP server.
|
|
270
|
+
|
|
271
|
+
**Returns:** `Promise<void>`
|
|
272
|
+
|
|
273
|
+
#### `server.port`
|
|
274
|
+
|
|
275
|
+
Get server port (getter).
|
|
276
|
+
|
|
277
|
+
**Returns:** `Promise<number>`
|
|
278
|
+
|
|
279
|
+
### `class TileCoord`
|
|
280
|
+
|
|
281
|
+
#### `new TileCoord(z, x, y)`
|
|
282
|
+
|
|
283
|
+
Create a tile coordinate.
|
|
284
|
+
|
|
285
|
+
**Parameters:**
|
|
286
|
+
|
|
287
|
+
- `z` (number): Zoom level
|
|
288
|
+
- `x` (number): Column
|
|
289
|
+
- `y` (number): Row
|
|
290
|
+
|
|
291
|
+
#### `TileCoord.fromGeo(lon, lat, z)`
|
|
292
|
+
|
|
293
|
+
Create from geographic coordinates (static).
|
|
294
|
+
|
|
295
|
+
**Parameters:**
|
|
296
|
+
|
|
297
|
+
- `lon` (number): Longitude
|
|
298
|
+
- `lat` (number): Latitude
|
|
299
|
+
- `z` (number): Zoom level
|
|
300
|
+
|
|
301
|
+
**Returns:** `TileCoord`
|
|
302
|
+
|
|
303
|
+
#### `coord.toGeo()`
|
|
304
|
+
|
|
305
|
+
Convert to geographic coordinates.
|
|
306
|
+
|
|
307
|
+
**Returns:** `[number, number]` - `[lon, lat]`
|
|
308
|
+
|
|
309
|
+
#### `coord.toGeoBbox()`
|
|
310
|
+
|
|
311
|
+
Get geographic bounding box.
|
|
312
|
+
|
|
313
|
+
**Returns:** `[number, number, number, number]` - `[west, south, east, north]`
|
|
314
|
+
|
|
315
|
+
#### `coord.toJson()`
|
|
316
|
+
|
|
317
|
+
Get JSON representation.
|
|
318
|
+
|
|
319
|
+
**Returns:** `string`
|
|
320
|
+
|
|
321
|
+
#### Properties
|
|
322
|
+
|
|
323
|
+
- `coord.z` (number): Zoom level
|
|
324
|
+
- `coord.x` (number): Column
|
|
325
|
+
- `coord.y` (number): Row
|
|
326
|
+
|
|
327
|
+
## Supported Formats
|
|
328
|
+
|
|
329
|
+
- **VersaTiles** (`.versatiles`) - Native format
|
|
330
|
+
- **MBTiles** (`.mbtiles`) - SQLite-based format
|
|
331
|
+
- **PMTiles** (`.pmtiles`) - Cloud-optimized format
|
|
332
|
+
- **TAR** (`.tar`) - Archive format
|
|
333
|
+
- **Directory** - File system based
|
|
334
|
+
|
|
335
|
+
## Examples
|
|
336
|
+
|
|
337
|
+
See the [examples](./examples) directory for more usage examples:
|
|
338
|
+
|
|
339
|
+
- [convert.js](./examples/convert.js) - Format conversion
|
|
340
|
+
- [probe.js](./examples/probe.js) - Container inspection
|
|
341
|
+
- [serve.js](./examples/serve.js) - Tile server
|
|
342
|
+
- [read-tiles.js](./examples/read-tiles.js) - Reading tiles
|
|
343
|
+
|
|
344
|
+
## Development
|
|
345
|
+
|
|
346
|
+
### Building from Source
|
|
347
|
+
|
|
348
|
+
```bash
|
|
349
|
+
# Install dependencies
|
|
350
|
+
npm install
|
|
351
|
+
|
|
352
|
+
# Build debug version
|
|
353
|
+
npm run build:debug
|
|
354
|
+
|
|
355
|
+
# Build release version
|
|
356
|
+
npm run build
|
|
357
|
+
|
|
358
|
+
# Run tests
|
|
359
|
+
npm test
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
### Requirements
|
|
363
|
+
|
|
364
|
+
- Node.js >= 16
|
|
365
|
+
- Rust toolchain (for building from source)
|
|
366
|
+
|
|
367
|
+
## License
|
|
368
|
+
|
|
369
|
+
MIT License - see [LICENSE](../LICENSE) for details.
|
|
370
|
+
|
|
371
|
+
## Links
|
|
372
|
+
|
|
373
|
+
- [VersaTiles Documentation](https://docs.versatiles.org/)
|
|
374
|
+
- [VersaTiles Rust](https://github.com/versatiles-org/versatiles-rs)
|
|
375
|
+
- [Issue Tracker](https://github.com/versatiles-org/versatiles-rs/issues)
|
|
376
|
+
|
|
377
|
+
## Contributing
|
|
378
|
+
|
|
379
|
+
Contributions are welcome! Please see the main [versatiles-rs repository](https://github.com/versatiles-org/versatiles-rs) for contribution guidelines.
|
package/package.json
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@versatiles/versatiles-rs",
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "Node.js bindings for VersaTiles - convert, serve, and process map tiles",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"index.d.ts",
|
|
9
|
+
"index.js",
|
|
10
|
+
"versatiles.*.node"
|
|
11
|
+
],
|
|
12
|
+
"napi": {
|
|
13
|
+
"binaryName": "versatiles",
|
|
14
|
+
"targets": [
|
|
15
|
+
"aarch64-apple-darwin",
|
|
16
|
+
"x86_64-apple-darwin",
|
|
17
|
+
"aarch64-unknown-linux-gnu",
|
|
18
|
+
"x86_64-unknown-linux-gnu",
|
|
19
|
+
"aarch64-pc-windows-msvc",
|
|
20
|
+
"x86_64-pc-windows-msvc"
|
|
21
|
+
]
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"versatiles",
|
|
25
|
+
"mbtiles",
|
|
26
|
+
"pmtiles",
|
|
27
|
+
"tiles",
|
|
28
|
+
"map",
|
|
29
|
+
"gis",
|
|
30
|
+
"geo",
|
|
31
|
+
"rust"
|
|
32
|
+
],
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/versatiles-org/versatiles-rs.git",
|
|
36
|
+
"directory": "versatiles_node"
|
|
37
|
+
},
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"author": "Michael Kreil <versatiles@michael-kreil.de>",
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">= 16"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"artifacts": "napi artifacts",
|
|
45
|
+
"build:debug": "napi build --platform",
|
|
46
|
+
"build": "napi build --platform --release",
|
|
47
|
+
"check": "npm run build:debug && npm run typecheck && npm run lint && npm run test && npm run test:examples && npm run format:check",
|
|
48
|
+
"docs:clean": "rm -rf docs",
|
|
49
|
+
"docs:generate": "typedoc",
|
|
50
|
+
"docs:serve": "npx http-server docs -p 8080 -o",
|
|
51
|
+
"fix": "npm run lint:fix && npm run format",
|
|
52
|
+
"format:check": "prettier --check .",
|
|
53
|
+
"format": "prettier --write .",
|
|
54
|
+
"lint:fix": "eslint src --fix",
|
|
55
|
+
"lint": "eslint src",
|
|
56
|
+
"pack:dry": "npm pack --dry-run",
|
|
57
|
+
"prepublishOnly": "napi prepublish -t npm",
|
|
58
|
+
"test:coverage": "vitest run --coverage",
|
|
59
|
+
"test:examples": "for file in examples/*.mjs; do echo \"\\n=== Running $file ===\"; node \"$file\" || exit 1; done",
|
|
60
|
+
"test:ui": "vitest --ui",
|
|
61
|
+
"test:watch": "vitest",
|
|
62
|
+
"test": "vitest run",
|
|
63
|
+
"typecheck": "tsc --noEmit",
|
|
64
|
+
"upgrade": "npm-check-updates -u && npm install",
|
|
65
|
+
"version": "napi version"
|
|
66
|
+
},
|
|
67
|
+
"devDependencies": {
|
|
68
|
+
"@eslint/js": "^9.39.2",
|
|
69
|
+
"@napi-rs/cli": "^3.5.0",
|
|
70
|
+
"@types/node": "^25",
|
|
71
|
+
"@vitest/ui": "^4.0.16",
|
|
72
|
+
"chalk": "^5.6.2",
|
|
73
|
+
"eslint": "^9.39.2",
|
|
74
|
+
"eslint-config-prettier": "^10.1.8",
|
|
75
|
+
"npm-check-updates": "^19.2.0",
|
|
76
|
+
"prettier": "^3.7.4",
|
|
77
|
+
"tsx": "^4.21.0",
|
|
78
|
+
"typedoc": "^0.28.15",
|
|
79
|
+
"typedoc-plugin-markdown": "^4.9.0",
|
|
80
|
+
"typescript": "^5.9.3",
|
|
81
|
+
"typescript-eslint": "^8.50.1",
|
|
82
|
+
"vitest": "^4.0.16"
|
|
83
|
+
},
|
|
84
|
+
"optionalDependencies": {
|
|
85
|
+
"@versatiles/versatiles-rs-darwin-arm64": "3.0.0",
|
|
86
|
+
"@versatiles/versatiles-rs-darwin-x64": "3.0.0",
|
|
87
|
+
"@versatiles/versatiles-rs-linux-arm64-gnu": "3.0.0",
|
|
88
|
+
"@versatiles/versatiles-rs-linux-x64-gnu": "3.0.0",
|
|
89
|
+
"@versatiles/versatiles-rs-win32-arm64-msvc": "3.0.0",
|
|
90
|
+
"@versatiles/versatiles-rs-win32-x64-msvc": "3.0.0"
|
|
91
|
+
}
|
|
92
|
+
}
|