[![NPM version][npm-image]][npm-url]
[![Build Status][build-image]][build-url]
[![Dependency Status][deps-image]][deps-url]

# mbtiles

This is a fork of [@mapbox/mbtiles].

It only provides sync and read-only subset of API.
It is using [node:sqlite] instead of [sqllite3].

# Installation

```sh
npm install @mapwhit/mbtiles
```

```javascript
import MBTiles from '@mapwhit/mbtiles';
```

# Environment Variables

This library uses the `MBTILES_PRAGMA` environment variable to control SQLite pragmas. Set this variable to customize SQLite behavior, for example:

```sh
MBTILES_PRAGMA="PRAGMA journal_mode = WAL; PRAGMA synchronous = NORMAL;"
```

# API

### Constructor

All MBTiles instances need to be constructed before any of the methods become available. *NOTE: All methods described below assume you've taken this step.*

```javascript
const mbtiles = new MBTiles('./path/to/file.mbtiles');
console.log(mbtiles) // mbtiles object with methods listed below
```

### Reading

**`getTile(z, x, y)`**

Get an individual tile from the MBTiles table. This can be a raster or gzipped vector tile. Also returns headers that are important for serving over HTTP.

```javascript
const { error, tile, headers } = mbtiles.getTile(z, x, y);
// `tile` is your gzipped buffer - use zlib to gunzip or inflate
```

**`getInfo()`**

Get info of an MBTiles file, which is stored in the `metadata` table. Includes information like zoom levels, bounds, vector_layers, that were created during generation. This performs fallback queries if certain keys like `bounds`, `minzoom`, or `maxzoom` have not been provided.

```javascript
const info = mbtiles.getInfo();
```

# Test

```
npm test
```

[@mapbox/mbtiles]: https://github.com/mapbox/node-mbtiles
[node:sqlite]: https://nodejs.org/api/sqlite.html
[sqllite3]: https://github.com/mapbox/node-sqlite3

[npm-image]: https://img.shields.io/npm/v/@mapwhit/mbtiles
[npm-url]: https://npmjs.org/package/@mapwhit/mbtiles

[build-url]: https://github.com/mapwhit/mbtiles/actions/workflows/check.yaml
[build-image]: https://img.shields.io/github/actions/workflow/status/mapwhit/mbtiles/check.yaml?branch=main

[deps-image]: https://img.shields.io/librariesio/release/npm/@mapwhit/mbtiles
[deps-url]: https://libraries.io/npm/@mapwhit%2Fmbtiles
