I've been trying to create a carto map with a torque layer as indicated in the Torque.js documentation, but I keep getting the same error:

Uncaught TypeError: L.TorqueLayer is not a constructor

var CARTOCSS = [
  'Map {',
  '-torque-time-attribute: "date";',
  '-torque-aggregation-function: "count(cartodb_id)";',
  '-torque-frame-count: 760;',
  '-torque-animation-duration: 15;',
  '-torque-resolution: 2',
  '#layer {',
  '  marker-width: 3;',
  '  marker-fill-opacity: 0.8;',
  '  marker-fill: #FEE391; ',
  '  comp-op: "lighten";',

var torqueLayer = new L.TorqueLayer({
  user       : 'your_username',
  table      : 'your_table_name',
  cartocss: CARTOCSS

can someone tell me how to make L.TorqueLayer work?

  • Could you share the rest of the code? – ramiroaznar Apr 18 '18 at 10:05

remember to link Torque.js in your .html file. for example(from github):

<script src="../dist/torque.full.uncompressed.js"  type="application/javascript" charset="utf-8"></script>

this should fix your problem. if not,there is another solution: you can use CartoDB.js library instead of directly using Torque.js:

 cartodb.createLayer(map, {
      type: "torque",
      order: 1,
      options: {
        table_name: "your table",
        user_name: "your user name",
        tile_style: 'your cartoCSS'
    }).done(function(layer) {


 <script src="http://libs.cartocdn.com/cartodb.js/v3/cartodb.js" type="application/javascript"></script>

I am new to Torque too,also sorry for my rusty english,it's not my native language:)

| improve this answer | |

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.