Skip to content

Commit

Permalink
Support XYZ at 2.0.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
Young Hahn committed Jul 3, 2011
1 parent 63d505c commit 92e738e
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions servers/Tile.bones
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ server = Bones.Server.extend({

this.param('tileset', this.load);

// 1.0.0 endpoints. Scheme is TMS.
this.get('/1.0.0/:tileset/:z/:x/:y.(png|jpg|jpeg)', this.tile);
this.get('/1.0.0/:tileset/:z/:x/:y.grid.json', this.grid);
this.get('/1.0.0/:tileset/layer.json', this.layer);
// x.0.0 endpoints.
this.get('/:version(1|2).0.0/:tileset/:z/:x/:y.(png|jpg|jpeg)', this.tile);
this.get('/:version(1|2).0.0/:tileset/:z/:x/:y.grid.json', this.grid);
this.get('/:version(1|2).0.0/:tileset/layer.json', this.layer);

this.get('/download/:tileset.mbtiles', this.download);
this.get('/status', this.status);
Expand Down Expand Up @@ -86,12 +86,12 @@ server = Bones.Server.extend({
},

// Tile endpoint
// Incoming coordinates are in TMS.
tile: function(req, res, next) {
var z = req.param('z'), x = req.param('x'), y = req.param('y');

// Flip Y coordinate because the Tilesource interface is in XYZ.
y = Math.pow(2, z) - 1 - y;
// 1.0.0: incoming request TMS => tilesource XYZ
// 2.0.0: incoming request XYZ => tilesource XYZ
req.param('version') === '1' && (y = Math.pow(2, z) - 1 - y);

This comment has been minimized.

Copy link
@kkaefer

kkaefer Jul 3, 2011

Contributor

I think if (req.param('version') === '1') is far more readable. If you want to save space:

if (req.param('version') === '1') y = Math.pow(2, z) - 1 - y;

instead of

if (req.param('version') === '1') {
    y = Math.pow(2, z) - 1 - y;
}

This comment has been minimized.

Copy link
@yhahn

yhahn Jul 3, 2011

Contributor

Agreed, got it here 629fac7


var headers = _.clone(this.config.header);
res.model.source.getTile(z, x, y, function(err, tile, options) {
Expand All @@ -106,12 +106,12 @@ server = Bones.Server.extend({
},

// Grid endpoint.
// Incoming coordinates are in TMS.
grid: function(req, res, next) {
var z = req.param('z'), x = req.param('x'), y = req.param('y');

// Flip Y coordinate because the Tilesource interface is in XYZ.
y = Math.pow(2, z) - 1 - y;
// 1.0.0: incoming request TMS => tilesource XYZ
// 2.0.0: incoming request XYZ => tilesource XYZ
req.param('version') === '1' && (y = Math.pow(2, z) - 1 - y);

var headers = _.clone(this.config.header);
res.model.source.getGrid(z, x, y, function(err, grid, options) {
Expand All @@ -125,14 +125,8 @@ server = Bones.Server.extend({
});
},

// Layer endpoint for version 2.0.0.
// Layer endpoint.
layer: function(req, res, next) {
var data = res.model.toJSON();

// Make sure these are arrays.
if (data.formatter) data.formatter = [ data.formatter ];
if (data.legend) data.legend = [ data.legend ];

res.send(res.model);
res.send(res.model.toJSON());
}
});

0 comments on commit 92e738e

Please sign in to comment.