0

CartoDB automatically display only days and months on my custom map. However, I would like to show the following format (included in my data): dd-mm hh-mm.

Here is my code:

<script>
function main() {      
  var map = new L.Map('map', {
    zoomControl: true,
    center: [0,0],
    zoom: 7
  });

  L.tileLayer('URL', {
  }).addTo(map);

      cartodb.createLayer(map, {
      type: "torque",
      order: 1,
      options: {
        table_name: "table_name",
        user_name: "",
       tile_style: $('#cartocss_template').html()
        }
    }).done(function(layer) {
      map.addLayer(layer);
    });
  }
  window.onload = main;
</script>
1

By using createVis you can get the time_slider element and format it accordingly:

 cartodb.createVis('map', 'viz.json')
    .done(function(vis, layers) {
      var slider = vis.getOverlay('time_slider')
      slider.formatter(function(d) {
        return  d.getUTCMonth()+"-"+ d.getUTCDay() + " "+ d.getUTCHours() + ":"+ d.getUTCMinutes();
      })
    })
    .error(function(err) {
      console.log(err);
    });
  }
1
  • Thanks! So, it's impossible to configure with createLayer? Because I included a lot of elements directly in my code (custom basemap, carto_css template, etc).
    – Florent
    Apr 28 '15 at 16:44
1

It could be done also with createLayer. Check this example

http://bl.ocks.org/ernesmb/3f8662160e37d3741082

This is the important part:

cartodb.createLayer(map,  {
          type: 'torque',
          order: 1,
          options: {
            query: "SQL",
            user_name:'USERNAME',
            cartocss: "CartoCSS"
          }
    },{})
        .done(function(layer) {
          var slider = map.viz.timeSlider;
          slider.formatter(function(d) {
            return d.getUTCFullYear() + "/" + d.getUTCMonth() + "/"+ d.getUTCDate() + " "+d.getUTCHours()+":"+d.getUTCMinutes()+":"+d.getUTCSeconds();
          })
        }).addTo(map);

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.