-
Notifications
You must be signed in to change notification settings - Fork 7
/
heatmap.html
67 lines (58 loc) · 1.44 KB
/
heatmap.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html> <head>
<title>Heatmap</title>
</head>
<body>
<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px
}
</style>
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyALrS4bNPhHaZ73dACaSxD-r6oht4CX7B8&libraries=visualization&sensor=false">
</script>
<script>
document.body.onload = function() {
fetch("dances_locs.json", function(response) {
load_dances(JSON.parse(response));
});
};
function fetch(url, callback) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState==4 && xhr.status==200) {
callback(xhr.responseText);
}
};
xhr.open("GET",url,true);
xhr.send();
}
function load_dances(dances) {
var heatMapData = [];
for (var i = 0 ; i < dances.length ; i++) {
var weight = dances[i][3];
var lat = dances[i][4];
var lng = dances[i][5];
var active = dances[i][7];
if (!lat || !lng || !active) continue;
heatMapData.push({
location: new google.maps.LatLng(lat, lng),
weight: weight
});
}
var usa = new google.maps.LatLng(39.81,-98.56);
map = new google.maps.Map(document.getElementById('map-canvas'), {
center: usa,
zoom: 5,
});
var heatmap = new google.maps.visualization.HeatmapLayer({
data: heatMapData
});
heatmap.set('radius', 40);
heatmap.setMap(map);
}
</script>
<div id="map-canvas"></div>
</body> </html>