torque/examples/ow-scrub.html

158 lines
5.1 KiB
HTML
Raw Permalink Normal View History

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>CartoDB + Time</title>
<link rel="shortcut icon" href="http://cartodb.com/favicon/favicon_32x32.ico" />
<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" />
2013-08-30 18:15:21 +08:00
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<style>
2013-08-30 18:15:21 +08:00
#torque-slider {
position:absolute;
bottom:18px;
right:25px;
width:300px;
}
2013-08-30 18:15:21 +08:00
#torque-pause {
2013-04-03 08:50:49 +08:00
position:absolute;
bottom:12px;
right:345px;
width:28px;
height: 26px;
padding: 1px 2px 2px 2px;
z-index: 1000;
border-radius: 3px;
cursor: pointer;
2013-08-30 18:15:21 +08:00
background-color: white;
background-image: url(../img/play.png);
background-repeat:no-repeat;
background-position:center;
2013-04-03 08:50:49 +08:00
}
2013-08-30 18:15:21 +08:00
#torque-pause.playing {
background-color: white; background-image: url(../img/pause.png); background-repeat:no-repeat; background-position:center;
}
#torque-time {
position: absolute;
top: 100px;
left: 50%;
color: white;
font-size: 31px;
font-family: Georgia, serif;
2013-04-03 08:50:49 +08:00
}
2013-12-03 01:27:19 +08:00
#map_canvas {
height: 100%;
}
</style>
2013-08-30 18:15:21 +08:00
</head>
<body>
<div id="map_canvas"></div>
<div id="torque-slider"></div>
<a id="torque-pause" class="playing"></a>
<div id="torque-time"></div>
<a class="cartodb_logo" href="http://www.cartodb.com" target="_blank">CartoDB</a>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
2013-08-30 18:15:21 +08:00
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script src="vendor/leaflet.js"></script>
<script src="vendor/carto.js"></script>
2013-08-30 18:15:21 +08:00
<script src="../dist/torque.uncompressed.js"></script>
<script type="text/javascript">
2013-08-30 18:15:21 +08:00
/**
* inits slider and a small play/pause button
*/
function init_slider(torqueLayer) {
var torqueTime = $('#torque-time');
$("#torque-slider").slider({
min: 0,
max: torqueLayer.options.steps,
value: 0,
step: 1,
slide: function(event, ui){
var step = ui.value;
torqueLayer.setStep(step);
}
});
2013-08-30 18:15:21 +08:00
// each time time changes, move the slider
torqueLayer.on('change:time', function(changes) {
$("#torque-slider" ).slider({ value: changes.step });
var month_year = changes.time.toString().substr(4).split(' ');
torqueTime.text(month_year[0] + " - " + month_year[2]);
console.log(torqueLayer.getTime());
});
2013-08-30 18:15:21 +08:00
// play-pause toggle
$("#torque-pause").click(function(){
torqueLayer.toggle();
$(this).toggleClass('playing');
});
};
2013-08-30 18:15:21 +08:00
function initialize() {
2013-08-30 18:15:21 +08:00
// initialise the google map
var map = new google.maps.Map(document.getElementById('map_canvas'), {
center: new google.maps.LatLng(30.95940879245423, -0.609375),
zoom: 2,
mapTypeId: google.maps.MapTypeId.SATELLITE,
mapTypeControl: false,
minZoom: 1
});
2013-08-30 18:15:21 +08:00
// dark map style
var gmaps_style = [{ stylers:[ { invert_lightness: true }, { weight:1 }, { saturation:-100 }, { lightness:-40 } ]
}, {
elementType:"labels",
stylers:[ { visibility:"simplified" } ]
}
2013-08-30 18:15:21 +08:00
];
map.setMapTypeId(google.maps.MapTypeId.ROADMAP);
map.setOptions({ styles: gmaps_style });
2013-08-30 18:15:21 +08:00
// init torque layer
var torqueLayer = new torque.GMapsTorqueLayer({
user : 'viz2',
table : 'ow',
column : 'date',
countby : 'count(cartodb_id)',
steps: 750,
blendmode : 'lighter',
animationDuration: 60,
map: map
});
2013-04-03 08:50:49 +08:00
2013-08-30 18:15:21 +08:00
var DEFAULT_CARTOCSS = [
'#layer {',
" marker-width: 3; ",
' marker-fill: #FEE391; ',
' [value > 2] { marker-fill: #FEC44F; }',
' [value > 3] { marker-fill: #FE9929; }',
' [value > 4] { marker-fill: #EC7014; }',
' [value > 5] { marker-fill: #CC4C02; }',
' [value > 6] { marker-fill: #993404; }',
' [value > 7] { marker-fill: #662506; }',
' [frame-offset = 1] { marker-width: 8;marker-fill-opacity: 0.05;}',
' [frame-offset = 2] { marker-width: 20;marker-fill-opacity: 0.02;}',
//' [frame-offset = 1] { marker-width: 25;marker-fill-opacity: 0.01;}',
'}'
].join('\n');
torqueLayer.setMap(map);
torqueLayer.setCartoCSS(DEFAULT_CARTOCSS);
2013-08-30 18:15:21 +08:00
init_slider(torqueLayer);
torqueLayer.play();
2013-04-03 08:50:49 +08:00
}
2013-08-30 18:15:21 +08:00
window.onload = initialize;
</script>
2013-08-30 18:15:21 +08:00
</body>
</html>