Skip to content

Instantly share code, notes, and snippets.

@ernesmb
Last active February 6, 2016 12:08
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 ernesmb/3f8662160e37d3741082 to your computer and use it in GitHub Desktop.
Save ernesmb/3f8662160e37d3741082 to your computer and use it in GitHub Desktop.
Custom Torque Slider with createLayer()
<!DOCTYPE html>
<html>
<head>
<title>Custom Torque Slider with createLayer() | CartoDB.js</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>
<script src="https://cartodb-libs.global.ssl.fastly.net/cartodb.js/v3/3.15/cartodb.js"></script>
<script>
function main() {
var map = new L.Map('map', {
zoomControl: true,
center: [36, -2],
zoom: 3,
});
L.tileLayer('http://{s}.tile.stamen.com/toner/{z}/{x}/{y}.png', {
attribution:'Stamen and CartoDB attribution'
}).addTo(map);
cartodb.createLayer(map, {
type: 'torque',
order: 1,
options: {
query: "SELECT * FROM tweet_sample_ebe15",
user_name:'ernestomb',
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_ebe15{ 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_ebe15[frame-offset=1] { marker-width:8; marker-fill-opacity:0.45; }#tweet_sample_ebe15[frame-offset=2] { marker-width:10; marker-fill-opacity:0.225; }"
}
},{https:true})
.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();
})
})
.error(function(err) {
console.log(err);
}).addTo(map);
}
window.onload = main;
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment