Serve TileJSONs on /{prefix}.json
This commit is contained in:
parent
9efa22b52b
commit
6f644a4c03
5 changed files with 33 additions and 39 deletions
|
@ -23,7 +23,7 @@
|
||||||
<script>
|
<script>
|
||||||
tileserver({
|
tileserver({
|
||||||
index: "index.json" + location.search,
|
index: "index.json" + location.search,
|
||||||
tilejson: "%n/index.json" + location.search
|
tilejson: "%n.json" + location.search
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -303,15 +303,5 @@ module.exports = function(maps, options, prefix) {
|
||||||
return respondImage(z, x, y, w, h, scale, format, res, next);
|
return respondImage(z, x, y, w, h, scale, format, res, next);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/index.json', function(req, res, next) {
|
|
||||||
var info = clone(map.tileJSON);
|
|
||||||
|
|
||||||
info.tiles = utils.getTileUrls(req.protocol, domains, req.headers.host,
|
|
||||||
prefix, tilePath, info.format,
|
|
||||||
req.query.key);
|
|
||||||
|
|
||||||
return res.send(info);
|
|
||||||
});
|
|
||||||
|
|
||||||
return app;
|
return app;
|
||||||
};
|
};
|
||||||
|
|
|
@ -73,15 +73,5 @@ module.exports = function(maps, options, prefix) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/index.json', function(req, res, next) {
|
|
||||||
var info = clone(map.tileJSON);
|
|
||||||
|
|
||||||
info.tiles = utils.getTileUrls(req.protocol, domains, req.headers.host,
|
|
||||||
prefix, tilePath, info.format,
|
|
||||||
req.query.key);
|
|
||||||
|
|
||||||
return res.send(info);
|
|
||||||
});
|
|
||||||
|
|
||||||
return app;
|
return app;
|
||||||
};
|
};
|
||||||
|
|
|
@ -48,17 +48,18 @@ module.exports = function(opts, callback) {
|
||||||
// serve index.html on the root
|
// serve index.html on the root
|
||||||
app.use('/', express.static(path.join(__dirname, '../public')));
|
app.use('/', express.static(path.join(__dirname, '../public')));
|
||||||
|
|
||||||
// aggregate index.json on root for multiple sources
|
app.get(/^(\/[^\/]+)\.json$/, function(req, res, next) {
|
||||||
app.get('/index.json', function(req, res, next) {
|
var prefix = req.params[0];
|
||||||
|
if (prefix == '/index') {
|
||||||
var queue = [];
|
var queue = [];
|
||||||
Object.keys(config).forEach(function(prefix) {
|
Object.keys(config).forEach(function(mapPrefix) {
|
||||||
var map = maps[prefix];
|
var map = maps[mapPrefix];
|
||||||
queue.push(function(callback) {
|
queue.push(function(callback) {
|
||||||
var info = clone(map.tileJSON);
|
var info = clone(map.tileJSON);
|
||||||
|
|
||||||
info.tiles = utils.getTileUrls(
|
info.tiles = utils.getTileUrls(
|
||||||
req.protocol, config[prefix].domains, req.headers.host,
|
req.protocol, config[mapPrefix].domains, req.headers.host,
|
||||||
prefix, '/{z}/{x}/{y}.{format}', info.format, req.query.key);
|
mapPrefix, '/{z}/{x}/{y}.{format}', info.format, req.query.key);
|
||||||
|
|
||||||
callback(null, info);
|
callback(null, info);
|
||||||
});
|
});
|
||||||
|
@ -66,6 +67,19 @@ module.exports = function(opts, callback) {
|
||||||
return async.parallel(queue, function(err, results) {
|
return async.parallel(queue, function(err, results) {
|
||||||
return res.send(results);
|
return res.send(results);
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
var map = maps[prefix];
|
||||||
|
if (!map || !map.tileJSON) {
|
||||||
|
return res.status(404).send('Not found');
|
||||||
|
}
|
||||||
|
var info = clone(map.tileJSON);
|
||||||
|
|
||||||
|
info.tiles = utils.getTileUrls(
|
||||||
|
req.protocol, config[prefix].domains, req.headers.host,
|
||||||
|
prefix, '/{z}/{x}/{y}.{format}', info.format, req.query.key);
|
||||||
|
|
||||||
|
return res.send(info);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var server = app.listen(process.env.PORT || opts.port, function() {
|
var server = app.listen(process.env.PORT || opts.port, function() {
|
||||||
|
|
|
@ -17,17 +17,17 @@ describe('Metadata', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('/test/index.json', function() {
|
describe('/test.json', function() {
|
||||||
it('is json', function(done) {
|
it('is json', function(done) {
|
||||||
supertest(app)
|
supertest(app)
|
||||||
.get('/test/index.json')
|
.get('/test.json')
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.expect('Content-Type', /application\/json/, done);
|
.expect('Content-Type', /application\/json/, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('has valid basename and tiles', function(done) {
|
it('has valid basename and tiles', function(done) {
|
||||||
supertest(app)
|
supertest(app)
|
||||||
.get('/test/index.json')
|
.get('/test.json')
|
||||||
.expect(function(res) {
|
.expect(function(res) {
|
||||||
res.body.basename.should.equal('test');
|
res.body.basename.should.equal('test');
|
||||||
res.body.tiles.length.should.be.greaterThan(0);
|
res.body.tiles.length.should.be.greaterThan(0);
|
||||||
|
|
Loading…
Reference in a new issue