-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex2.php
144 lines (123 loc) · 5.46 KB
/
index2.php
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
<!DOCTYPE html>
<html>
<head>
<title>University Heights Association</title>
<script src="//maps.googleapis.com/maps/api/js?v=3"></script>
<script src="//code.jquery.com/jquery-latest.min.js"></script>
<style type="text/css">
html {
height: 100%
}
body {
height: 100%;
margin: 0;
padding: 0
}
table {
border-collapse: collapse;
}
table, th, td {
border: 1px solid black;
}
#mapdiv {
height: 100%
}
</style>
</head>
<body>
<div id="mapdiv"></div>
<script>
var map;
var box;
var infoWindow;
function map_initialize() {
map = new google.maps.Map(document.getElementById("mapdiv"), {
center: new google.maps.LatLng(35.104874, -106.627808),
zoom: 10,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
// var latlngbounds = new google.maps.LatLngBounds();
$.getJSON("php/locations.json", function(json1) {
$.each(json1, function(key, data) {
var latLng = new google.maps.LatLng(data.lat, data.lng);
// var iconImage = "";
//
// switch (data.year) {
// case "2010":
// iconImage = "img/red-dot.png";
// break;
// case "2011":
// iconImage = "img/blue-dot.png";
// break;
// case "2012":
// iconImage = "img/yellow-dot.png";
// break;
// case "2013":
// iconImage = "img/green-dot.png";
// break;
// }
// Create a marker and put it on the map
var marker = new google.maps.Marker({
// icon: iconImage,
position: latLng
// title: data.title + ' - Year: ' + data.year + ' - rowId: ' + data.objectid
});
var contentString = '<div id="content">' +
'<h1>Accident Data</h1>' +
'<div id="bodyContent">' +
'<p>Latitude: ' + data.lat + ', Longitude: ' + data.lng + '</p>' +
'<table><tr><th>Year</th><th># of accidents at this location</th></tr>' +
((data.count2010 > 0) ? '<tr><td>2010</td><td style="text-align: center">' + data.count2010 + '</td></tr>' : '' ) +
((data.count2011 > 0) ? '<tr><td>2011</td><td style="text-align: center">' + data.count2011 + '</td></tr>' : '') +
((data.count2012 > 0) ? '<tr><td>2012</td><td style="text-align: center">' + data.count2012 + '</td></tr>' : '') +
((data.count2013 > 0) ? '<tr><td>2013</td><td style="text-align: center">' + data.count2013 + '</td></tr>' : '') +
'</table>' +
'<p></p>' +
'</div>' +
'</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
marker.addListener('mouseover', function() {
infowindow.open(map, marker);
});
marker.addListener('mouseout', function() {
infowindow.close();
});
// latlngbounds.extend(latLng);
marker.setMap(map);
});
});
// Create a bounding box
// map.fitBounds(latlngbounds);
// box = new google.maps.Rectangle({
// bounds: latlngbounds,
// map: map,
// fillColor: "#000000",
// fillOpacity: 0.2,
// strokeWeight: 0
// });
// box.addListener('mouseover', showAccidentData);
// Define an info window on the map.
// infoWindow = new google.maps.InfoWindow();
}
function showAccidentData() {
var ne = box.getBounds().getNorthEast();
$.getJSON("php/accidents.json", function(json2) {
var contentString = "<strong>Accident Data</strong>";
$.each(json2, function(key, data) {
contentString += "<li>Year: " + data.title + ", # of accidents: " + data.accidents + "</li>";
});
// Set the info window's content
infoWindow.setContent(contentString);
});
// Set the info window's position.
infoWindow.setPosition(ne);
infoWindow.open(map);
}
$(document).ready(function() {
map_initialize();
});
</script>
</body>
</html>