TransWikia.com

Torque.js is not working: L.TorqueLayer is not a constructor

Geographic Information Systems Asked by Juan Salvatore on November 26, 2020

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

<script>
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";',
  '}'
].join('n');

var torqueLayer = new L.TorqueLayer({
  user       : 'your_username',
  table      : 'your_table_name',
  cartocss: CARTOCSS
});
torqueLayer.addTo(map);
torqueLayer.play()

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

One Answer

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) {
      map.addLayer(layer);
    });
  }

html:

 <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:)

Answered by Ringo Johnny on November 26, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP