diff --git a/public/templates/index.tmpl b/public/templates/index.tmpl
index 3f1aad4..ff5400e 100644
--- a/public/templates/index.tmpl
+++ b/public/templates/index.tmpl
@@ -43,7 +43,7 @@
{{name}}
(id: {{@key}})
- X-Ray viewer
+ X-Ray viewer
TileJSON
{{/each}}
diff --git a/public/templates/xray.tmpl b/public/templates/xray.tmpl
new file mode 100644
index 0000000..e44738a
--- /dev/null
+++ b/public/templates/xray.tmpl
@@ -0,0 +1,102 @@
+
+
+
+
+ {{name}} - TileServer GL
+
+
+
+
+ {{name}}
+
+
+
+
+
+
diff --git a/src/serve_raster.js b/src/serve_raster.js
index 78304ef..201a632 100644
--- a/src/serve_raster.js
+++ b/src/serve_raster.js
@@ -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) {
diff --git a/src/serve_vector.js b/src/serve_vector.js
index f123a09..dc95414 100644
--- a/src/serve_vector.js
+++ b/src/serve_vector.js
@@ -31,6 +31,7 @@ module.exports = function(options, repo, params, id) {
tileJSON['format'] = 'pbf';
Object.assign(tileJSON, params.tilejson || {});
+ utils.fixTileJSONCenter(tileJSON);
});
});
diff --git a/src/server.js b/src/server.js
index f102ecc..e0a8f13 100644
--- a/src/server.js
+++ b/src/server.js
@@ -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);
diff --git a/src/utils.js b/src/utils.js
index 7e21504..fda3b5f 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -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
+ )
+ ];
+ }
+};