remove trailing commas
This commit is contained in:
parent
fff69f2483
commit
dbfe411796
11 changed files with 76 additions and 73 deletions
|
|
@ -8,4 +8,7 @@ parserOptions:
|
|||
sourceType: module
|
||||
ignorePatterns:
|
||||
- /public/resources
|
||||
rules: {}
|
||||
rules:
|
||||
comma-dangle:
|
||||
- error
|
||||
- never
|
||||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
// SYNC THE `light` FOLDER
|
||||
require('child_process').execSync('rsync -av --exclude="light" --exclude=".git" --exclude="node_modules" --delete . light', {
|
||||
stdio: 'inherit',
|
||||
stdio: 'inherit'
|
||||
});
|
||||
|
||||
// PATCH `package.json`
|
||||
|
|
@ -45,10 +45,10 @@ if (process.argv.length > 2 && process.argv[2] == '--no-publish') {
|
|||
|
||||
// tileserver-gl
|
||||
require('child_process').execSync('npm publish .', {
|
||||
stdio: 'inherit',
|
||||
stdio: 'inherit'
|
||||
});
|
||||
|
||||
// tileserver-gl-light
|
||||
require('child_process').execSync('npm publish light', {
|
||||
stdio: 'inherit',
|
||||
stdio: 'inherit'
|
||||
});
|
||||
|
|
|
|||
38
src/main.js
38
src/main.js
|
|
@ -26,50 +26,50 @@ program
|
|||
.option(
|
||||
'--mbtiles <file>',
|
||||
'MBTiles file (uses demo configuration);\n' +
|
||||
'\t ignored if the configuration file is also specified',
|
||||
'\t ignored if the configuration file is also specified'
|
||||
)
|
||||
.option(
|
||||
'-c, --config <file>',
|
||||
'Configuration file [config.json]',
|
||||
'config.json',
|
||||
'config.json'
|
||||
)
|
||||
.option(
|
||||
'-b, --bind <address>',
|
||||
'Bind address',
|
||||
'Bind address'
|
||||
)
|
||||
.option(
|
||||
'-p, --port <port>',
|
||||
'Port [8080]',
|
||||
8080,
|
||||
parseInt,
|
||||
parseInt
|
||||
)
|
||||
.option(
|
||||
'-C|--no-cors',
|
||||
'Disable Cross-origin resource sharing headers',
|
||||
'Disable Cross-origin resource sharing headers'
|
||||
)
|
||||
.option(
|
||||
'-u|--public_url <url>',
|
||||
'Enable exposing the server on subpaths, not necessarily the root of the domain',
|
||||
'Enable exposing the server on subpaths, not necessarily the root of the domain'
|
||||
)
|
||||
.option(
|
||||
'-V, --verbose',
|
||||
'More verbose output',
|
||||
'More verbose output'
|
||||
)
|
||||
.option(
|
||||
'-s, --silent',
|
||||
'Less verbose output',
|
||||
'Less verbose output'
|
||||
)
|
||||
.option(
|
||||
'-l|--log_file <file>',
|
||||
'output log file (defaults to standard out)',
|
||||
'output log file (defaults to standard out)'
|
||||
)
|
||||
.option(
|
||||
'-f|--log_format <format>',
|
||||
'define the log format: https://github.com/expressjs/morgan#morganformat-options',
|
||||
'define the log format: https://github.com/expressjs/morgan#morganformat-options'
|
||||
)
|
||||
.version(
|
||||
packageJson.version,
|
||||
'-v, --version',
|
||||
'-v, --version'
|
||||
);
|
||||
program.parse(process.argv);
|
||||
const opts = program.opts();
|
||||
|
|
@ -90,7 +90,7 @@ const startServer = (configPath, config) => {
|
|||
silent: opts.silent,
|
||||
logFile: opts.log_file,
|
||||
logFormat: opts.log_format,
|
||||
publicUrl: publicUrl,
|
||||
publicUrl: publicUrl
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -129,17 +129,17 @@ const startWithMBTiles = (mbtilesFile) => {
|
|||
'root': styleDir,
|
||||
'fonts': 'fonts',
|
||||
'styles': 'styles',
|
||||
'mbtiles': path.dirname(mbtilesFile),
|
||||
},
|
||||
'mbtiles': path.dirname(mbtilesFile)
|
||||
}
|
||||
},
|
||||
'styles': {},
|
||||
'data': {},
|
||||
'data': {}
|
||||
};
|
||||
|
||||
if (info.format === 'pbf' &&
|
||||
info.name.toLowerCase().indexOf('openmaptiles') > -1) {
|
||||
config['data'][`v3`] = {
|
||||
'mbtiles': path.basename(mbtilesFile),
|
||||
'mbtiles': path.basename(mbtilesFile)
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -151,8 +151,8 @@ const startWithMBTiles = (mbtilesFile) => {
|
|||
config['styles'][styleName] = {
|
||||
'style': styleFileRel,
|
||||
'tilejson': {
|
||||
'bounds': bounds,
|
||||
},
|
||||
'bounds': bounds
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -162,7 +162,7 @@ const startWithMBTiles = (mbtilesFile) => {
|
|||
.replace(/\//g, '_')
|
||||
.replace(/:/g, '_')
|
||||
.replace(/\?/g, '_')] = {
|
||||
'mbtiles': path.basename(mbtilesFile),
|
||||
'mbtiles': path.basename(mbtilesFile)
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ export const serve_data = {
|
|||
const tile = new VectorTile(new Pbf(data));
|
||||
const geojson = {
|
||||
'type': 'FeatureCollection',
|
||||
'features': [],
|
||||
'features': []
|
||||
};
|
||||
for (const layerName in tile.layers) {
|
||||
const layer = tile.layers[layerName];
|
||||
|
|
@ -110,7 +110,7 @@ export const serve_data = {
|
|||
const info = clone(item.tileJSON);
|
||||
info.tiles = getTileUrls(req, info.tiles,
|
||||
`data/${req.params.id}`, info.format, item.publicUrl, {
|
||||
'pbf': options.pbfAlias,
|
||||
'pbf': options.pbfAlias
|
||||
});
|
||||
return res.send(info);
|
||||
});
|
||||
|
|
@ -120,7 +120,7 @@ export const serve_data = {
|
|||
add: (options, repo, params, id, publicUrl) => {
|
||||
const mbtilesFile = path.resolve(options.paths.mbtiles, params.mbtiles);
|
||||
let tileJSON = {
|
||||
'tiles': params.domains || options.domains,
|
||||
'tiles': params.domains || options.domains
|
||||
};
|
||||
|
||||
const mbtilesFileStats = fs.statSync(mbtilesFile);
|
||||
|
|
@ -165,8 +165,8 @@ export const serve_data = {
|
|||
repo[id] = {
|
||||
tileJSON,
|
||||
publicUrl,
|
||||
source,
|
||||
source
|
||||
};
|
||||
});
|
||||
},
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -45,14 +45,14 @@ export const serve_font = (options, allowedFonts) => {
|
|||
res.header('Content-type', 'application/x-protobuf');
|
||||
res.header('Last-Modified', lastModified);
|
||||
return res.send(concated);
|
||||
}, (err) => res.status(400).send(err),
|
||||
}, (err) => res.status(400).send(err)
|
||||
);
|
||||
});
|
||||
|
||||
app.get('/fonts.json', (req, res, next) => {
|
||||
res.header('Content-type', 'application/json');
|
||||
return res.send(
|
||||
Object.keys(options.serveAllFonts ? existingFonts : allowedFonts).sort(),
|
||||
Object.keys(options.serveAllFonts ? existingFonts : allowedFonts).sort()
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -6,5 +6,5 @@ export const serve_rendered = {
|
|||
add: (options, repo, params, id, publicUrl, dataResolver) => {
|
||||
},
|
||||
remove: (repo, id) => {
|
||||
},
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ const extensionToFormat = {
|
|||
'.jpg': 'jpeg',
|
||||
'.jpeg': 'jpeg',
|
||||
'.png': 'png',
|
||||
'.webp': 'webp',
|
||||
'.webp': 'webp'
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -46,7 +46,7 @@ const extensionToFormat = {
|
|||
* string is for unknown or unsupported formats.
|
||||
*/
|
||||
const cachedEmptyResponses = {
|
||||
'': Buffer.alloc(0),
|
||||
'': Buffer.alloc(0)
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -83,8 +83,8 @@ function createEmptyResponse(format, color, callback) {
|
|||
raw: {
|
||||
width: 1,
|
||||
height: 1,
|
||||
channels: channels,
|
||||
},
|
||||
channels: channels
|
||||
}
|
||||
}).toFormat(format).toBuffer((err, buffer, info) => {
|
||||
if (!err) {
|
||||
cachedEmptyResponses[cacheKey] = buffer;
|
||||
|
|
@ -182,7 +182,7 @@ const calcZForBBox = (bbox, w, h, query) => {
|
|||
|
||||
z -= Math.max(
|
||||
Math.log((maxCorner[0] - minCorner[0]) / w_),
|
||||
Math.log((maxCorner[1] - minCorner[1]) / h_),
|
||||
Math.log((maxCorner[1] - minCorner[1]) / h_)
|
||||
) / Math.LN2;
|
||||
|
||||
z = Math.max(Math.log(Math.max(w, h) / 256) / Math.LN2, Math.min(25, z));
|
||||
|
|
@ -253,7 +253,7 @@ export const serve_rendered = {
|
|||
bearing: bearing,
|
||||
pitch: pitch,
|
||||
width: width,
|
||||
height: height,
|
||||
height: height
|
||||
};
|
||||
if (z === 0) {
|
||||
params.width *= 2;
|
||||
|
|
@ -293,8 +293,8 @@ export const serve_rendered = {
|
|||
raw: {
|
||||
width: params.width * scale,
|
||||
height: params.height * scale,
|
||||
channels: 4,
|
||||
},
|
||||
channels: 4
|
||||
}
|
||||
});
|
||||
|
||||
if (z > 2 && tileMargin > 0) {
|
||||
|
|
@ -304,7 +304,7 @@ export const serve_rendered = {
|
|||
left: tileMargin * scale,
|
||||
top: (tileMargin + yoffset) * scale,
|
||||
width: width * scale,
|
||||
height: height * scale,
|
||||
height: height * scale
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -346,7 +346,7 @@ export const serve_rendered = {
|
|||
|
||||
res.set({
|
||||
'Last-Modified': item.lastModified,
|
||||
'Content-Type': `image/${format}`,
|
||||
'Content-Type': `image/${format}`
|
||||
});
|
||||
return res.status(200).send(buffer);
|
||||
});
|
||||
|
|
@ -379,7 +379,7 @@ export const serve_rendered = {
|
|||
const tileSize = 256;
|
||||
const tileCenter = mercator.ll([
|
||||
((x + 0.5) / (1 << z)) * (256 << z),
|
||||
((y + 0.5) / (1 << z)) * (256 << z),
|
||||
((y + 0.5) / (1 << z)) * (256 << z)
|
||||
], z);
|
||||
return respondImage(item, z, tileCenter[0], tileCenter[1], 0, 0,
|
||||
tileSize, tileSize, scale, format, res, next);
|
||||
|
|
@ -533,7 +533,7 @@ export const serve_rendered = {
|
|||
|
||||
const bbox_ = mercator.convert(bbox, '900913');
|
||||
const center = mercator.inverse(
|
||||
[(bbox_[0] + bbox_[2]) / 2, (bbox_[1] + bbox_[3]) / 2],
|
||||
[(bbox_[0] + bbox_[2]) / 2, (bbox_[1] + bbox_[3]) / 2]
|
||||
);
|
||||
|
||||
const z = calcZForBBox(bbox, w, h, req.query);
|
||||
|
|
@ -564,7 +564,7 @@ export const serve_rendered = {
|
|||
add: (options, repo, params, id, publicUrl, dataResolver) => {
|
||||
const map = {
|
||||
renderers: [],
|
||||
sources: {},
|
||||
sources: {}
|
||||
};
|
||||
|
||||
let styleJSON;
|
||||
|
|
@ -587,7 +587,7 @@ export const serve_rendered = {
|
|||
const fontstack = unescape(parts[2]);
|
||||
const range = parts[3].split('.')[0];
|
||||
getFontsPbf(
|
||||
null, options.paths[protocol], fontstack, range, existingFonts,
|
||||
null, options.paths[protocol], fontstack, range, existingFonts
|
||||
).then((concated) => {
|
||||
callback(null, {data: concated});
|
||||
}, (err) => {
|
||||
|
|
@ -634,7 +634,7 @@ export const serve_rendered = {
|
|||
request({
|
||||
url: req.url,
|
||||
encoding: null,
|
||||
gzip: true,
|
||||
gzip: true
|
||||
}, (err, res, body) => {
|
||||
const parts = url.parse(req.url);
|
||||
const extension = path.extname(parts.pathname).toLowerCase();
|
||||
|
|
@ -660,7 +660,7 @@ export const serve_rendered = {
|
|||
callback(null, response);
|
||||
});
|
||||
}
|
||||
},
|
||||
}
|
||||
});
|
||||
renderer.load(styleJSON);
|
||||
createCallback(null, renderer);
|
||||
|
|
@ -671,7 +671,7 @@ export const serve_rendered = {
|
|||
create: createRenderer.bind(null, ratio),
|
||||
destroy: (renderer) => {
|
||||
renderer.release();
|
||||
},
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -715,7 +715,7 @@ export const serve_rendered = {
|
|||
'maxzoom': 20,
|
||||
'bounds': [-180, -85.0511, 180, 85.0511],
|
||||
'format': 'png',
|
||||
'type': 'baselayer',
|
||||
'type': 'baselayer'
|
||||
};
|
||||
const attributionOverride = params.tilejson && params.tilejson.attribution;
|
||||
Object.assign(tileJSON, params.tilejson || {});
|
||||
|
|
@ -728,7 +728,7 @@ export const serve_rendered = {
|
|||
map,
|
||||
dataProjWGStoInternalWGS: null,
|
||||
lastModified: new Date().toUTCString(),
|
||||
watermark: params.watermark || options.watermark,
|
||||
watermark: params.watermark || options.watermark
|
||||
};
|
||||
repo[id] = repoobj;
|
||||
|
||||
|
|
@ -783,7 +783,7 @@ export const serve_rendered = {
|
|||
source.type = type;
|
||||
source.tiles = [
|
||||
// meta url which will be detected when requested
|
||||
`mbtiles://${name}/{z}/{x}/{y}.${info.format || 'pbf'}`,
|
||||
`mbtiles://${name}/{z}/{x}/{y}.${info.format || 'pbf'}`
|
||||
];
|
||||
delete source.scheme;
|
||||
|
||||
|
|
@ -830,5 +830,5 @@ export const serve_rendered = {
|
|||
});
|
||||
}
|
||||
delete repo[id];
|
||||
},
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ export const serve_style = {
|
|||
spritePath = path.join(options.paths.sprites,
|
||||
styleJSON.sprite
|
||||
.replace('{style}', path.basename(styleFile, '.json'))
|
||||
.replace('{styleJsonFolder}', path.relative(options.paths.sprites, path.dirname(styleFile))),
|
||||
.replace('{styleJsonFolder}', path.relative(options.paths.sprites, path.dirname(styleFile)))
|
||||
);
|
||||
styleJSON.sprite = `local://styles/${id}/sprite`;
|
||||
}
|
||||
|
|
@ -150,9 +150,9 @@ export const serve_style = {
|
|||
styleJSON,
|
||||
spritePath,
|
||||
publicUrl,
|
||||
name: styleJSON.name,
|
||||
name: styleJSON.name
|
||||
};
|
||||
|
||||
return true;
|
||||
},
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ export function server(opts) {
|
|||
styles: {},
|
||||
rendered: {},
|
||||
data: {},
|
||||
fonts: {},
|
||||
fonts: {}
|
||||
};
|
||||
|
||||
app.enable('trust proxy');
|
||||
|
|
@ -48,7 +48,7 @@ export function server(opts) {
|
|||
const logFormat = opts.logFormat || defaultLogFormat;
|
||||
app.use(morgan(logFormat, {
|
||||
stream: opts.logFile ? fs.createWriteStream(opts.logFile, {flags: 'a'}) : process.stdout,
|
||||
skip: (req, res) => opts.silent && (res.statusCode === 200 || res.statusCode === 304),
|
||||
skip: (req, res) => opts.silent && (res.statusCode === 200 || res.statusCode === 304)
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
@ -112,7 +112,7 @@ export function server(opts) {
|
|||
serve_rendered.init(options, serving.rendered)
|
||||
.then((sub) => {
|
||||
app.use('/styles/', sub);
|
||||
}),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -143,7 +143,7 @@ export function server(opts) {
|
|||
let id = mbtiles.substr(0, mbtiles.lastIndexOf('.')) || mbtiles;
|
||||
while (data[id]) id += '_';
|
||||
data[id] = {
|
||||
'mbtiles': mbtiles,
|
||||
'mbtiles': mbtiles
|
||||
};
|
||||
return id;
|
||||
}
|
||||
|
|
@ -165,7 +165,7 @@ export function server(opts) {
|
|||
}
|
||||
}
|
||||
return mbtilesFile;
|
||||
},
|
||||
}
|
||||
));
|
||||
} else {
|
||||
item.serve_rendered = false;
|
||||
|
|
@ -186,7 +186,7 @@ export function server(opts) {
|
|||
startupPromises.push(
|
||||
serve_font(options, serving.fonts).then((sub) => {
|
||||
app.use('/', sub);
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
for (const id of Object.keys(data)) {
|
||||
|
|
@ -197,7 +197,7 @@ export function server(opts) {
|
|||
}
|
||||
|
||||
startupPromises.push(
|
||||
serve_data.add(options, serving.data, item, id, opts.publicUrl),
|
||||
serve_data.add(options, serving.data, item, id, opts.publicUrl)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -211,7 +211,7 @@ export function server(opts) {
|
|||
path.extname(file.name).toLowerCase() == '.json') {
|
||||
const id = path.basename(file.name, '.json');
|
||||
const item = {
|
||||
style: file.name,
|
||||
style: file.name
|
||||
};
|
||||
addStyle(id, item, false, false);
|
||||
}
|
||||
|
|
@ -234,7 +234,7 @@ export function server(opts) {
|
|||
|
||||
if (eventType == 'add' || eventType == 'change') {
|
||||
const item = {
|
||||
style: filename,
|
||||
style: filename
|
||||
};
|
||||
addStyle(id, item, false, false);
|
||||
}
|
||||
|
|
@ -251,7 +251,7 @@ export function server(opts) {
|
|||
version: styleJSON.version,
|
||||
name: styleJSON.name,
|
||||
id: id,
|
||||
url: `${getPublicUrl(opts.publicUrl, req)}styles/${id}/style.json${query}`,
|
||||
url: `${getPublicUrl(opts.publicUrl, req)}styles/${id}/style.json${query}`
|
||||
});
|
||||
}
|
||||
res.send(result);
|
||||
|
|
@ -267,7 +267,7 @@ export function server(opts) {
|
|||
path = `${type}/${id}`;
|
||||
}
|
||||
info.tiles = getTileUrls(req, info.tiles, path, info.format, opts.publicUrl, {
|
||||
'pbf': options.pbfAlias,
|
||||
'pbf': options.pbfAlias
|
||||
});
|
||||
arr.push(info);
|
||||
}
|
||||
|
|
@ -368,7 +368,7 @@ export function server(opts) {
|
|||
|
||||
data_.xyz_link = getTileUrls(
|
||||
req, tilejson.tiles, `data/${id}`, tilejson.format, opts.publicUrl, {
|
||||
'pbf': options.pbfAlias,
|
||||
'pbf': options.pbfAlias
|
||||
})[0];
|
||||
}
|
||||
if (data_.filesize) {
|
||||
|
|
@ -387,7 +387,7 @@ export function server(opts) {
|
|||
}
|
||||
return {
|
||||
styles: Object.keys(styles).length ? styles : null,
|
||||
data: Object.keys(data).length ? data : null,
|
||||
data: Object.keys(data).length ? data : null
|
||||
};
|
||||
});
|
||||
|
||||
|
|
@ -462,7 +462,7 @@ export function server(opts) {
|
|||
return {
|
||||
app: app,
|
||||
server: server,
|
||||
startupPromise: startupPromise,
|
||||
startupPromise: startupPromise
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -70,8 +70,8 @@ export const fixTileJSONCenter = (tileJSON) => {
|
|||
(tileJSON.bounds[1] + tileJSON.bounds[3]) / 2,
|
||||
Math.round(
|
||||
-Math.log((tileJSON.bounds[2] - tileJSON.bounds[0]) / 360 / tiles) /
|
||||
Math.LN2,
|
||||
),
|
||||
Math.LN2
|
||||
)
|
||||
];
|
||||
}
|
||||
};
|
||||
|
|
@ -121,7 +121,7 @@ export const getFontsPbf = (allowedFonts, fontPath, names, range, fallbacks) =>
|
|||
const queue = [];
|
||||
for (const font of fonts) {
|
||||
queue.push(
|
||||
getFontPbf(allowedFonts, fontPath, font, range, clone(allowedFonts || fallbacks)),
|
||||
getFontPbf(allowedFonts, fontPath, font, range, clone(allowedFonts || fallbacks))
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ before(function() {
|
|||
const running = server({
|
||||
configPath: 'config.json',
|
||||
port: 8888,
|
||||
publicUrl: '/test/',
|
||||
publicUrl: '/test/'
|
||||
});
|
||||
global.app = running.app;
|
||||
global.server = running.server;
|
||||
|
|
|
|||
Loading…
Reference in a new issue