Skip to content

Commit

Permalink
Generalize, fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Young Hahn committed Apr 7, 2011
1 parent 04a8c41 commit 775349b
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 30 deletions.
37 changes: 21 additions & 16 deletions mvc/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,36 @@ if (typeof require !== 'undefined') {
var Bones = Bones || {};
Bones.models = Bones.models || {};

// Set options on initialize.
Backbone.Collection.prototype.initialize =
Backbone.Model.prototype.initialize = function(attributes, options) {
options = options || {};
if (this.collection && this.collection.options) {
this.options = this.collection.options;
} else {
this.options = options;
}
if (this.models) {
_(this.models).each(function(model) {
model.options = this.options;
});
}
};

// Tileset
// ---
// A single tileset, corresponding to an `.mbtiles` file. `model.id` is the
// file basename, e.g. `foo.mbtiles` has an `id` of `foo`.
Bones.models.Tileset = Backbone.Model.extend({
initialize: function(attributes, options) {
options = options || {};
if (this.collection) {
this.uiHost = this.collection.uiHost;
this.tileHost = this.collection.tileHost;
} else {
this.uiHost = options.uiHost;
this.tileHost = options.tileHost;
}
},
url: function() {
return '/api/Tileset/' + this.id;
},
layerURL: function() {
return this.tileHost;
if (this.options.tileHost) {
return this.options.tileHost;
} else {
return ['http://localhost:8888/'];
}
},
// Get ZXY of tile of tileset's center and minzoom. From [OSM wiki][1].
// [1]: http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#lon.2Flat_to_tile_numbers_2
Expand Down Expand Up @@ -65,11 +75,6 @@ Bones.models.Tileset = Backbone.Model.extend({
// --------
// Collection of all tileset models.
Bones.models.Tilesets = Backbone.Collection.extend({
initialize: function(models, options) {
options = options || {};
this.uiHost = options.uiHost;
this.tileHost = options.tileHost;
},
model: Bones.models.Tileset,
url: '/api/Tileset',
comparator: function(model) {
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/wax/wax.center.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@new OpenLayers.Layer.TMS",
"control_room",
[
"http://localhost:8888"
"http://localhost:8888/"
],
{
"projection": [
Expand Down Expand Up @@ -64,7 +64,7 @@
],
"units": "m",
"maxResolution": 1.40625,
"theme": "http://locahost:8888maps/ol/dark.css",
"theme": "http://localhost:8888/maps/ol/dark.css",
"maxExtent": [
"@new OpenLayers.Bounds",
-20037508.34,
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/wax/wax.el.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@new OpenLayers.Layer.TMS",
"control_room",
[
"http://localhost:8888"
"http://localhost:8888/"
],
{
"projection": [
Expand Down Expand Up @@ -64,7 +64,7 @@
],
"units": "m",
"maxResolution": 1.40625,
"theme": "http://locahost:8888maps/ol/dark.css",
"theme": "http://localhost:8888/maps/ol/dark.css",
"maxExtent": [
"@new OpenLayers.Bounds",
-20037508.34,
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/wax/wax.layers.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@new OpenLayers.Layer.TMS",
"control_room",
[
"http://localhost:8888"
"http://localhost:8888/"
],
{
"projection": [
Expand Down Expand Up @@ -64,7 +64,7 @@
],
"units": "m",
"maxResolution": 1.40625,
"theme": "http://locahost:8888maps/ol/dark.css",
"theme": "http://localhost:8888/maps/ol/dark.css",
"maxExtent": [
"@new OpenLayers.Bounds",
-20037508.34,
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/wax/wax.options.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@new OpenLayers.Layer.TMS",
"control_room",
[
"http://localhost:8888"
"http://localhost:8888/"
],
{
"projection": [
Expand Down Expand Up @@ -64,7 +64,7 @@
],
"units": "m",
"maxResolution": 1.40625,
"theme": "http://locahost:8888maps/ol/dark.css",
"theme": "http://localhost:8888/maps/ol/dark.css",
"maxExtent": [
"@new OpenLayers.Bounds",
-20037508.34,
Expand Down
14 changes: 8 additions & 6 deletions test/tilestream.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
var assert = require('assert'),
var _ = require('underscore')._,
assert = require('assert'),
tilestream = require('tilestream')({
tiles: __dirname + '/fixtures/tiles',
uiPort: 8888,
tilePort: 8888
});
}),
request = { headers: { 'host': 'localhost:8888' } };

module.exports = {
'tile': function() {
Expand Down Expand Up @@ -142,7 +144,7 @@ module.exports = {
);
assert.response(
tilestream.uiServer,
{ url: '/wax.json?layers[]=control_room' },
_.extend({ url: '/wax.json?layers[]=control_room' }, request),
{ status: 200 },
function(res) {
assert.deepEqual(fixtures.layers, JSON.parse(res.body));
Expand All @@ -156,7 +158,7 @@ module.exports = {
);
assert.response(
tilestream.uiServer,
{ url: '/wax.json?layers[]=control_room&el=foo' },
_.extend({ url: '/wax.json?layers[]=control_room&el=foo' }, request),
{ status: 200 },
function(res) {
assert.deepEqual(fixtures.el, JSON.parse(res.body));
Expand All @@ -180,7 +182,7 @@ module.exports = {
);
assert.response(
tilestream.uiServer,
{ url: '/wax.json?layers[]=control_room&center[]=40&center[]=40&center[]=2' },
_.extend({ url: '/wax.json?layers[]=control_room&center[]=40&center[]=40&center[]=2' }, request),
{ status: 200 },
function(res) {
assert.deepEqual(fixtures.center, JSON.parse(res.body));
Expand All @@ -199,7 +201,7 @@ module.exports = {
);
assert.response(
tilestream.uiServer,
{ url: '/wax.json?layers[]=control_room&options[]=tooltips' },
_.extend({ url: '/wax.json?layers[]=control_room&options[]=tooltips' }, request),
{ status: 200 },
function(res) {
assert.deepEqual(fixtures.options, JSON.parse(res.body));
Expand Down

0 comments on commit 775349b

Please sign in to comment.