Add xray viewer for vector data

This commit is contained in:
Petr Sloup
2016-03-17 11:31:33 +01:00
parent c132d7fba8
commit 34befd43c9
6 changed files with 141 additions and 18 deletions

View File

@@ -143,18 +143,7 @@ module.exports = function(options, repo, params, id) {
};
Object.assign(tileJSON, params.tilejson || {});
tileJSON.tiles = params.domains || options.domains;
if (tileJSON.bounds && !tileJSON.center) {
var fitWidth = 1024;
var tiles = fitWidth / 256;
tileJSON.center = [
(tileJSON.bounds[0] + tileJSON.bounds[2]) / 2,
(tileJSON.bounds[1] + tileJSON.bounds[3]) / 2,
Math.round(
-Math.log((tileJSON.bounds[2] - tileJSON.bounds[0]) / 360 / tiles) /
Math.LN2
)
];
}
utils.fixTileJSONCenter(tileJSON);
var queue = [];
Object.keys(styleJSON.sources).forEach(function(name) {

View File

@@ -31,6 +31,7 @@ module.exports = function(options, repo, params, id) {
tileJSON['format'] = 'pbf';
Object.assign(tileJSON, params.tilejson || {});
utils.fixTileJSONCenter(tileJSON);
});
});

View File

@@ -153,10 +153,6 @@ module.exports = function(opts, callback) {
// serve web presentations
app.use('/', express.static(path.join(__dirname, '../public/resources')));
handlebars.registerHelper('json', function(context) {
return JSON.stringify(context);
});
var templates = path.join(__dirname, '../public/templates');
var serveTemplate = function(path, template, dataGetter) {
fs.readFile(templates + '/' + template + '.tmpl', function(err, content) {
@@ -199,9 +195,19 @@ module.exports = function(opts, callback) {
}
}
});
var data = clone(serving.vector || {});
Object.keys(data).forEach(function(id) {
var vector = data[id];
var center = vector.center;
if (center) {
vector.viewer_hash = '#' + center[2] + '/' +
center[1].toFixed(5) + '/' +
center[0].toFixed(5);
}
});
return {
styles: styles,
data: serving.vector
data: data
};
});
@@ -222,6 +228,16 @@ module.exports = function(opts, callback) {
return res.redirect(301, '/styles/' + req.params.id + '/');
});
serveTemplate('/vector/:id/', 'xray', function(params) {
var id = params.id;
var vector = serving.vector[id];
if (!vector) {
return null;
}
vector.id = id;
return vector;
});
var server = app.listen(process.env.PORT || opts.port, function() {
console.log('Listening at http://%s:%d/',
this.address().address, this.address().port);

View File

@@ -22,3 +22,18 @@ module.exports.getTileUrls = function(req, domains, path, format) {
return uris;
};
module.exports.fixTileJSONCenter = function(tileJSON) {
if (tileJSON.bounds && !tileJSON.center) {
var fitWidth = 1024;
var tiles = fitWidth / 256;
tileJSON.center = [
(tileJSON.bounds[0] + tileJSON.bounds[2]) / 2,
(tileJSON.bounds[1] + tileJSON.bounds[3]) / 2,
Math.round(
-Math.log((tileJSON.bounds[2] - tileJSON.bounds[0]) / 360 / tiles) /
Math.LN2
)
];
}
};