Read tiles and metadata from MBTiles files, uses better-sqlite3 under-the-hood.
npm install mbtiles-reader
Here's a basic example of how to use MBTiles Reader:
import { MBTilesReader } from 'mbtiles-reader'
const mbtiles = new MBTilesReader('path/to/your/mbtiles/file.mbtiles')
const { x, y, z, data, format } = reader.getTile(0, 0, 0)
for (const { x, y, z, data, format } in mbtiles) {
console.log(`Tile ${x}, ${y}, ${z}: ${data.length} bytes of ${format} data`)
}
console.log(mbtiles.metadata)
Creates a new instance of MBTilesReader. Will throw if the file is not a valid MBTiles file.
filePathOrDb
(string | Database): Path to the MBTiles file or a better-sqlite3 Database instance.
Retrieves a tile from the MBTiles file.
z
(number): Zoom level.x
(number): Tile column.y
(number): Tile row.- Returns:
{ x: number, y: number, z: number, data: Buffer, format: string }
Metadata from the MBTiles file, see spec. Will always include bounds
, center
, minzoom
, maxzoom
derived from the tile data in the file.
mbtiles
is an iterable object that yields Tile
objects:
interface Tile {
x: number
y: number
z: number
data: Buffer
format: string
}
Returns a readable stream that yields Tile
objects (see above).
Closes the MBTiles file.
This project is licensed under the MIT License.
Contributions are welcome! Please open an issue or submit a pull request.
Inspired by mbtiles