-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
182 lines (163 loc) · 4.51 KB
/
index.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Heatmaps</title>
<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px
}
#panel {
position: absolute;
top: 5px;
left: 50%;
margin-left: -180px;
z-index: 5;
background-color: #fff;
padding: 5px;
border: 1px solid #999;
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=visualization"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>
// Adding 500 Data Points
var map, pointarray, heatmap;
var taxiData = [];
var points = [];
var markers = [];
function getData() {
search = location.search;
search = location.search.substring(1, 100);
if (search == "")
{
search = "stop";
}
//url2 = 'http://api.hackfargo.co/calls/type/' + search + '?start=1-1-2010&end=12-1-2014';
url2 = "/data.js"
$.getJSON(url2, function(data) {
for (i=0; i<data.length; i++)
{
taxiData.push(new google.maps.LatLng(data[i].Lat, data[i].Long));
points.push(data[i]);
if (i == 0){
address = points[0].Meta.Address;
console.log(address);
console.log(geoCoder(address));
}
}
initialize();
});
}
getData();
//46.91895748955729, Long: -96.79799879663642
function initialize() {
var mapOptions = {
zoom: 12,
radius: 60,
center: new google.maps.LatLng(46.85895748955729, -96.79799879663642),
mapTypeId: google.maps.MapTypeId.MAP
};
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
var pointArray = new google.maps.MVCArray(taxiData);
heatmap = new google.maps.visualization.HeatmapLayer({
data: pointArray
});
heatmap.setMap(map);
heatmap.set('radius', 50);
// add points
for (i=0; i<points.length; i++)
{
var m = new google.maps.Marker({
map: map,
title: points[i].Meta.Address + ": " + points[i].Description + " | " + points[i].Meta.GeoLookupType,
position: new google.maps.LatLng(points[i].Lat,points[i].Long),
});
markers.push(m);
}
setAllMap(null); // hide by default
}
function toggleHeatmap() {
heatmap.setMap(heatmap.getMap() ? null : map);
}
function changeGradient() {
var gradient = [
'rgba(0, 255, 255, 0)',
'rgba(0, 255, 255, 1)',
'rgba(0, 191, 255, 1)',
'rgba(0, 127, 255, 1)',
'rgba(0, 63, 255, 1)',
'rgba(0, 0, 255, 1)',
'rgba(0, 0, 223, 1)',
'rgba(0, 0, 191, 1)',
'rgba(0, 0, 159, 1)',
'rgba(0, 0, 127, 1)',
'rgba(63, 0, 91, 1)',
'rgba(127, 0, 63, 1)',
'rgba(191, 0, 31, 1)',
'rgba(255, 0, 0, 1)'
];
// var gradient = [
// 'rgba(0, 255, 255, 0)',
// 'rgba(0, 255, 255, 1)',
// 'rgba(0, 191, 255, 1)',
// 'rgba(0, 127, 255, 1)',
// 'rgba(0, 63, 255, 1)',
// 'rgba(0, 0, 255, 1)',
// 'rgba(0, 0, 223, 1)',
// 'rgba(0, 0, 191, 1)',
// 'rgba(0, 0, 159, 1)',
// 'rgba(0, 0, 127, 1)',
// 'rgba(63, 0, 91, 1)',
// 'rgba(127, 0, 63, 1)',
// 'rgba(191, 0, 31, 1)',
// 'rgba(255, 0, 0, 1)'
// ]
heatmap.set('gradient', heatmap.get('gradient') ? null : gradient);
}
function changeRadius() {
heatmap.set('radius', heatmap.get('radius') ? null : 50);
}
function changeOpacity() {
heatmap.set('opacity', heatmap.get('opacity') ? null : 0.6);
}
// Sets the map on all markers in the array.
function setAllMap(map) {
for (var i = 0; i < markers.length; i++) {
markers[i].setMap(map);
}
}
var tmarkers = false;
function changeMarkers() {
if (tmarkers) {
setAllMap(null);
tmarkers=false;
} else {
setAllMap(map);
tmarkers=true;
}
}
function geoCoder(address){
geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': address }, function(results, status) {
if (status == google.maps.GeocoderStatus.OK)
return results[0].geometry.location;
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="panel">
<button onclick="changeMarkers()">Toggle Markers</button>
<button onclick="toggleHeatmap()">Toggle Heatmap</button>
<button onclick="changeGradient()">Change gradient</button>
<button onclick="changeRadius()">Change radius</button>
<button onclick="changeOpacity()">Change opacity</button>
</div>
<div id="map-canvas"></div>
</body>
</html>