Prepare for the new tile schema and compatibility checking

This commit is contained in:
Petr Sloup 2016-12-13 16:00:16 +01:00
parent dfb07b8286
commit 0018ed9524
2 changed files with 41 additions and 16 deletions

View file

@ -35,7 +35,7 @@
"request": "2.79.0",
"sharp": "0.16.2",
"sphericalmercator": "1.0.5",
"tileserver-gl-styles": "0.3.0",
"tileserver-gl-styles": "1.0.0",
"vector-tile": "1.3.0"
},
"optionalDependencies": {

View file

@ -78,8 +78,7 @@ var startWithMBTiles = function(mbtilesFile) {
"options": {
"paths": {
"root": styleDir,
"fonts": "glyphs",
"sprites": "sprites",
"fonts": "fonts",
"styles": "styles",
"mbtiles": path.dirname(mbtilesFile)
}
@ -89,27 +88,53 @@ var startWithMBTiles = function(mbtilesFile) {
};
if (info.format == 'pbf' &&
info.name.toLowerCase().indexOf('osm2vectortiles') > -1) {
config['data']['osm2vectortiles'] = {
info.name.toLowerCase().indexOf('openmaptiles') > -1) {
config['data']['openmaptiles'] = {
"mbtiles": path.basename(mbtilesFile)
};
var omtV = (info.version || '').split('.');
var styles = fs.readdirSync(path.resolve(styleDir, 'styles'));
for (var i = 0; i < styles.length; i++) {
var styleFilename = styles[i];
if (styleFilename.endsWith('.json')) {
var styleName = styles[i];
var styleFileRel = styleName + '/style.json';
var styleFile = path.resolve(styleDir, 'styles', styleFileRel);
if (fs.existsSync(styleFile)) {
var styleJSON = require(styleFile);
var omtVersionCompatibility =
((styleJSON || {}).metadata || {})['openmaptiles:version'] || 'x';
var m = omtVersionCompatibility.toLowerCase().split('.');
var 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) {
var styleObject = {
"style": path.basename(styleFilename),
"style": styleFileRel,
"tilejson": {
"bounds": bounds
}
};
config['styles'][path.basename(styleFilename, '.json')] =
styleObject;
config['styles'][styleName] = styleObject;
} else {
console.log('Style', styleName, 'requires OpenMapTiles version',
omtVersionCompatibility, 'but mbtiles is version', info.version);
}
}
}
} else {
console.log('WARN: MBTiles not in "osm2vectortiles" format. ' +
console.log('WARN: MBTiles not in "openmaptiles" format. ' +
'Serving raw data only...');
config['data'][(info.id || 'mbtiles')
.replace(/\//g, '_')