From 6788237ec7fb0b0529180c16ef0611794ec6cf77 Mon Sep 17 00:00:00 2001 From: javi Date: Tue, 4 Feb 2014 18:13:34 +0100 Subject: [PATCH] fixed windshaft provider --- lib/torque/provider.windshaft.js | 26 +++++++++++++++++++++----- test/provider.windshaft.test.js | 18 +++++++++++++----- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/lib/torque/provider.windshaft.js b/lib/torque/provider.windshaft.js index d42e5a3..bad4014 100644 --- a/lib/torque/provider.windshaft.js +++ b/lib/torque/provider.windshaft.js @@ -179,6 +179,13 @@ }; }, + setOptions: function(opt) { + for(var k in opt) { + this.options[k] = opt[k]; + } + return false; + }, + _extraParams: function() { if (this.options.extra_params) { var p = []; @@ -219,6 +226,7 @@ * `zoom` quadtree zoom level */ _getTileData: function(coord, zoom, callback) { + var self = this; var prof_fetch_time = Profiler.metric('ProviderJSON:tile_fetch_time').start(); var subdomains = this.options.subdomains || '0123'; var index = Math.abs(coord.x + coord.y) % subdomains.length; @@ -231,7 +239,7 @@ var extra = this._extraParams(); torque.net.get( url + (extra ? "?" + extra: ''), function (data) { if (data && data.responseText) { - var rows = JSON.parse(data.responseText).rows; + var rows = JSON.parse(data.responseText); callback(self.proccessTile(rows, coord, zoom)); } else { callback(null); @@ -245,7 +253,7 @@ end: this.options.end * 1000, step: this.options.step, steps: this.options.steps, - columnType: this.options.is_time ? 'date': 'number' + columnType: this.options.column_type }; }, @@ -303,7 +311,9 @@ var named = this.options.named_map; if(named) { - url = this._tilerHost() + "/maps/" + named.name + "/jsonp" + //tiles/template + url = this._tilerHost() + "/tiles/template/" + named.name + "/jsonp" + //url = this._tilerHost() + "/maps/" + named.name + "/jsonp" } else { layergroup = { "version": "1.0.1", @@ -330,10 +340,16 @@ "?config=" + encodeURIComponent(JSON.stringify(layergroup)) + "&callback=?" + (extra ? "&" + extra: ''); - torque.net.get(url, function (data) { + torque.net.jsonp(url, function (data) { if (data) { //TODO: update options with layer metadata - self.templateUrl = self.url() + "/tiles/layergroup/" + data.layergroup_id + "/{z}/{x}/{y}.torque.json"; + var torque_key = Object.keys(data.metadata.torque)[0] + var opt = data.metadata.torque[torque_key]; + for(var k in opt) { + self.options[k] = opt[k]; + } + self.templateUrl = self.url() + "/tiles/layergroup/" + data.layergroupid + "/" + torque_key + "/{z}/{x}/{y}.json.torque"; + self._setReady(true); } }); }, diff --git a/test/provider.windshaft.test.js b/test/provider.windshaft.test.js index 9bd78c4..9476fe4 100644 --- a/test/provider.windshaft.test.js +++ b/test/provider.windshaft.test.js @@ -3,10 +3,15 @@ var lastCall; var old_net; module('provider.windshaft', { setup: function() { - old_net = torque.net.get; + 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; - callback({ layergroup_id: 'testlg' }); + callback(null); }; windshaft = new torque.providers.windshaft({ table: 'test', @@ -21,7 +26,8 @@ module('provider.windshaft', { }); }, teardown: function() { - torque.net.get = old_net; + torque.net.jsonp = old_net; + torque.net.get = old_get; } }); @@ -41,6 +47,8 @@ module('provider.windshaft', { var url = "http://rambo.cartodb.com:80/tiles/layergroup?config=" + encodeURIComponent(JSON.stringify(layergroup)) + "&callback=" equal(lastCall.indexOf(url), 0); + equal(windshaft.options.data_steps, 10); + }); test("url", function() { @@ -60,14 +68,14 @@ module('provider.windshaft', { name: 'test_named' } }); - var url = "http://rambo.cartodb.com:80/maps/test_named/jsonp?config"; + var url = "http://rambo.cartodb.com:80/tiles/template/test_named/jsonp?config"; equal(lastCall.indexOf(url), 0); }); test("fetch tile", function() { windshaft._ready = true; windshaft.getTileData({x: 0, y: 1}, 2, function() {}); - equal(lastCall,"http://rambo.cartodb.com:80/tiles/layergroup/testlg/2/0/1.torque.json?testing=abcd%25"); + equal(lastCall,"http://rambo.cartodb.com:80/tiles/layergroup/testlg/0/2/0/1.json.torque?testing=abcd%25"); });