multiple fixes

This commit is contained in:
javi 2013-10-17 15:51:12 +02:00
parent 87c09a81d2
commit cf23d6c5b2
9 changed files with 79 additions and 12 deletions

View File

@ -82,6 +82,11 @@
return this;
},
steps: function(_) {
this.options.steps = _;
return this.rescale();
},
step: function(s) {
if(arguments.length === 0) return this.range(this.domain(this._time));
this._time = this.domainInv(this.rangeInv(s));

View File

@ -28,7 +28,11 @@
for(var i = 0; c && i < c.length; ++i) {
if(c[i] === callback) remove.push(i);
}
while(i = remove.pop()) c.splice(i, 1);
while((i = remove.pop()) !== undefined) c.splice(i, 1);
};
Event.callbacks = function(evt) {
return (this._evt_callbacks && this._evt_callbacks[evt]) || [];
};
exports.torque.Event = Event;

View File

@ -444,7 +444,6 @@ CanvasLayer.prototype.repositionCanvas_ = function() {
var projection = this.getProjection();
var divTopLeft = projection.fromLatLngToDivPixel(this.topLeft_);
console.log(this.topLeft_.lng(), divTopLeft.x);
// when the zoom level is low, more than one map can be shown in the screen
// so the canvas should be attach to the map with more are in the screen
var mapSize = (1 << this.getMap().getZoom())*256;

View File

@ -27,6 +27,7 @@ function GMapsTorqueLayer(options) {
this.pause = this.animator.pause.bind(this.animator);
this.toggle = this.animator.toggle.bind(this.animator);
this.setDuration = this.animator.duration.bind(this.animator);
this.isRunning = this.animator.isRunning.bind(this.animator);
CanvasLayer.call(this, {
@ -80,6 +81,15 @@ GMapsTorqueLayer.prototype = _.extend({},
},
setSQL: function(sql) {
if (!this.provider || !this.provider.setSQL) {
throw new Error("this provider does not support SQL");
}
this.provider.setSQL(sql);
this._reloadTiles();
return this;
},
setBlendMode: function(_) {
this.renderer.setBlendMode(_);
this.redraw();
@ -87,6 +97,7 @@ GMapsTorqueLayer.prototype = _.extend({},
setSteps: function(steps) {
this.provider.setSteps(steps);
this.animator.steps(steps);
this._reloadTiles();
},
@ -95,6 +106,10 @@ GMapsTorqueLayer.prototype = _.extend({},
this._reloadTiles();
},
getTimeBounds: function() {
return this.provider && this.provider.getKeySpan();
},
getCanvas: function() {
return this.canvas;
},
@ -161,7 +176,7 @@ GMapsTorqueLayer.prototype = _.extend({},
if (!this.provider) return 0;
var times = this.provider.getKeySpan();
var time = times.start + (times.end - times.start)*(step/this.options.steps);
return new Date(time*1000);
return new Date(time);
},
/**

View File

@ -12,7 +12,7 @@ L.Mixin.TileLoader = {
},
_removeTileLoader: function() {
map.off({
this._map.off({
'moveend': this._updateTiles
}, this);
this._removeTiles();

View File

@ -34,6 +34,7 @@ L.TorqueLayer = L.CanvasLayer.extend({
this.pause = this.animator.pause.bind(this.animator);
this.toggle = this.animator.toggle.bind(this.animator);
this.setDuration = this.animator.duration.bind(this.animator);
this.isRunning = this.animator.isRunning.bind(this.animator);
L.CanvasLayer.prototype.initialize.call(this, options);
@ -58,6 +59,15 @@ L.TorqueLayer = L.CanvasLayer.extend({
this._removeTileLoader();
},
setSQL: function(sql) {
if (!this.provider || !this.provider.setSQL) {
throw new Error("this provider does not support SQL");
}
this.provider.setSQL(sql);
this._reloadTiles();
return this;
},
setBlendMode: function(_) {
this.renderer.setBlendMode(_);
this.redraw();
@ -65,6 +75,7 @@ L.TorqueLayer = L.CanvasLayer.extend({
setSteps: function(steps) {
this.provider.setSteps(steps);
this.animator.steps(steps);
this._reloadTiles();
},
@ -73,6 +84,11 @@ L.TorqueLayer = L.CanvasLayer.extend({
this._reloadTiles();
},
getTimeBounds: function() {
return this.provider && this.provider.getKeySpan();
},
/**
* render the selectef key
* don't call this function directly, it's called by
@ -125,7 +141,7 @@ L.TorqueLayer = L.CanvasLayer.extend({
stepToTime: function(step) {
var times = this.provider.getKeySpan();
var time = times.start + (times.end - times.start)*(step/this.options.steps);
return new Date(time*1000);
return new Date(time);
},
/**

View File

@ -152,9 +152,9 @@
options = options || {};
torque.net.get(this.url() + "?q=" + encodeURIComponent(sql) + (extra ? "&" + extra: ''), function (data) {
if(options.parseJSON) {
data = JSON.parse(data.responseText);
data = JSON.parse(data && data.responseText);
}
callback(data);
callback && callback(data);
});
},
@ -203,7 +203,7 @@
" SELECT ST_SnapToGrid(i.the_geom_webmercator, p.res) g" +
", {countby} c" +
", floor(({column_conv} - {start})/{step}) d" +
" FROM {table} i, par p " +
" FROM ({_sql}) i, par p " +
" WHERE i.the_geom_webmercator && p.ext " +
" GROUP BY g, d" +
") " +
@ -218,7 +218,8 @@
zoom: zoom,
x: coord.x,
y: coord.y,
column_conv: column_conv
column_conv: column_conv,
_sql: this.getSQL()
});
var self = this;
@ -244,6 +245,14 @@
this._fetchKeySpan();
},
setSQL: function(sql) {
if (this.options.sql != sql) {
this.options.sql = sql;
this._ready = false;
this._fetchKeySpan();
}
},
setSteps: function(steps) {
if (this.options.steps !== steps) {
this.options.steps = steps;
@ -255,6 +264,10 @@
return this.options.bounds;
},
getSQL: function() {
return this.options.sql || "select * from " + this.options.table;
},
//
// the data range could be set by the user though ``start``
// option. It can be fecthed from the table when the start
@ -263,9 +276,13 @@
_fetchKeySpan: function() {
var self = this;
var max_col, min_col, max_tmpl, min_tmpl;
var query = format("select {column} from {table} limit 0", this.options);
var query = format("select {column} from ({sql}) __torque_wrap_sql limit 0", {
column: this.options.column,
sql: self.getSQL()
});
this.sql(query, function (data) {
if (!data) return;
self.options.is_time = data.fields[self.options.column].type === 'date';
if (self.options.is_time){
@ -279,10 +296,10 @@
max_col = format(max_tmpl, { column: self.options.column });
min_col = format(min_tmpl, { column: self.options.column });
var sql = format("SELECT st_xmax(st_envelope(st_collect(the_geom))) xmax,st_ymax(st_envelope(st_collect(the_geom))) ymax, st_xmin(st_envelope(st_collect(the_geom))) xmin, st_ymin(st_envelope(st_collect(the_geom))) ymin, {max_col} max, {min_col} min FROM {table}", {
var sql = format("SELECT st_xmax(st_envelope(st_collect(the_geom))) xmax,st_ymax(st_envelope(st_collect(the_geom))) ymax, st_xmin(st_envelope(st_collect(the_geom))) xmin, st_ymin(st_envelope(st_collect(the_geom))) ymin, {max_col} max, {min_col} min FROM ({sql}) __torque_wrap_sql", {
max_col: max_col,
min_col: min_col,
table: self.options.table
sql: self.getSQL()
});
self.sql(sql, function(data) {

View File

@ -3,6 +3,7 @@ var json, url;
module('provider.json')
QUnit.testStart(function() {
json = new torque.providers.json({
table: 'test',
user: "rambo",
resolution: 1,
steps: 10,
@ -22,5 +23,14 @@ QUnit.testStart(function() {
equal(torque.net.lastCall().url, url);
});
test("getSQL", function() {
var s;
equal(json.getSQL(), "select * from test");
json.setSQL(s='select * from test limit 10');
equal(json.getSQL(), s);
json.setSQL(null);
equal(json.getSQL(), "select * from test");
});

View File

@ -16,6 +16,7 @@
<script src="../lib/torque/provider.json.js"></script>
<script src="data/torque.array.json"></script>
<script src="core.js"></script>
<script src="provider.jsonarray.js"></script>
<script src="provider.json.js"></script>
</body>