Simplify the startup procedure a little (#271)
This commit is contained in:
parent
515c295898
commit
e2387d164b
2 changed files with 13 additions and 33 deletions
|
@ -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",
|
||||||
|
|
32
src/main.js
32
src/main.js
|
@ -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);
|
|
||||||
const omtVersionCompatibility =
|
|
||||||
((styleJSON || {}).metadata || {})['openmaptiles:version'] || 'x';
|
|
||||||
const m = omtVersionCompatibility.toLowerCase().split('.');
|
|
||||||
|
|
||||||
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] = {
|
config['styles'][styleName] = {
|
||||||
"style": styleFileRel,
|
"style": styleFileRel,
|
||||||
"tilejson": {
|
"tilejson": {
|
||||||
"bounds": bounds
|
"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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue