torque/test/provider.tilejson.js

57 lines
2.0 KiB
JavaScript
Raw Normal View History

2015-10-01 21:32:58 +08:00
var torque = require('../lib/torque/core');
2015-10-02 00:46:33 +08:00
var tilejsonprovider, url;
2015-10-01 21:32:58 +08:00
var lastCall;
var old_net;
QUnit.module('provider.tilejson', {
setup: function() {
old_net = torque.net.jsonp;
old_get = torque.net.get;
torque.net.jsonp = function(url, callback) {
lastCall = url;
callback({ layergroupid: 'testlg', metadata: { torque: { 0: { data_steps:10 }} } });
};
torque.net.get = function(url, callback) {
lastCall = url;
var tilejson = '{"tiles": ["./{z}/{x}/{y}.json.torque"], "end": 903000, "column_type": "number", "start": 1000, "data_steps": 1, "resolution": 32}';
callback({response: tilejson});
};
2015-10-02 00:46:33 +08:00
tilejsonprovider = new torque.providers.tileJSON({
2015-10-01 21:32:58 +08:00
tileJSON: 'http://what.ev.er/tilejson.json',
cartocss: '#test{}',
resolution: 1,
steps: 10
});
},
teardown: function() {
torque.net.jsonp = old_net;
torque.net.get = old_get;
}
});
test("tile urls should be correctly formed for relative urls", function() {
2015-10-02 00:46:33 +08:00
tilejsonprovider._ready = true;
tilejsonprovider.getTileData({x: 0, y: 1, corrected: {x: 0, y: 1}}, 2, function() {});
2015-10-01 21:32:58 +08:00
equal(lastCall,"http://what.ev.er/./2/0/1.json.torque");
2015-10-02 00:42:55 +08:00
});
test("tile urls should be correctly formed for absolute urls", function() {
torque.net.jsonp = function(url, callback) {
lastCall = url;
callback({ layergroupid: 'testlg', metadata: { torque: { 0: { data_steps:10 }} } });
};
torque.net.get = function(url, callback) {
lastCall = url;
var tilejson = '{"tiles": ["http://ca.ta.pam/{z}/{x}/{y}.json.torque"], "end": 903000, "column_type": "number", "start": 1000, "data_steps": 1, "resolution": 32}';
callback({response: tilejson});
};
2015-10-02 00:46:33 +08:00
tilejsonprovider = new torque.providers.tileJSON({
2015-10-02 00:42:55 +08:00
tileJSON: 'http://what.ev.er/tilejson.json',
cartocss: '#test{}',
resolution: 1,
steps: 10
});
2015-10-02 00:46:33 +08:00
tilejsonprovider._ready = true;
tilejsonprovider.getTileData({x: 0, y: 1, corrected: {x: 0, y: 1}}, 2, function() {});
2015-10-02 00:42:55 +08:00
equal(lastCall,"http://ca.ta.pam/2/0/1.json.torque");
2015-10-01 21:32:58 +08:00
});