👷 making mbtiles library optional (install via npm install -g mbtiles)

This commit is contained in:
Michael Straßburger 2016-11-06 00:21:31 +01:00
parent ac1494636a
commit a21d172a2c
2 changed files with 11 additions and 2 deletions

View File

@ -32,7 +32,6 @@
"earcut": "^2.1.1", "earcut": "^2.1.1",
"gl-matrix": "^2.3.2", "gl-matrix": "^2.3.2",
"keypress": "^0.2.1", "keypress": "^0.2.1",
"mbtiles": "^0.9.0",
"pbf": "^3.0.0", "pbf": "^3.0.0",
"rbush": "^2.0.1", "rbush": "^2.0.1",
"request": "^2.76.0", "request": "^2.76.0",

View File

@ -8,7 +8,6 @@
### ###
Promise = require 'bluebird' Promise = require 'bluebird'
MBTiles = require 'mbtiles'
userhome = require 'userhome' userhome = require 'userhome'
request = require 'request' request = require 'request'
rp = require 'request-promise' rp = require 'request-promise'
@ -16,6 +15,14 @@ fs = require 'fs'
Tile = require './Tile' Tile = require './Tile'
# https://github.com/mapbox/node-mbtiles has native build dependencies (sqlite3)
# To maximize mapscii's compatibility, MBTiles support must be manually added via
# $> npm install -g mbtiles
MBTiles = try
require 'mbtiles'
catch
null
module.exports = class TileSource module.exports = class TileSource
config: config:
persistDownloadedTiles: true persistDownloadedTiles: true
@ -37,6 +44,9 @@ module.exports = class TileSource
@mode = @modes.HTTP @mode = @modes.HTTP
else if @source.endsWith ".mbtiles" else if @source.endsWith ".mbtiles"
unless MBTiles
throw new Error "MBTiles support must be installed with following command: 'npm install -g mbtiles'"
@mode = @modes.MBTiles @mode = @modes.MBTiles
@loadMBtils source @loadMBtils source