-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.html
240 lines (219 loc) · 10.4 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
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
<!DOCTYPE html>
<html>
<head>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet">
<style type="text/css">
#map-canvas {
height: 400px;
margin-top: 10px;
}
#map-container {
padding: 10px;
border: solid 1px black;
}
#table-of-contents {
margin-top: 30px;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js" ></script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCNsyojm0VjBde5v9AVunWHm1qBF2lCiKE"></script>
<script type="text/javascript">
var geocoder;
var map;
var contents;
var curInfoWindow;
var propNames = {
"numberofmembers": "Number of Members",
"siteof": "Site of",
"contactname": "Contact Name",
"focusareas": "Focus Areas",
"focusarea": "Focus Area",
"missionofsponsor": "Mission of Sponsor",
"missionofsubsite": "Mission of Subsite",
"volunteerstationtype": "Volunteer Station Type",
"volunteerstationname": "Volunteer Station Name",
"stationssupervisor": "Stations Supervisor",
"sitephone": "Site Phone",
"veteranindicator": "Veteran Indicator",
"volcnt": "Vol Count",
"areasserved": "Areas Served",
"programdescription": "Program Description",
"primaryfocusarea": "Primary Focus Area",
"congressionaldistrict": "Congressional District",
"programdirectorname": "Program Director Name",
"sponsororganization": "Sponsor Organization",
"vistaassignmentdescription": "Vista Assignment Description"
};
var markerUrl = 'https://dcd9f34ab49dd08d26877db18c8db53bb56007a3-www.googledrive.com/host/0B8BleOByyHyIQTlmdDJGUENaNGs/';
function initialize() {
var mapOptions = {
center: { lat: 37.5333, lng: -77.4667},
zoom: 6
};
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
geocoder = new google.maps.Geocoder();
}
function codeAddress() {
var address = document.getElementById("address").value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
map.setZoom(12);
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
function changeMarkers(checkbox) {
console.log(checkbox.name);
console.log(checkbox.checked);
var sheet;
for(var i=0; i<contents.length; i++) {
if(contents[i].title === checkbox.name) {
sheet = contents[i];
}
}
if(!sheet.data) {
getSheetData(sheet, showData, checkbox.checked);
} else {
showData(sheet, checkbox.checked);
}
}
function showData(sheet, visible) {
$.each(sheet.data, function(){
if(visible && !this.marker) {
var position = new google.maps.LatLng(this.lat, this.lng);
var icon = {
url: markerUrl + this.title.replace(/\s+/g, '') + '.png'
};
var marker = new google.maps.Marker({
position: position,
map: map,
title: this.program,
icon: icon
});
this.marker = marker;
var infoWindowContent = '<div class="row">' +
'<div class="col-xs-12"><h4>' + this.program + '</h4></div>' +
'</div>' + this.infoWindowContent;
var infoWindow = new google.maps.InfoWindow({
content: infoWindowContent,
maxWidth: 550
});
google.maps.event.addListener(this.marker, 'click', function() {
if(curInfoWindow) {
curInfoWindow.close();
}
curInfoWindow = infoWindow;
infoWindow.open(map, marker);
});
} else if (visible && this.marker) {
this.marker.setMap(map);
} else {
this.marker.setMap(null);
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
var titles = [];
var sheetsLoaded = 0;
function getSheetData(sheet, callback, visible) {
sheet.data = [];
$.get(sheet.url, function(data){
var rows = data.feed.entry;
var title = data.feed['title']['$t'].trim();
$.each(rows, function(){
var curData = {
title: title,
infoWindowContent: ''
};
for (var property in this) {
if(property == 'gsx$latitude') {
curData['lat'] = this['gsx$latitude']['$t'];
} else if(property == 'gsx$longitude') {
curData['lng'] = this['gsx$longitude']['$t'];
} else if(property == 'gsx$program') {
curData['program'] = this['gsx$program']['$t'];
} else if(property.indexOf('gsx$') === 0) {
var propName = property.substring(4);
if(propName in propNames) {
propName = propNames[propName];
} else {
propName = propName.charAt(0).toUpperCase() + propName.slice(1);
}
var propData = this[property]['$t'].trim();
if(propData !== "") {
curData.infoWindowContent += '<div class="row">' +
'<div class="col-xs-3"><b>' + propName + '</b></div>' +
'<div class="col-xs-9">'+ propData + '</div>' +
'</div><hr>';
}
}
}
sheet.data.push(curData);
});
callback(sheet, visible);
});
}
$(function(){
$('#address').keyup(function(e){
if(e.keyCode == 13) {
codeAddress();
}
});
mapData = [];
contents = [];
var sheetCount = 0;
var urlRoot = 'https://spreadsheets.google.com/feeds/';
var sheetId = '1w8D1D_zCisaayQ5629nY7spJmzntJ5nRZKWD0x2kY44';
var urlEnd = '/public/values?alt=json';
var sheetUrl = urlRoot + 'worksheets/' + sheetId + urlEnd;
$.get(sheetUrl, function(data){
sheetCount = data.feed.entry.length;
for(var i=0; i<sheetCount; i++) {
var title = data.feed.entry[i]['title']['$t'].trim();
titles.push(title);
contents.push({
title: title,
url: urlRoot + 'list/' + sheetId + '/' + (i+1) + urlEnd
});
}
$('#titles').empty();
$.each(titles, function(){
$('#titles').append('<input name="' + this + '" onclick="changeMarkers(this)" type="checkbox"> ' + this + '<br>');
});
});
});
</script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-xs-5">
<div id="map-container">
<div>
Search for a location:
<div class="input-group col-sm-6">
<input id="address" class="form-control" type="text">
<span class="input-group-btn">
<button class="btn btn-default" type="button" onclick="codeAddress()">Search</button>
</span>
</div>
</div>
<div id="map-canvas"></div>
</div>
</div>
<div class="col-xs-4 col-xs-offset-1">
<div id="table-of-contents">
<div id="titles" style="color: #ddd">
<div class="text-center">Loading</div>
<div class="progress">
<div class="progress-bar" role="progressbar" style="width: 0%;"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>