Prepare for the new tile schema and compatibility checking
This commit is contained in:
parent
dfb07b8286
commit
0018ed9524
2 changed files with 41 additions and 16 deletions
|
@ -35,7 +35,7 @@
|
||||||
"request": "2.79.0",
|
"request": "2.79.0",
|
||||||
"sharp": "0.16.2",
|
"sharp": "0.16.2",
|
||||||
"sphericalmercator": "1.0.5",
|
"sphericalmercator": "1.0.5",
|
||||||
"tileserver-gl-styles": "0.3.0",
|
"tileserver-gl-styles": "1.0.0",
|
||||||
"vector-tile": "1.3.0"
|
"vector-tile": "1.3.0"
|
||||||
},
|
},
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
|
|
55
src/main.js
55
src/main.js
|
@ -78,8 +78,7 @@ var startWithMBTiles = function(mbtilesFile) {
|
||||||
"options": {
|
"options": {
|
||||||
"paths": {
|
"paths": {
|
||||||
"root": styleDir,
|
"root": styleDir,
|
||||||
"fonts": "glyphs",
|
"fonts": "fonts",
|
||||||
"sprites": "sprites",
|
|
||||||
"styles": "styles",
|
"styles": "styles",
|
||||||
"mbtiles": path.dirname(mbtilesFile)
|
"mbtiles": path.dirname(mbtilesFile)
|
||||||
}
|
}
|
||||||
|
@ -89,27 +88,53 @@ var startWithMBTiles = function(mbtilesFile) {
|
||||||
};
|
};
|
||||||
|
|
||||||
if (info.format == 'pbf' &&
|
if (info.format == 'pbf' &&
|
||||||
info.name.toLowerCase().indexOf('osm2vectortiles') > -1) {
|
info.name.toLowerCase().indexOf('openmaptiles') > -1) {
|
||||||
config['data']['osm2vectortiles'] = {
|
config['data']['openmaptiles'] = {
|
||||||
"mbtiles": path.basename(mbtilesFile)
|
"mbtiles": path.basename(mbtilesFile)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var omtV = (info.version || '').split('.');
|
||||||
|
|
||||||
var styles = fs.readdirSync(path.resolve(styleDir, 'styles'));
|
var styles = fs.readdirSync(path.resolve(styleDir, 'styles'));
|
||||||
for (var i = 0; i < styles.length; i++) {
|
for (var i = 0; i < styles.length; i++) {
|
||||||
var styleFilename = styles[i];
|
var styleName = styles[i];
|
||||||
if (styleFilename.endsWith('.json')) {
|
var styleFileRel = styleName + '/style.json';
|
||||||
var styleObject = {
|
var styleFile = path.resolve(styleDir, 'styles', styleFileRel);
|
||||||
"style": path.basename(styleFilename),
|
if (fs.existsSync(styleFile)) {
|
||||||
"tilejson": {
|
var styleJSON = require(styleFile);
|
||||||
"bounds": bounds
|
var omtVersionCompatibility =
|
||||||
}
|
((styleJSON || {}).metadata || {})['openmaptiles:version'] || 'x';
|
||||||
};
|
var m = omtVersionCompatibility.toLowerCase().split('.');
|
||||||
config['styles'][path.basename(styleFilename, '.json')] =
|
|
||||||
styleObject;
|
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": styleFileRel,
|
||||||
|
"tilejson": {
|
||||||
|
"bounds": bounds
|
||||||
|
}
|
||||||
|
};
|
||||||
|
config['styles'][styleName] = styleObject;
|
||||||
|
} else {
|
||||||
|
console.log('Style', styleName, 'requires OpenMapTiles version',
|
||||||
|
omtVersionCompatibility, 'but mbtiles is version', info.version);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log('WARN: MBTiles not in "osm2vectortiles" format. ' +
|
console.log('WARN: MBTiles not in "openmaptiles" format. ' +
|
||||||
'Serving raw data only...');
|
'Serving raw data only...');
|
||||||
config['data'][(info.id || 'mbtiles')
|
config['data'][(info.id || 'mbtiles')
|
||||||
.replace(/\//g, '_')
|
.replace(/\//g, '_')
|
||||||
|
|
Loading…
Reference in a new issue