-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.html
More file actions
210 lines (179 loc) · 5.92 KB
/
map.html
File metadata and controls
210 lines (179 loc) · 5.92 KB
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html {
height: 100%
}
body {
height: 100%;
margin: 0;
padding: 0;
font-family:"Open Sans", "Roboto", "Tahoma", sans-serif;
}
#map-canvas {
height: 100%;
}
#info {
position: absolute;
bottom: 0;
right: 0;
background: #fff;
padding: 5px;
z-index:99;
text-align: right;
}
#info a {
}
h2 {
font-size: 14px;
margin: 0;
padding: 0;
}
</style>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?libraries=geometry&sensor=false">
</script>
<script type="text/javascript" src="highschools.js">
</script>
<script type="text/javascript">
var map;
var totalSchools = 0;
var totalCount = 0;
var Boston = new google.maps.LatLng(42.358431, -71.059773);
var USA = new google.maps.LatLng(39.232253, -96.020508);
function initialize() {
var mapOptions = {
center: USA,
zoom: 5,
scrollwheel: true,
minZoom: 5,
maxZoom: 12
};
map = new google.maps.Map(document.getElementById("map-canvas"),
mapOptions);
var FivehCircleOptions = {
strokeColor: "#FFFF00",
strokeOpacity: 0.8,
strokeWeight: 1,
fillColor: "#FFFF00",
fillOpacity: 0.1,
map: map,
clickable: false,
center: Boston,
radius: 500000
};
var FivehCircle = new google.maps.Circle(FivehCircleOptions);
var maCircleOptions = {
strokeColor: "#00FF00",
strokeOpacity: 0.8,
strokeWeight: 1,
fillColor: "#00FF00",
fillOpacity: 0.15,
map: map,
clickable: false,
center: Boston,
radius: 100000
};
var maCircle = new google.maps.Circle(maCircleOptions);
// google.maps.event.addListener(maCircle, 'click', function() {
// map.setZoom(12);
// map.panTo(Boston);
// });
var bostonCircleOptions = {
strokeColor: "#00FFFF",
strokeOpacity: 0.8,
strokeWeight: 1,
fillColor: "#00FFFF",
fillOpacity: 0.2,
map: map,
clickable: false,
center: Boston,
radius: 10000
};
var bostonCircle = new google.maps.Circle(bostonCircleOptions);
var i = 0;
for (var name in highschools) {
i++;
totalSchools++;
totalCount += highschools[name].count;
var locationColor = 0;
var distanceFromBoston = google.maps.geometry.spherical.computeDistanceBetween(Boston, highschools[name].center);
if (distanceFromBoston < 100000) {
locationColor = '#2400e0';
} else if (highschools[name].count > 1) {
locationColor = '#8d1168';
} else {
locationColor = '#FF0000';
}
var highschoolOptions = {
strokeColor: locationColor,
strokeOpacity: 1,
strokeWeight: 3,
fillColor: locationColor,
fillOpacity: 0.5,
map: map,
clickable: true,
center: highschools[name].center,
radius: Math.log(highschools[name].count + 1) * (1 / (map.getZoom() - 4)) * 30000
};
var hsCircle = new google.maps.Circle(highschoolOptions);
addInfoWindow(hsCircle, name, highschools[name].count, distanceFromBoston);
addCircleZoom(hsCircle, highschools[name].count);
};
var infowindow = new google.maps.InfoWindow({
content: '<h2>Total Schools</h2>' + totalSchools + '<h2>Total Students</h2>' + totalCount,
position: new google.maps.LatLng(28.917923, -122.849609)
});
infowindow.open(map);
}
google.maps.event.addDomListener(window, 'load', initialize);
function addCircleZoom(circle, count) {
google.maps.event.addListener(map, 'zoom_changed', function() {
var newzoom = map.getZoom();
if (newzoom == 8) {
circle.setRadius(3000);
} else if (newzoom == 9) {
circle.setRadius(1000);
} else if (newzoom >= 10) {
circle.setRadius(500);
} else {
circle.setRadius(Math.log(count + 1) * (1 / (newzoom - 4)) * 30000);
}
});
}
function addInfoWindow(hsCircle, name, count, dist) {
var studentPlural = " students ";
if (count == 1) {
studentPlural = " student ";
}
var hsInfo = new google.maps.InfoWindow({
content: '<h2>' + name + '</h2>' + count + studentPlural + " | dist: " + (Math.round(dist / 1000, 0)) + "km",
disableAutoPan: true
});
google.maps.event.addListener(hsCircle, 'mouseover', function() {
var infocenter = hsCircle.getCenter();
if (map.getZoom() <= 6) {
var p = infocenter.lat() + 0.1;
} else {
var p = infocenter.lat() + 0.02;
}
hsInfo.setPosition(new google.maps.LatLng(p, infocenter.lng()));
hsInfo.open(map);
});
google.maps.event.addListener(hsCircle, 'click', function() {
map.panTo(hsCircle.getCenter());
map.setZoom(7);
});
google.maps.event.addListener(hsCircle, 'mouseout', function() {
setTimeout(function() {
hsInfo.close();
}, 300);
});
}
</script>
</head>
<body>
<div id="map-canvas" />
</body>
</html>