fix formatting issues

This commit is contained in:
Joseph Canero 2017-10-03 19:04:42 -04:00
parent f07e6ef3e8
commit a007218e2d
3 changed files with 97 additions and 97 deletions

View file

@ -9,13 +9,13 @@ var clone = require('clone'),
express = require('express');
module.exports = function (options, repo, params, id, reportTiles, reportFont) {
module.exports = function(options, repo, params, id, reportTiles, reportFont) {
var app = express().disable('x-powered-by');
var styleFile = path.resolve(options.paths.styles, params.style);
var styleJSON = clone(require(styleFile));
Object.keys(styleJSON.sources).forEach(function (name) {
Object.keys(styleJSON.sources).forEach(function(name) {
var source = styleJSON.sources[name];
var url = source.url;
if (url && url.lastIndexOf('mbtiles:', 0) === 0) {
@ -35,7 +35,7 @@ module.exports = function (options, repo, params, id, reportTiles, reportFont) {
}
});
styleJSON.layers.forEach(function (obj) {
styleJSON.layers.forEach(function(obj) {
if (obj['type'] == 'symbol') {
var fonts = (obj['layout'] || {})['text-font'];
if (fonts && fonts.length) {
@ -115,7 +115,7 @@ module.exports = function (options, repo, params, id, reportTiles, reportFont) {
};
var styleJSON_ = clone(styleJSON);
Object.keys(styleJSON_.sources).forEach(function (name) {
Object.keys(styleJSON_.sources).forEach(function(name) {
var source = styleJSON_.sources[name];
source.url = fixUrl(source.url);
});

View file

@ -84,7 +84,7 @@ function start(opts) {
var startupPromises = [];
var checkPath = function (type) {
var checkPath = function(type) {
if (!fs.existsSync(paths[type])) {
console.error('The specified path for "' + type + '" does not exist (' + paths[type] + ').');
process.exit(1);
@ -98,7 +98,7 @@ function start(opts) {
if (options.dataDecorator) {
try {
options.dataDecoratorFunc = require(path.resolve(paths.root, options.dataDecorator));
} catch (e) { }
} catch (e) {}
}
var data = clone(config.data || {});
@ -107,7 +107,7 @@ function start(opts) {
app.use(cors());
}
Object.keys(config.styles || {}).forEach(function (id) {
Object.keys(config.styles || {}).forEach(function(id) {
var item = config.styles[id];
if (!item.style || item.style.length == 0) {
console.log('Missing "style" property for ' + id);
@ -116,9 +116,9 @@ function start(opts) {
if (item.serve_data !== false) {
startupPromises.push(serve_style(options, serving.styles, item, id,
function (mbtiles, fromData) {
function(mbtiles, fromData) {
var dataItemId;
Object.keys(data).forEach(function (id) {
Object.keys(data).forEach(function(id) {
if (fromData) {
if (id == mbtiles) {
dataItemId = id;
@ -142,9 +142,9 @@ function start(opts) {
};
return id;
}
}, function (font) {
}, function(font) {
serving.fonts[font] = true;
}).then(function (sub) {
}).then(function(sub) {
app.use('/styles/', sub);
}));
}
@ -152,16 +152,16 @@ function start(opts) {
if (serve_rendered) {
startupPromises.push(
serve_rendered(options, serving.rendered, item, id,
function (mbtiles) {
function(mbtiles) {
var mbtilesFile;
Object.keys(data).forEach(function (id) {
Object.keys(data).forEach(function(id) {
if (id == mbtiles) {
mbtilesFile = data[id].mbtiles;
}
});
return mbtilesFile;
}
).then(function (sub) {
).then(function(sub) {
app.use('/styles/', sub);
})
);
@ -172,12 +172,12 @@ function start(opts) {
});
startupPromises.push(
serve_font(options, serving.fonts).then(function (sub) {
serve_font(options, serving.fonts).then(function(sub) {
app.use('/', sub);
})
);
Object.keys(data).forEach(function (id) {
Object.keys(data).forEach(function(id) {
var item = data[id];
if (!item.mbtiles || item.mbtiles.length == 0) {
console.log('Missing "mbtiles" property for ' + id);
@ -185,16 +185,16 @@ function start(opts) {
}
startupPromises.push(
serve_data(options, serving.data, item, id, serving.styles).then(function (sub) {
serve_data(options, serving.data, item, id, serving.styles).then(function(sub) {
app.use('/data/', sub);
})
);
});
app.get('/styles.json', function (req, res, next) {
app.get('/styles.json', function(req, res, next) {
var result = [];
var query = req.query.key ? ('?key=' + req.query.key) : '';
Object.keys(serving.styles).forEach(function (id) {
Object.keys(serving.styles).forEach(function(id) {
var styleJSON = serving.styles[id];
result.push({
version: styleJSON.version,
@ -207,8 +207,8 @@ function start(opts) {
res.send(result);
});
var addTileJSONs = function (arr, req, type) {
Object.keys(serving[type]).forEach(function (id) {
var addTileJSONs = function(arr, req, type) {
Object.keys(serving[type]).forEach(function(id) {
var info = clone(serving[type][id]);
var path = '';
if (type == 'rendered') {
@ -224,13 +224,13 @@ function start(opts) {
return arr;
};
app.get('/rendered.json', function (req, res, next) {
app.get('/rendered.json', function(req, res, next) {
res.send(addTileJSONs([], req, 'rendered'));
});
app.get('/data.json', function (req, res, next) {
app.get('/data.json', function(req, res, next) {
res.send(addTileJSONs([], req, 'data'));
});
app.get('/index.json', function (req, res, next) {
app.get('/index.json', function(req, res, next) {
res.send(addTileJSONs(addTileJSONs([], req, 'rendered'), req, 'data'));
});
@ -239,7 +239,7 @@ function start(opts) {
app.use('/', express.static(path.join(__dirname, '../public/resources')));
var templates = path.join(__dirname, '../public/templates');
var serveTemplate = function (urlPath, template, dataGetter) {
var serveTemplate = function(urlPath, template, dataGetter) {
var templateFile = templates + '/' + template + '.tmpl';
if (template == 'index') {
if (options.frontPage === false) {
@ -249,15 +249,15 @@ function start(opts) {
templateFile = path.resolve(paths.root, options.frontPage);
}
}
startupPromises.push(new Promise(function (resolve, reject) {
fs.readFile(templateFile, function (err, content) {
startupPromises.push(new Promise(function(resolve, reject) {
fs.readFile(templateFile, function(err, content) {
if (err) {
console.error('Template not found:', err);
reject(err);
}
var compiled = handlebars.compile(content.toString());
app.use(urlPath, function (req, res, next) {
app.use(urlPath, function(req, res, next) {
var data = {};
if (dataGetter) {
data = dataGetter(req);
@ -277,9 +277,9 @@ function start(opts) {
}));
};
serveTemplate('/$', 'index', function (req) {
serveTemplate('/$', 'index', function(req) {
var styles = clone(config.styles || {});
Object.keys(styles).forEach(function (id) {
Object.keys(styles).forEach(function(id) {
var style = styles[id];
style.name = (serving.styles[id] || serving.rendered[id] || {}).name;
style.serving_data = serving.styles[id];
@ -309,7 +309,7 @@ function start(opts) {
}
});
var data = clone(serving.data || {});
Object.keys(data).forEach(function (id) {
Object.keys(data).forEach(function(id) {
var data_ = data[id];
var center = data_.center;
if (center) {
@ -357,7 +357,7 @@ function start(opts) {
};
});
serveTemplate('/styles/:id/$', 'viewer', function (req) {
serveTemplate('/styles/:id/$', 'viewer', function(req) {
var id = req.params.id;
var style = clone((config.styles || {})[id]);
if (!style) {
@ -376,7 +376,7 @@ function start(opts) {
});
*/
serveTemplate('/data/:id/$', 'data', function (req) {
serveTemplate('/data/:id/$', 'data', function(req) {
var id = req.params.id;
var data = clone(serving.data[id]);
if (!data) {
@ -388,11 +388,11 @@ function start(opts) {
});
var startupComplete = false;
var startupPromise = Promise.all(startupPromises).then(function () {
var startupPromise = Promise.all(startupPromises).then(function() {
console.log('Startup complete');
startupComplete = true;
});
app.get('/health', function (req, res, next) {
app.get('/health', function(req, res, next) {
if (startupComplete) {
return res.status(200).send('OK');
} else {
@ -400,7 +400,7 @@ function start(opts) {
}
});
var server = app.listen(process.env.PORT || opts.port, process.env.BIND || opts.bind, function () {
var server = app.listen(process.env.PORT || opts.port, process.env.BIND || opts.bind, function() {
var address = this.address().address;
if (address.indexOf('::') === 0) {
address = '[' + address + ']'; // literal IPv6 address
@ -418,17 +418,17 @@ function start(opts) {
};
}
module.exports = function (opts) {
module.exports = function(opts) {
var running = start(opts);
process.on('SIGINT', function () {
process.on('SIGINT', function() {
process.exit();
});
process.on('SIGHUP', function () {
process.on('SIGHUP', function() {
console.log('Stopping server and reloading config');
running.server.shutdown(function () {
running.server.shutdown(function() {
for (var key in require.cache) {
delete require.cache[key];
}

View file

@ -6,7 +6,7 @@ var path = require('path'),
var clone = require('clone'),
glyphCompose = require('glyph-pbf-composite');
module.exports.getTileUrls = function (req, domains, path, format, aliases, options) {
module.exports.getTileUrls = function(req, domains, path, format, aliases, options) {
if (domains) {
if (domains.constructor === String && domains.length > 0) {
@ -17,7 +17,7 @@ module.exports.getTileUrls = function (req, domains, path, format, aliases, opti
var relativeSubdomainsUsable = hostParts.length > 1 &&
!/^([0-9]{1,3}\.){3}[0-9]{1,3}(\:[0-9]+)?$/.test(host);
var newDomains = [];
domains.forEach(function (domain) {
domains.forEach(function(domain) {
if (domain.indexOf('*') !== -1) {
if (relativeSubdomainsUsable) {
var newParts = hostParts.slice(1);
@ -49,7 +49,7 @@ module.exports.getTileUrls = function (req, domains, path, format, aliases, opti
}
var uris = [];
domains.forEach(function (domain) {
domains.forEach(function(domain) {
uris.push(req.protocol + '://' + domain + '/' + path +
'/{z}/{x}/{y}.' + format + query);
});
@ -57,7 +57,7 @@ module.exports.getTileUrls = function (req, domains, path, format, aliases, opti
return uris;
};
module.exports.fixTileJSONCenter = function (tileJSON) {
module.exports.fixTileJSONCenter = function(tileJSON) {
if (tileJSON.bounds && !tileJSON.center) {
var fitWidth = 1024;
var tiles = fitWidth / 256;
@ -72,15 +72,15 @@ module.exports.fixTileJSONCenter = function (tileJSON) {
}
};
var getFontPbf = function (allowedFonts, fontPath, name, range, fallbacks) {
return new Promise(function (resolve, reject) {
var getFontPbf = function(allowedFonts, fontPath, name, range, fallbacks) {
return new Promise(function(resolve, reject) {
if (!allowedFonts || (allowedFonts[name] && fallbacks)) {
var filename = path.join(fontPath, name, range + '.pbf');
if (!fallbacks) {
fallbacks = clone(allowedFonts || {});
}
delete fallbacks[name];
fs.readFile(filename, function (err, data) {
fs.readFile(filename, function(err, data) {
if (err) {
console.error('ERROR: Font not found:', name);
if (fallbacks && Object.keys(fallbacks).length) {
@ -101,17 +101,17 @@ var getFontPbf = function (allowedFonts, fontPath, name, range, fallbacks) {
});
};
module.exports.getFontsPbf = function (allowedFonts, fontPath, names, range, fallbacks) {
module.exports.getFontsPbf = function(allowedFonts, fontPath, names, range, fallbacks) {
var fonts = names.split(',');
var queue = [];
fonts.forEach(function (font) {
fonts.forEach(function(font) {
queue.push(
getFontPbf(allowedFonts, fontPath, font, range, clone(allowedFonts || fallbacks))
);
});
return new Promise(function (resolve, reject) {
Promise.all(queue).then(function (values) {
return new Promise(function(resolve, reject) {
Promise.all(queue).then(function(values) {
return resolve(glyphCompose.combine(values));
}, reject);
});