diff --git a/examples/ow-scrub.html b/examples/ow-scrub.html index 56dfcb7..dc86b4a 100644 --- a/examples/ow-scrub.html +++ b/examples/ow-scrub.html @@ -89,6 +89,28 @@ map.setMapTypeId(google.maps.MapTypeId.ROADMAP); map.setOptions({styles:map_style.google_maps_customization_style}); + + function init_slider( that ){ + var that_opts = that.options; + $('body').append('
'); + // Init jQuery UI options + $("#torque-slider").slider({ + min: Math.round(that_opts.start), + max: Math.floor(that_opts.end), + value: Math.round(that_opts.start), + step: that._step, + slide: function(event, ui){ + that._current = ui.value; + var date = new Date(that._current * 1000); + var date_arry = date.toString().substr(4).split(' '); + that._display.set_time((that._current - that.start) / that._step); + } + }); + }; + function on_move (that) { + $( "#torque-slider" ).slider({ value: that._current }); + } + var TorqueOptions = { user:'viz2', table:'ow', @@ -103,7 +125,8 @@ trails:true, point_type:'circle', cellsize:1, - scrub: true, + scrub: init_slider, + scrub_move: on_move } var torque = null; diff --git a/examples/uspo-scrub.html b/examples/uspo-scrub.html index 818a11b..b7a5764 100644 --- a/examples/uspo-scrub.html +++ b/examples/uspo-scrub.html @@ -76,6 +76,26 @@ map.setMapTypeId(google.maps.MapTypeId.ROADMAP); map.setOptions({styles:map_style.google_maps_customization_style}); + + + function init_slider( that ){ + var that_opts = that.options; + $('body').append('
'); + // Init jQuery UI options + $("#torque-slider").slider({ + min: Math.round(that_opts.start), + max: Math.floor(that_opts.end), + value: Math.round(that_opts.start), + step: that._step, + slide: function(event, ui){ + that._current = ui.value; + var date = new Date(that._current * 1000); + var date_arry = date.toString().substr(4).split(' '); + that._display.set_time((that._current - that.start) / that._step); + } + }); + }; + var TorqueOptions = { user: "viz2", table: "us_po_offices", @@ -91,7 +111,7 @@ point_type:'circle', cellsize:2, autoplay: false, - scrub: true + scrub: init_slider } var torque = null; diff --git a/src/torque.js b/src/torque.js index 8344edc..251e05a 100644 --- a/src/torque.js +++ b/src/torque.js @@ -151,10 +151,9 @@ Torque.modules.layer = function (torque) { // If scrubbable, override other options that may have been set if (this.options.scrub){ + this.options.scrub(this); // this.options.autoplay = false; // this.options.trails = false; - $('body').append('
'); - } if (this.options.autoplay) { @@ -162,7 +161,6 @@ Torque.modules.layer = function (torque) { this.play(); } - init_slider(this); torque.log.info('Layer is now running!'); }, @@ -234,8 +232,8 @@ Torque.modules.layer = function (torque) { this._display.set_time((this._current - this.start) / this._step); - if (this.options.scrub==true){ - $( "#torque-slider" ).slider({ value: this._current }); + if (this.options.scrub_move){ + this.options.scrub_move(this) } if (this.running) { setTimeout(function () { @@ -243,19 +241,19 @@ Torque.modules.layer = function (torque) { }.bind(this), pause + 1000 * 1 / this.options.fps); } }, - scrub:function(scrub_current){ - this._current = scrub_current; - var date = new Date(this._current * 1000); - var date_arry = date.toString().substr(4).split(' '); - torque.clock.set('' + date_arry[0] + ' ' + date_arry[2] + ''); + // scrub:function(scrub_current){ + // this._current = scrub_current; + // var date = new Date(this._current * 1000); + // var date_arry = date.toString().substr(4).split(' '); + // torque.clock.set('' + date_arry[0] + ' ' + date_arry[2] + ''); - if (this.options.subtitles) { - torque.subtitles.set(date); - } + // if (this.options.subtitles) { + // torque.subtitles.set(date); + // } - this._display.set_time((this._current - this.start) / this._step); + // this._display.set_time((this._current - this.start) / this._step); - } + // } }); } @@ -338,20 +336,6 @@ Torque.modules.subtitles = function (torque) { }; }; -function init_slider( that ){ - var that_opts = that.options; - // Init jQuery UI options - $("#torque-slider").slider({ - min: Math.round(that_opts.start), - max: Math.floor(that_opts.end), - value: Math.round(that_opts.start), - step: that._step, - slide: function(event, ui){ - that.scrub(ui.value); - } - }); -}; - /** * Logging module that torquetes log messages to the console and to the Speed * Tracer API. It contains convenience methods for info(), warn(), error(),