summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Straßburger <codepoet@cpan.org>2016-11-06 00:21:31 +0100
committerMichael Straßburger <codepoet@cpan.org>2016-11-06 00:21:31 +0100
commita21d172a2c123d5691a963f8162d0b538e53f74b (patch)
tree5adbe1c88f7d61fae4f2c2d9b4e008dc6c11e494
parentac1494636a05037e6ae3fa76344264ced6981f0b (diff)
:construction_worker: making mbtiles library optional (install via npm install -g mbtiles)
-rw-r--r--package.json1
-rw-r--r--src/TileSource.coffee12
2 files changed, 11 insertions, 2 deletions
diff --git a/package.json b/package.json
index c166ea1..42d6b16 100644
--- a/package.json
+++ b/package.json
@@ -32,7 +32,6 @@
"earcut": "^2.1.1",
"gl-matrix": "^2.3.2",
"keypress": "^0.2.1",
- "mbtiles": "^0.9.0",
"pbf": "^3.0.0",
"rbush": "^2.0.1",
"request": "^2.76.0",
diff --git a/src/TileSource.coffee b/src/TileSource.coffee
index a99ba0b..336f533 100644
--- a/src/TileSource.coffee
+++ b/src/TileSource.coffee
@@ -8,7 +8,6 @@
###
Promise = require 'bluebird'
-MBTiles = require 'mbtiles'
userhome = require 'userhome'
request = require 'request'
rp = require 'request-promise'
@@ -16,6 +15,14 @@ fs = require 'fs'
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
config:
persistDownloadedTiles: true
@@ -37,6 +44,9 @@ module.exports = class TileSource
@mode = @modes.HTTP
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
@loadMBtils source