Skip to content

Instantly share code, notes, and snippets.

@chriswhong
Created November 20, 2015 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chriswhong/a4d1e6305ecaf2ad507a to your computer and use it in GitHub Desktop.
Save chriswhong/a4d1e6305ecaf2ad507a to your computer and use it in GitHub Desktop.
Use cartodb.js to add a torque layer from a named map with auth_tokens enabled
var layerSource = {
type: "torque",
options: {
auth_token: '{yourAuthToken}',
user_name: "{yourCartoDBUsername}",
tile_style:"{torqueCartoCSS}",
named_map: {
name: "{namedmap}"
}
}
}
cartodb.createLayer(map, layerSource).done(function(layer) {
map.addLayer(layer);
});
@chriswhong
Copy link
Author

layer.setAuthToken() doesn't work for torque named maps, auth_token must be added to the options
The trick is that the tile_style, or CartoCSS must be defined in the layerSource definition
A viz.json for a torque layer will include the same layerSource including tile_style

@alasarr
Copy link

alasarr commented Dec 1, 2015

Great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment