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>
|
||||
tileserver({
|
||||
index: "index.json" + location.search,
|
||||
tilejson: "%n/index.json" + location.search
|
||||
tilejson: "%n.json" + location.search
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
@ -303,15 +303,5 @@ module.exports = function(maps, options, prefix) {
|
|||
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;
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -48,24 +48,38 @@ module.exports = function(opts, callback) {
|
|||
// serve index.html on the root
|
||||
app.use('/', express.static(path.join(__dirname, '../public')));
|
||||
|
||||
// aggregate index.json on root for multiple sources
|
||||
app.get('/index.json', function(req, res, next) {
|
||||
var queue = [];
|
||||
Object.keys(config).forEach(function(prefix) {
|
||||
var map = maps[prefix];
|
||||
queue.push(function(callback) {
|
||||
var info = clone(map.tileJSON);
|
||||
app.get(/^(\/[^\/]+)\.json$/, function(req, res, next) {
|
||||
var prefix = req.params[0];
|
||||
if (prefix == '/index') {
|
||||
var queue = [];
|
||||
Object.keys(config).forEach(function(mapPrefix) {
|
||||
var map = maps[mapPrefix];
|
||||
queue.push(function(callback) {
|
||||
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);
|
||||
info.tiles = utils.getTileUrls(
|
||||
req.protocol, config[mapPrefix].domains, req.headers.host,
|
||||
mapPrefix, '/{z}/{x}/{y}.{format}', info.format, req.query.key);
|
||||
|
||||
callback(null, info);
|
||||
callback(null, info);
|
||||
});
|
||||
});
|
||||
});
|
||||
return async.parallel(queue, function(err, results) {
|
||||
return res.send(results);
|
||||
});
|
||||
return async.parallel(queue, function(err, 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() {
|
||||
|
|
|
@ -17,17 +17,17 @@ describe('Metadata', function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe('/test/index.json', function() {
|
||||
describe('/test.json', function() {
|
||||
it('is json', function(done) {
|
||||
supertest(app)
|
||||
.get('/test/index.json')
|
||||
.get('/test.json')
|
||||
.expect(200)
|
||||
.expect('Content-Type', /application\/json/, done);
|
||||
});
|
||||
|
||||
it('has valid basename and tiles', function(done) {
|
||||
supertest(app)
|
||||
.get('/test/index.json')
|
||||
.get('/test.json')
|
||||
.expect(function(res) {
|
||||
res.body.basename.should.equal('test');
|
||||
res.body.tiles.length.should.be.greaterThan(0);
|
||||
|
|
Loading…
Reference in a new issue