After ESLint in TileSource

This commit is contained in:
Christian Paul 2017-12-23 00:07:23 -08:00
parent 1369140af4
commit 088b9a3b71

View File

@ -20,11 +20,7 @@ const config = require('./config');
let MBTiles = null; let MBTiles = null;
try { try {
MBTiles = require('mbtiles'); MBTiles = require('mbtiles');
} catch (err) {} } catch (err) {void 0;}
const cache = {};
const cacheSize = 16;
const cached = [];
const modes = { const modes = {
MBTiles: 1, MBTiles: 1,
@ -53,13 +49,13 @@ class TileSource {
} else if (this.source.endsWith('.mbtiles')) { } else if (this.source.endsWith('.mbtiles')) {
if (!MBTiles) { if (!MBTiles) {
throw new Error("MBTiles support must be installed with following command: 'npm install -g mbtiles'"); throw new Error('MBTiles support must be installed with following command: \'npm install -g mbtiles\'');
} }
this.mode = modes.MBTiles; this.mode = modes.MBTiles;
this.loadMBtils(source); this.loadMBtils(source);
} else { } else {
throw new Error("source type isn't supported yet"); throw new Error('source type isn\'t supported yet');
} }
} }
@ -81,10 +77,10 @@ class TileSource {
getTile(z, x, y) { getTile(z, x, y) {
if (!this.mode) { if (!this.mode) {
throw new Error("no TileSource defined"); throw new Error('no TileSource defined');
} }
const cached = this.cache[[z, x, y].join("-")]; const cached = this.cache[[z, x, y].join('-')];
if (cached) { if (cached) {
return Promise.resolve(cached); return Promise.resolve(cached);
} }
@ -111,13 +107,13 @@ class TileSource {
promise = Promise.resolve(persistedTile); promise = Promise.resolve(persistedTile);
} else { } else {
promise = fetch(this.source + [z,x,y].join('/') + '.pbf') promise = fetch(this.source + [z,x,y].join('/') + '.pbf')
.then((res) => res.buffer()) .then((res) => res.buffer())
.then((buffer) => { .then((buffer) => {
if (config.persistDownloadedTiles) { if (config.persistDownloadedTiles) {
this._persistTile(z, x, y, buffer); this._persistTile(z, x, y, buffer);
return buffer; return buffer;
} }
}); });
} }
return promise.then((buffer) => { return promise.then((buffer) => {
return this._createTile(z, x, y, buffer); return this._createTile(z, x, y, buffer);
@ -172,7 +168,7 @@ class TileSource {
fs.mkdirSync(path); fs.mkdirSync(path);
return true; return true;
} catch (error) { } catch (error) {
return error.code === "EEXIST"; return error.code === 'EEXIST';
} }
} }
} }