Browse files

Simplify and de-wax MapClient

  • Loading branch information...
1 parent 97940c2 commit ce7cda797f3810027cd91f1b8a9d90a63a337c10 @tmcw tmcw committed Oct 28, 2011
Showing with 37 additions and 56 deletions.
  1. +4 −4 models/Tileset.server.bones
  2. +7 −12 servers/Tile.bones
  3. +3 −1 views/Map.bones
  4. +23 −39 views/MapClient.bones
View
8 models/Tileset.server.bones
@@ -2,25 +2,25 @@ var tilelive = require('tilelive');
var url = require('url');
models.Tileset.syncread = function(data, options) {
- data.scheme = data.scheme || 'tms';
+ data.scheme = 'xyz';
data.center = data.center || [0, 0, 0];
data.tiles = data.tiles || _(options.tileHost).map(function(host) {
return url.format({
host: host,
- pathname: options.basepath + '1.0.0/' + data.id + '/{z}/{x}/{y}.png',
+ pathname: options.basepath + 'v2/' + data.id + '/{z}/{x}/{y}.png',
protocol: 'http:'
});
});
if (data.formatter) data.grids = data.grids || _(options.tileHost).map(function(host) {
return url.format({
host: host,
- pathname: options.basepath + '1.0.0/' + data.id + '/{z}/{x}/{y}.grid.json',
+ pathname: options.basepath + 'v2/' + data.id + '/{z}/{x}/{y}.grid.json',
protocol: 'http:'
});
});
if (data.basename) data.download = url.format({
host: options.tileHost[0],
- pathname: options.basepath + 'download/' + data.basename,
+ pathname: options.basepath + 'v2/' + data.basename,
protocol: 'http:'
});
return data;
View
19 servers/Tile.bones
@@ -24,13 +24,10 @@ server = Bones.Server.extend({
this.param('tileset', this.load);
- // x.0.0 endpoints.
- this.get('/v:version(1|2)/:tileset/:z/:x/:y.(png|jpg|jpeg)', this.tile);
- this.get('/v:version(1|2)/:tileset/:z/:x/:y.grid.json', this.grid);
- this.get('/v:version(1|2)/:tileset/layer.json', this.layer);
-
- this.get('/:version(1|2)(.0.0)?/:tileset.mbtiles', this.download);
- this.get('/download/:tileset.mbtiles', this.download);
+ this.get('/v2/:tileset/:z/:x/:y.(png|jpg|jpeg)', this.tile);
+ this.get('/v2/:tileset/:z/:x/:y.grid.json', this.grid);
+ this.get('/v2/:tileset/layer.json', this.layer);
+ this.get('/v2/:tileset.mbtiles', this.download);
this.get('/crossdomain.xml', this.crossdomainXML);
this.get('/status', this.status);
@@ -99,11 +96,9 @@ server = Bones.Server.extend({
// Tile endpoint
tile: function(req, res, next) {
- var z = req.param('z'), x = req.param('x'), y = req.param('y');
-
- // 1.0.0: incoming request TMS => tilesource XYZ
- // 2.0.0: incoming request XYZ => tilesource XYZ
- if (req.param('version') === '1') y = Math.pow(2, z) - 1 - y;
+ var z = req.param('z'),
+ x = req.param('x'),
+ y = req.param('y');
var headers = _.clone(this.config.header);
res.model.source.getTile(z, x, y, function(err, tile, options) {
View
4 views/Map.bones
@@ -34,7 +34,9 @@ view = views.HUD.extend({
data.buttons.push({id:'download', title:'Download'});
}
$(this.el).html(templates.Map(data));
- this.map = new views.MapClient({model: this.model});
+ this.map = new views.MapClient({
+ model: this.model
+ });
this.bind('ready', this.map.ready);
$(this.el).append(this.map.el);
return this;
View
62 views/MapClient.bones
@@ -5,47 +5,31 @@ view = Backbone.View.extend({
className: 'MapClient',
id: 'map',
initialize: function(options) {
- _.bindAll(this, 'ready', 'mm', 'mmNav');
+ _.bindAll(this, 'ready');
},
ready: function() {
- var wax = this.generateWax();
- if (!wax.layers || wax.layers.length === 0) return;
+ var mm = com.modestmaps;
- $.ajax({
- dataType: 'jsonp',
- url: this.waxURL(wax),
- context: this,
- callback: 'grid',
- callbackParameter: 'callback',
- success: this.render,
- error: function() {}
- });
- },
- render: function(data) {
- console.log(arguments);
- },
- // Since this is client-side we cannot use url.format().
- waxURL: function(wax) {
- return 'http://' +
- this.model.options.uiHost +
- this.model.options.basepath +
- 'api/wax.json?' +
- $.param(wax);
- },
- generateWax: function(callback) {
- var wax = this.model.wax();
- wax.el = $(this.el).attr('id');
- wax.size && (delete wax.size);
- return wax;
- },
- mm: function() {
- this.map.addCallback('zoomed', this.mmNav);
- this.map.addCallback('extentset', this.mmNav);
- this.mmNav();
- },
- mmNav: function() {
- if (!$('.zoom').size()) return;
- $('.zoom.active').removeClass('active');
- $('.zoom-' + this.map.getZoom()).addClass('active');
+ function mmNav() {
+ if (!$('.zoom').size()) return;
+ $('.zoom.active').removeClass('active');
+ $('.zoom-' + map.getZoom()).addClass('active');
+ }
+
+ var center = this.model.get('center');
+ var map = new mm.Map(this.el,
+ new wax.mm.connector(this.model.toJSON())
+ ).setCenterZoom(
+ new mm.Location(center[1], center[0]
+ ), center[2]);
+
+ wax.mm.zoomer(map).appendTo(map.parent);
+ wax.mm.zoombox(map);
+ wax.mm.attribution(map).appendTo(map.parent);
+ map.addCallback('zoomed', mmNav);
+ map.addCallback('extentset', mmNav);
+ mmNav();
+
+ this.map = map;
}
});

0 comments on commit ce7cda7

Please sign in to comment.