Merge pull request #128 from CartoDB/timetostep

Adds timeToStep() method
This commit is contained in:
Francisco Dans 2015-02-17 16:22:24 +01:00
commit db41e24b42
2 changed files with 16 additions and 0 deletions

View File

@ -240,6 +240,14 @@ GMapsTorqueLayer.prototype = torque.extend({},
return new Date(time);
},
timeToStep: function(timestamp) {
if (typeof timestamp === "Date") timestamp = timestamp.getTime();
if (!this.provider) return 0;
var times = this.provider.getKeySpan();
var step = (this.provider.getSteps() * (timestamp - times.start)) / (times.end - times.start);
return step;
},
getStep: function() {
return this.key;
},

View File

@ -295,6 +295,14 @@ L.TorqueLayer = L.CanvasLayer.extend({
var time = times.start + (times.end - times.start)*(step/this.provider.getSteps());
return new Date(time);
},
timeToStep: function(timestamp) {
if (typeof timestamp === "Date") timestamp = timestamp.getTime();
if (!this.provider) return 0;
var times = this.provider.getKeySpan();
var step = (this.provider.getSteps() * (timestamp - times.start)) / (times.end - times.start);
return step;
},
getStep: function() {
return this.key;