Simplify the startup procedure a little (#271)

This commit is contained in:
Petr Sloup 2019-12-30 17:08:15 +01:00
parent 515c295898
commit e2387d164b
2 changed files with 13 additions and 33 deletions

View file

@ -36,7 +36,7 @@
"proj4": "2.6.0", "proj4": "2.6.0",
"request": "2.88.0", "request": "2.88.0",
"sharp": "0.23.4", "sharp": "0.23.4",
"tileserver-gl-styles": "1.2.0" "tileserver-gl-styles": "2.0.0"
}, },
"devDependencies": { "devDependencies": {
"mocha": "^6.2.2", "mocha": "^6.2.2",

View file

@ -90,7 +90,9 @@ const startServer = (configPath, config) => {
}; };
const startWithMBTiles = (mbtilesFile) => { const startWithMBTiles = (mbtilesFile) => {
console.log(`Automatically creating config file for ${mbtilesFile}`); console.log(`[INFO] Automatically creating config file for ${mbtilesFile}`);
console.log(`[INFO] Only a basic preview style will be used.`);
console.log(`[INFO] See documentation to learn how to create config.json file.`);
mbtilesFile = path.resolve(process.cwd(), mbtilesFile); mbtilesFile = path.resolve(process.cwd(), mbtilesFile);
@ -131,9 +133,8 @@ const startWithMBTiles = (mbtilesFile) => {
if (info.format === 'pbf' && if (info.format === 'pbf' &&
info.name.toLowerCase().indexOf('openmaptiles') > -1) { info.name.toLowerCase().indexOf('openmaptiles') > -1) {
const omtV = (info.version || '').split('.');
config['data'][`v${omtV[0]}`] = { config['data'][`v3`] = {
"mbtiles": path.basename(mbtilesFile) "mbtiles": path.basename(mbtilesFile)
}; };
@ -143,34 +144,12 @@ const startWithMBTiles = (mbtilesFile) => {
const styleFileRel = styleName + '/style.json'; const styleFileRel = styleName + '/style.json';
const styleFile = path.resolve(styleDir, 'styles', styleFileRel); const styleFile = path.resolve(styleDir, 'styles', styleFileRel);
if (fs.existsSync(styleFile)) { if (fs.existsSync(styleFile)) {
const styleJSON = require(styleFile); config['styles'][styleName] = {
const omtVersionCompatibility = "style": styleFileRel,
((styleJSON || {}).metadata || {})['openmaptiles:version'] || 'x'; "tilejson": {
const m = omtVersionCompatibility.toLowerCase().split('.'); "bounds": bounds
}
const isCompatible = !( };
m[0] !== 'x' && (
m[0] !== omtV[0] || (
(m[1] || 'x') !== 'x' && (
m[1] !== omtV[1] || (
(m[2] || 'x') !== 'x' &&
m[2] !== omtV[2]
)
)
)
)
);
if (isCompatible) {
config['styles'][styleName] = {
"style": styleFileRel,
"tilejson": {
"bounds": bounds
}
};
} else {
console.log(`Style ${styleName} requires OpenMapTiles version ${omtVersionCompatibility} but mbtiles is version ${info.version}`);
}
} }
} }
} else { } else {
@ -216,7 +195,8 @@ fs.stat(path.resolve(opts.config), (err, stats) => {
const url = 'https://github.com/klokantech/tileserver-gl/releases/download/v1.3.0/zurich_switzerland.mbtiles'; const url = 'https://github.com/klokantech/tileserver-gl/releases/download/v1.3.0/zurich_switzerland.mbtiles';
const filename = 'zurich_switzerland.mbtiles'; const filename = 'zurich_switzerland.mbtiles';
const stream = fs.createWriteStream(filename); const stream = fs.createWriteStream(filename);
console.log(`Downloading sample data (${filename}) from ${url}`); console.log(`No MBTiles found`);
console.log(`[DEMO] Downloading sample data (${filename}) from ${url}`);
stream.on('finish', () => startWithMBTiles(filename)); stream.on('finish', () => startWithMBTiles(filename));
return request.get(url).pipe(stream); return request.get(url).pipe(stream);
} }