1

I have an animation working using Torque, and the animation is set to pause on load. this automatically loads on the first date of the data series. Is there a way to draw the animation so that it loads on a specified date? My viz also has a datepicker that I would like to be able to set to control the animation so that if I select a date from the datepicker, the animation jumps/redraws and loads to that same date while still having the full timeline of data.

Here's my current code.

Is there a way to set the step in the .on('load') method?

// Draw animation layer using torque
cartodb.createLayer(map, reservoir_storage_layer, options = {https:true, time_slider:true})
  .addTo(map, 1)
  .done(function(layer) {
      layer.on('change:time', function(changes){
          var currentDate = layer.getTime();
          //console.log(currentDate);
          if (changes.step === layer.provider.getSteps() - 1) {
                  layer.pause();
          };
      });
      layer.on('load', function(){
          layer.pause();
      });
1

The setStep() method handles this. Easy fix!

// calculate start step
step = Math.round((new Date(selectDate) - new Date(startDate))/(1000*60*60*24))
console.log(step)

// Draw animation layer using torque
cartodb.createLayer(map, reservoir_storage_layer, options = {https:true, time_slider:true})
  .addTo(map, 1)
  .done(function(layer) {
      layer.on('change:time', function(changes){
          var currentDate = layer.getTime();
          //console.log(currentDate);
          if (changes.step === layer.provider.getSteps() - 1) {
                  layer.pause();
          };
      });
      layer.on('load', function(){
          layer.setStep(step);
          layer.pause();
      });
  })
  • mark the question as answered then, please :) – Jorge Sanz Apr 11 '18 at 9:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.