Skip to content

Commit

Permalink
Serve any vector/raster mbtiles, use styles only for osm2vt (close #51,
Browse files Browse the repository at this point in the history
  • Loading branch information
petrsloup committed Sep 27, 2016
1 parent f201dee commit 09859c1
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ var startWithMBTiles = function(mbtilesFile) {
}
var instance = new mbtiles(mbtilesFile, function(err) {
instance.getInfo(function(err, info) {
if (info.format != 'pbf') {
console.log('ERROR: MBTiles format is not "pbf".');
process.exit(1);
}
var bounds = info.bounds;

var styleDir = path.resolve(__dirname, "../node_modules/tileserver-gl-styles/");
Expand All @@ -89,26 +85,35 @@ var startWithMBTiles = function(mbtilesFile) {
}
},
"styles": {},
"data": {
"osm2vectortiles": {
"mbtiles": path.basename(mbtilesFile)
}
}
"data": {}
};

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 styleObject = {
"style": path.basename(styleFilename),
"tilejson": {
"bounds": bounds
}
};
config['styles'][path.basename(styleFilename, '.json')] =
styleObject;
if (info.format == 'pbf' &&
info.name.toLowerCase().indexOf('osm2vectortiles') > -1) {
config['data']['osm2vectortiles'] = {
"mbtiles": path.basename(mbtilesFile)
};

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 styleObject = {
"style": path.basename(styleFilename),
"tilejson": {
"bounds": bounds
}
};
config['styles'][path.basename(styleFilename, '.json')] =
styleObject;
}
}
} else {
console.log('WARN: MBTiles not in "osm2vectortiles" format. ' +
'Serving raw data only...');
config['data'][info.id || 'mbtiles'] = {
"mbtiles": path.basename(mbtilesFile)
};
}

if (opts.verbose) {
Expand Down

0 comments on commit 09859c1

Please sign in to comment.