0

I'm working on a torque map and would like it to just animate once and then stop. I've found loop=false, but am unsure if I can apply this in any way when I'm using the CartoDB editor.

Does anyone know if that is possible?

1

This is not directly possible from the Editor at the moment, you need to use CartoDB.js for that. Check this example by @javisantana here. It's detecting the last torque step and pausing the reproduction there.

<!DOCTYPE html>
<html>
<head>
<title>Easy example | CartoDB.js</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<link rel="shortcut icon" href="http://cartodb.com/assets/favicon.ico" />
<style>
  html, body, #map {
    height: 100%;
    padding: 0;
    margin: 0;
  }
 </style>

<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.css" />
</head>
<body>
<div id="map"></div>

<!-- include cartodb.js library -->
<script src="http://libs.cartocdn.com/cartodb.js/v3/cartodb.js"></script>

<script>
  function main() {
    cartodb.createVis('map', 'http://javi.cartodb.com/api/v2/viz/d4a5c7e4-4ad6-11e3-ab17-3085a9a9563c/viz.json', {
        shareable: true,
        title: true,
        description: true,
        search: true,
        tiles_loader: true
    })
    .done(function(vis, layers) {
      // there are 3 layers
      // - base color (gray)
      // - circuit
      // - car (blue)

      // torque layer is the third one (0 based index)
      var torqueLayer = layers[2]
      // listen for every animation step
      // and pause when we reach the map steps
      torqueLayer.on('change:time', function(changes) {
        if (changes.step === torqueLayer.provider.getSteps() - 1) {
          torqueLayer.pause();
        }
      })
    })
    .error(function(err) {
      console.log(err);
    });
  }

  window.onload = main;
 </script>
 </body>
 </html>

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.