2014-09-24 17:48:29 +08:00
|
|
|
|
|
|
|
<html>
|
|
|
|
<style>
|
|
|
|
#map, html, body {
|
|
|
|
width: 100%; height: 100%; padding: 0; margin: 0;
|
|
|
|
}
|
|
|
|
#title {
|
|
|
|
position: absolute;
|
|
|
|
top: 100px;
|
|
|
|
left: 50px;
|
|
|
|
color: white;
|
|
|
|
font-size: 27px;
|
2014-09-24 18:07:54 +08:00
|
|
|
font-family: Helvetica, sans-serif;
|
2014-09-24 17:48:29 +08:00
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<body>
|
|
|
|
<div id="map"></div>
|
|
|
|
<div id="title">Average temperature collected by Britain's Royal Navy (1913-1925)</div>
|
|
|
|
|
2018-12-03 21:53:13 +08:00
|
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.4/leaflet.css" />
|
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.4/leaflet.js"></script>
|
2018-12-03 23:14:42 +08:00
|
|
|
<script src="../dist/torque.full.uncompressed.js"></script>
|
2014-09-24 17:48:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
// define the torque layer style using cartocss
|
|
|
|
// this creates a kind of density map
|
|
|
|
//color scale from http://colorbrewer2.org/
|
|
|
|
var CARTOCSS = [
|
|
|
|
'Map {',
|
|
|
|
'-torque-time-attribute: "date";',
|
|
|
|
'-torque-aggregation-function: "avg(temp::float)";',
|
|
|
|
'-torque-frame-count: 1;',
|
|
|
|
'-torque-animation-duration: 15;',
|
|
|
|
'-torque-resolution: 16',
|
|
|
|
'}',
|
|
|
|
'#layer {',
|
|
|
|
' marker-width: 8;',
|
|
|
|
' marker-fill-opacity: 1.0;',
|
|
|
|
' marker-fill: #fff5eb; ',
|
|
|
|
' marker-type: rectangle;',
|
|
|
|
' [value > 1] { marker-fill: #fee6ce; }',
|
|
|
|
' [value > 2] { marker-fill: #fdd0a2; }',
|
|
|
|
' [value > 4] { marker-fill: #fdae6b; }',
|
|
|
|
' [value > 10] { marker-fill: #fd8d3c; }',
|
|
|
|
' [value > 15] { marker-fill: #f16913; }',
|
|
|
|
' [value > 20] { marker-fill: #d94801; }',
|
|
|
|
' [value > 25] { marker-fill: #8c2d04; }',
|
|
|
|
'}'
|
|
|
|
].join('\n');
|
|
|
|
|
|
|
|
|
|
|
|
var map = new L.Map('map', {
|
|
|
|
zoomControl: true,
|
|
|
|
center: [40, 0],
|
|
|
|
zoom: 3
|
|
|
|
});
|
|
|
|
|
2018-12-03 23:14:42 +08:00
|
|
|
L.tileLayer('https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png', {
|
2014-09-24 17:48:29 +08:00
|
|
|
attribution: 'CartoDB'
|
2018-12-03 23:14:42 +08:00
|
|
|
}).addTo(map, true);
|
2014-09-24 17:48:29 +08:00
|
|
|
|
|
|
|
var torqueLayer = new L.TorqueLayer({
|
|
|
|
user : 'viz2',
|
|
|
|
table : 'ow',
|
2018-12-03 21:53:13 +08:00
|
|
|
cartocss: CARTOCSS,
|
2018-12-03 23:14:42 +08:00
|
|
|
tiler_protocol: 'https',
|
|
|
|
tiler_port: 443,
|
|
|
|
zIndex: 10
|
2014-09-24 17:48:29 +08:00
|
|
|
});
|
|
|
|
torqueLayer.addTo(map);
|
|
|
|
|
|
|
|
map.on('click', function(e) {
|
|
|
|
var p = e.containerPoint
|
|
|
|
var value = torqueLayer.getValueForPos(p.x, p.y);
|
|
|
|
if (value !== null) {
|
|
|
|
map.openPopup('average temperature: ' + value.value + "C", e.latlng);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// show small rectable and change cursor on hover
|
|
|
|
var hover = null;
|
|
|
|
map.on('mousemove', function(e) {
|
|
|
|
var p = e.containerPoint
|
|
|
|
var value = torqueLayer.getValueForPos(p.x, p.y);
|
|
|
|
|
|
|
|
// remove previous hover box
|
|
|
|
if (hover) {
|
|
|
|
map.removeLayer(hover);
|
|
|
|
hover = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value !== null) {
|
|
|
|
hover = L.rectangle(value.bbox, {
|
|
|
|
color: '#000',
|
|
|
|
weight: 1
|
|
|
|
}).addTo(map);
|
|
|
|
map._container.style.cursor = 'pointer';
|
|
|
|
} else {
|
|
|
|
map._container.style.cursor = 'auto';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
|