mbtiles-offline v4.0.1
MBTiles Offline
MBTiles binding for NodeJS 4+ using Callbacks and/or Promises.
Install
$ npm install --save mbtiles-offlineUsage
const MBTiles = require('mbtiles-offline')
const db = new MBTiles('example.mbtiles')
db.metadata()
//= Promise{ JSON }
db.save([1, 2, 3], Buffer([0, 1]))
db.save([2, 2, 3], Buffer([3, 4]))
db.findOne([1, 2, 3])
//= Promise { <Buffer 00 01> }
db.findAll()
//= Promise{ [[1, 2, 3], [2, 2, 3]] }
db.count()
//= Promise { 2 }
db.delete([1, 2, 3])
db.delete([2, 2, 3])
db.count()
//= Promise { 0 }Features
| Name | Description |
|---|---|
| metadata | Retrieve Metadata from MBTiles |
| update | Update Metadata |
| save | Save buffer data to individual Tile |
| delete | Delete individual Tile |
| count | Count total tiles |
| findOne | Finds one Tile and returns buffer |
| findAll | Finds all Tiles |
| tables | Build SQL Tables |
| index | Build SQL Index |
| getMinZoom | Retrieves Minimum Zoom level |
| getMaxZoom | Retrieves Maximum Zoom level |
| getFormat | Retrieves Image Format |
| getBounds | Retrieves Bounds |
| validate | Validate MBTiles according to the specifications |
| hash | Creates hash from a single Tile |
| hashes | Creates a hash table for all tiles |
NodeJS Support
Windows, MacOSX, Linux & Electron
- Node.js v8
- Node.js v7
- Node.js v6
- Node.js v5
- Node.js v4
Schemas
XYZ
Slippy Map is the most commonly used Tile schema for service maps as tiles, providers such as Google/ArcGIS & OpenStreetMap use this schema.
const tile1 = [1, 2, 3]
const tile2 = [2, 2, 3]
const tile3 = [1, 3, 3]
const tile4 = [2, 3, 3]
const img = Buffer([0, 1])
const db = new MBTiles('xyz.mbtiles', 'xyz')
db.save(tile1, img)
db.save(tile1, img)
db.findOne(tile1)
//= Promise { <Buffer 00 01> }
db.findAll()
//= Promise{ [[1, 2, 3], [2, 2, 3]] }TMS
Tile Map Service is an OGC protocol for serving maps as tiles. MBTiles uses TMS as it's internal tile storage schema (TMS has an inverse Y compared to the XYZ schema).
const tile1 = [1, 5, 3]
const tile2 = [2, 5, 3]
const tile3 = [1, 4, 3]
const tile4 = [2, 4, 3]
const img = Buffer([0, 1])
const db = new MBTiles('tms.mbtiles', 'tms')
db.save(tile1, img)
db.save(tile2, img)
db.findOne(tile1)
//= Promise { <Buffer 00 01> }
db.findAll()
//= Promise{ [[1, 5, 3], [2, 5, 3]] }Quadkey
Bing Map Tile System, a quadkey is defined as a string which represent a Tile x,y,z.
const tile1 = '021'
const tile2 = '030'
const tile3 = '023'
const tile4 = '032'
const img = Buffer([0, 1])
const db = new MBTiles('quadkey.mbtiles', 'quadkey')
db.save(tile1, img)
db.save(tile2, img)
db.findOne(tile1)
//= Promise { <Buffer 00 01> }
db.findAll()
//= Promise { ['021', '030'] }API
index
MBTiles
constructor
MBTiles
Parameters
uristring Path to MBTilesschemastring Tile schema ('xyz', 'tms', 'quadkey') (optional, default'xyz')
Examples
const db = new MBTiles('example.mbtiles')
//= mbtilesReturns MBTiles MBTiles
save
Save buffer data to individual Tile
Parameters
Examples
db.save([x, y, z], buffer).then(status => {
//= status
}).catch(error => {
//= error
})Returns Promise<boolean> true/false
metadata
Retrieves Metadata from MBTiles
Examples
db.metadata().then(metadata => {
//= metadata
}).catch(error => {
//= error
})Returns Promise<Metadata> Metadata as an Object
metadataSync
Sync: Retrieves Metadata from MBTiles
Parameters
callbackFunction a method that takes (error: {Error}, metadata: {Object})
Examples
db.metadata((error, metadata) => {
//= error
//= metadata
})Returns void
delete
Delete individual Tile
Parameters
tileTile Tile x, y, z
Examples
db.delete([x, y, z]).then(status => {
//= status
}).catch(error => {
//= error
})Returns Promise<boolean> true/false
getMinZoom
Retrieves Minimum Zoom level
Examples
db.getMinZoom().then(minZoom => {
//= minZoom
}).catch(error => {
//= error
})getMaxZoom
Retrieves Maximum Zoom level
Examples
db.getMaxZoom().then(maxZoom => {
//= maxZoom
}).catch(error => {
//= error
})getFormat
Retrieves Image Format
Examples
db.getFormat().then(format => {
//= format
}).catch(error => {
//= error
})Returns Promise<Formats>
getBounds
Retrieves Bounds
Parameters
zoomnumber Zoom level
Examples
db.getBounds().then(bbox => {
//= bbox
}).catch(error => {
//= error
})Returns Promise<BBox>
count
Count the amount of Tiles
Parameters
tilesArray<Tile>? Only find given tiles
Examples
db.count().then(count => {
//= count
}).catch(error => {
//= error
})update
Update Metadata
Parameters
metadataMetadata Metadata according to MBTiles spec 1.1.0 (optional, default{})metadata.attributionstring Attributionmetadata.boundsBBox BBox west, south, east, north or Polygon GeoJSONmetadata.centerCenter Center lng, lat or lng, lat, heightmetadata.descriptionstring Descriptionmetadata.formatFormats Format 'png' | 'jpg' | 'webp' | 'pbf'metadata.minzoomnumber Minimum zoom levelmetadata.maxzoomnumber Maximum zoom levelmetadata.namestring Namemetadata.urlstring URL source or tile schememetadata.typeTypes Type 'baselayer' | 'overlay' (optional, default'baselayer')metadata.versionVersions Version '1.0.0' | '1.1.0' | '1.2.0' (optional, default'1.1.0')
Examples
const options = {
name: 'Foo',
description: 'Bar',
minzoom: 1,
maxzoom: 3,
format: 'png',
bounds: [-110, -40, 95, 50]
}
db.update(options).then(metadata => {
//= metadata
}).catch(error => {
//= error
})Returns Promise<Metadata> Metadata
validate
Validate MBTiles according to the specifications
Examples
db.validate().then(status => {
//= status
}).catch(error => {
//= error
})Returns Promise<boolean> true/false
findAll
Finds all Tile unique hashes
Parameters
tilesArray<Tile>? Only find given tiles (optional, default[])
Examples
const tile1 = [33, 40, 6]
const tile2 = [20, 50, 7]
db.findAll([tile1, tile2]).then(tiles => {
//= tiles
}).catch(error => {
//= error
})Returns Promise<Array<Tile>> An array of Tiles x, y, z
findOneSync
Sync: Finds one Tile and returns Buffer
Parameters
Examples
db.findOneSync([x, y, z], (error, image) => {
//= error
//= image
})Returns void
findOne
Finds one Tile and returns Buffer
Parameters
tileTile Tile x, y, z
Examples
db.findOne([x, y, z]).then(image => {
//= image
}).catch(error => {
//= error
})Returns Promise<Buffer> Tile Data
tables
Build SQL tables
Examples
db.tables().then(status => {
//= status
}).catch(error => {
//= error
})Returns Promise<boolean> true/false
index
Build SQL index
Examples
db.index().then(status => {
//= status
}).catch(error => {
//= error
})Returns Promise<boolean> true/false
hash
Creates hash from a single Tile
Parameters
tileTile
Examples
const hash = db.hash([5, 25, 12])
//= 16797721Returns number hash
hashes
Creates a hash table for all tiles
Parameters
tilesArray<Tile>? Only find given tiles
Examples
await db.save([0, 0, 3], Buffer([0, 1]))
await db.save([0, 1, 3], Buffer([2, 3]))
db.hashes()
//= Promise { Set { 64, 65 } }8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago