Skip to content

Instantly share code, notes, and snippets.

@ernesmb
Last active February 6, 2016 12:39
Show Gist options
  • Save ernesmb/a7453def821ae9872eb1 to your computer and use it in GitHub Desktop.
Save ernesmb/a7453def821ae9872eb1 to your computer and use it in GitHub Desktop.
Torque Named Map

##create the map using authenticated call

curl 'https://{your_account_name}.cartodb.com/api/v1/map/named?api_key={your_api_key}' -H 'Content-Type: application/json' -d @config.json
{
"version": "0.0.1",
"name": "torque_named_map",
"auth": {
"method": "open"
},
"layergroup": {
"layers": [{
"type": "torque",
"options": {
"cartocss_version": "2.1.1",
"sql" : "select * from tweet_sample",
"cartocss": "Map { -torque-frame-count:256; -torque-animation-duration:30; -torque-time-attribute:'postedtime'; -torque-aggregation-function:'count(cartodb_id)'; -torque-resolution:2; -torque-data-aggregation:linear;} #tweet_sample{ comp-op: lighter; marker-fill-opacity: 0.9; marker-line-color: #FFF; marker-line-width: 0; marker-line-opacity: 1; marker-type: ellipse; marker-width: 6; marker-fill: #0F3B82;} #tweet_sample[frame-offset=1] { marker-width:8; marker-fill-opacity:0.45; } #tweet_sample[frame-offset=2] { marker-width:10; marker-fill-opacity:0.225; }" }
}]
}
}
<!DOCTYPE html>
<html>
<head>
<title>Torque Named Map | CartoDB</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="https://cartodb-libs.global.ssl.fastly.net/cartodb.js/v3/3.15/themes/css/cartodb.css" />
</head>
<body>
<div id="map"></div>
<!-- include cartodb.js library -->
<script src="https://cartodb-libs.global.ssl.fastly.net/cartodb.js/v3/3.15/cartodb.js"></script>
<!-- Drop your code between the script tags below! -->
<script>
function main() {
// create leaflet map
var map = L.map('map', {
zoomControl: false,
scrollWheelZoom: false,
center: [36, 2],
zoomControl: true,
zoom: 3
});
// add a base layer
L.tileLayer('http://tile.stamen.com/toner/{z}/{x}/{y}.png', {
attribution: 'Stamen'
}).addTo(map);
// add cartodb layer with one sublayer
cartodb.createLayer(map, {
user_name: 'ernestomb',
type: 'torque',
order: 1,
options: {
query: "",
table_name: "tweet_sample",
user_name: "ernestomb",
tile_style: 'Map { -torque-frame-count:256; -torque-animation-duration:30; -torque-time-attribute:"postedtime"; -torque-aggregation-function:"count(cartodb_id)"; -torque-resolution:2; -torque-data-aggregation:linear;} #tweet_sample{ comp-op: lighter; marker-fill-opacity: 0.9; marker-line-color: #FFF; marker-line-width: 0; marker-line-opacity: 1; marker-type: ellipse; marker-width: 6; marker-fill: #0F3B82;} #tweet_sample [frame-offset=1] { marker-width:8; marker-fill-opacity:0.45; } #tweet_sample [frame-offset=2] { marker-width:10; marker-fill-opacity:0.225; }'
},
named_map: {
name: "torque_named_map",
layers: [{
layer_name: "t"
}]
}
},{https:true})
.addTo(map)
.done(function(layer) {
});
}
window.onload = main;
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment