forked from lippytak/ebt-near-me
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
352 lines (306 loc) · 11.6 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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
<!DOCTYPE html>
<html>
<head>
<title>EBT Near Me</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<link rel="shortcut icon" href="favicon.ico" />
<link rel="apple-touch-icon" href="icon.png">
<link rel="apple-touch-icon" sizes="72x72" href="icon.png">
<link rel="apple-touch-icon" sizes="114x114" href="icon.png">
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places,geometry"></script>
<script src="public/js/geolocationmarker-compiled.js"></script>
<!-- j Q U E R Y -->
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-20825280-22', 'auto');
ga('send', 'pageview');
</script>
<!-- C U S T O M S T Y L E S -->
<link rel="stylesheet" href="public/css/app.css">
<!-- G E O M I C O N S -->
<script src="http://d2v52k3cl9vedd.cloudfront.net/geomicons/0.2.0/geomicons.min.js"></script>
<script>
// Map variables
var map;
var no_geolocation_zoom = 10;
var default_zoom = 18;
var ebt_fusion_table = '1gTMiiUxNgLDISIymtea1gJ9oph_F4Lt7BE-FLfAe';
var ebt_data_layer;
var visible_atm_data;
var timeoutID; // So we don't query for visible data on every idle
var marker;
// EBT data layer
ebt_data_layer = new google.maps.FusionTablesLayer({
query: {
select: 'geo_address',
from: ebt_fusion_table,
where: "state = 'CA'"},
styles: [
{where: "type = 'store'", markerOptions: {iconName: 'rec_convenience'}},
{where: "type IN ('ATM', 'POS') AND surcharge = '0'", markerOptions: {iconName: 'dollar'}},
{where: "type IN ('ATM', 'POS') AND surcharge NOT EQUAL TO '0'", markerOptions: {iconName: 'small_yellow'}}
]
});
var directions_pre_link;
if (/iPhone/i.test(navigator.userAgent)) {
directions_pre_link = "<a href='http://maps.google.com/?saddr=Current%20Location&daddr="
} else if (/Android/i.test(navigator.userAgent)) {
directions_pre_link = "<a href='geo:"
} else {
directions_pre_link = "<a href='http://maps.google.com?q="
}
google.maps.event.addListener(ebt_data_layer, 'click', function(e) {
var row_hash = {};
$.each( e.row, function( key, value ) {
row_hash[key] = value.value
});
phrases = getPhrasesFromRow(row_hash);
// Create info window
if (type == 'store') {
e.infoWindowHtml = phrases['name_phrase'] + '<br><br>';
e.infoWindowHtml += phrases['directions_link'] + '<br><br>';
e.infoWindowHtml += phrases['feedback_link_html'] + '<br>';
} else if (type == 'ATM') {
e.infoWindowHtml = phrases['name_phrase'] + '<br><br>';
e.infoWindowHtml += phrases['cost_phrase'] + '<br><br>';
e.infoWindowHtml += phrases['directions_link'] + '<br><br>';
e.infoWindowHtml += phrases['feedback_link_html'] + '<br>';
} else if (type == 'POS') {
e.infoWindowHtml = phrases['name_phrase'] + '<br><br>';
e.infoWindowHtml += phrases['cost_phrase'] + '<br><br>';
e.infoWindowHtml += phrases['directions_link'] + '<br><br>';
e.infoWindowHtml += phrases['feedback_link_html'] + '<br>';
}
});
function getPhrasesFromRow(row_hash) {
var phrases = {};
type = row_hash['type']
directions_link = directions_pre_link + encodeURIComponent(row_hash['text_address']) + "'>Get directions</a>"
phrases["directions_link"] = directions_link;
var name_phrase;
var printable_name_phrase;
location_name = row_hash['location_name']
atm_name = row_hash['atm_name']
text_address = row_hash['text_address']
if (type == 'store') {
name_phrase = row_hash['store_name'];
printable_name_phrase = name_phrase;
} else if (location_name && type == 'ATM') {
name_phrase = 'This is an <b>ATM</b> at ' + location_name;
printable_name_phrase = '<b>ATM</b> at ' + location_name;
} else if (type == 'ATM') {
name_phrase = 'This is a ' + atm_name + ' <b>ATM</b>';
printable_name_phrase = 'This is a ' + atm_name + ' <b>ATM</b>';
} else if (type == 'POS') {
name_phrase = 'This is a cash back location at ' + location_name;
printable_name_phrase = 'Cash back at ' + location_name;
}
phrases["name_phrase"] = name_phrase;
phrases["printable_name_phrase"] = printable_name_phrase;
var cost_phrase;
surcharge = row_hash['surcharge']
cash_limit = row_hash['cash_limit']
if (surcharge == '0') {
cost_phrase = "It's <b>free</b> to use and you can get up to <b>$" + cash_limit + "</b>";
} else if (isNaN(surcharge)) {
cost_phrase = 'You can take out <b>$' + cash_limit + '</b> but you have to pay <b>2% fee</b>.';
} else {
cost_phrase = 'It costs <b>$' + surcharge + '</b> to use and you can get up to <b>$' + cash_limit + '</b>';
}
phrases["cost_phrase"] = cost_phrase;
// See CfA Wufoo API docs for details
wufoo_url = 'https://codeforamerica.wufoo.com/forms/ebtnearme-feedback/def/field3=' + type + '&field2=' + text_address;
feedback_link_html = '<a href="' + wufoo_url + '">Report a problem with this location</a>'
phrases["feedback_link_html"] = feedback_link_html;
return phrases;
}
function foundLocation(position) {
var pos = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
map.setZoom(default_zoom);
map.setCenter(pos);
addLayersAndIdleListener();
// Geomarker
var GeoMarker = new GeolocationMarker();
GeoMarker.setCircleOptions({
visible: false});
google.maps.event.addListenerOnce(GeoMarker, 'position_changed', function() {
map.setCenter(this.getPosition());
});
GeoMarker.setMap(map);
}
function handleNoGeolocation() {
infowindow = new google.maps.InfoWindow({
map: map,
position: map.getCenter(),
content: "Hmmm, I couldn't detect your location.<br>Try searching for an address instead.",
});
infowindow.setMap(map);
addLayersAndIdleListener();
}
function handleIdle() {
window.clearTimeout(timeoutID);
timeoutID = window.setTimeout(queryAndAppendVisibleATMData, 2000);
}
function addLayersAndIdleListener() {
// Add layers and start idle listener after we settle on initial location
ebt_data_layer.setMap(map);
google.maps.event.addListener(map, 'idle', handleIdle);
}
function toTitleCase(str) {
return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
}
function queryAndAppendVisibleATMData() {
var sw = map.getBounds().getSouthWest()
var ne = map.getBounds().getNorthEast()
var r = (google.maps.geometry.spherical.computeDistanceBetween(sw, ne))/2
var center = map.getCenter()
var apiKey = 'AIzaSyDzaRUwEz7l0m3sEbROdDNCNRmsJ-zvUUc'
var query = 'SELECT * '
+ 'FROM ' + ebt_fusion_table + ' '
+ 'WHERE ST_INTERSECTS(geo_address, CIRCLE(LATLNG' + center + ', ' + r + ')) '
+ 'LIMIT 12';
var encodedQuery = encodeURIComponent(query);
// Construct the URL
var url = ['https://www.googleapis.com/fusiontables/v1/query'];
url.push('?sql=' + encodedQuery);
url.push('&key=' + apiKey);
url.push('&callback=?');
// Send the JSONP request using jQuery
$.ajax({
url: url.join(''),
dataType: 'jsonp',
success: appendVisibleAtmData
});
}
function appendVisibleAtmData(data) {
visible_atm_data = data;
// Append data to printable list
var list = $( "#printable-list-div ul" ).empty();
var rows = visible_atm_data['rows']
var cols = visible_atm_data['columns']
if (rows) {
$.each(rows, function( index, value ) {
var row_hash = {};
$.each( value, function( index, value ) {
row_hash[cols[index]] = value
});
phrases = getPhrasesFromRow(row_hash)
if (row_hash['type'] == 'store') {
list.append( "<li><b>" + phrases['printable_name_phrase'] + "</b><br>"
+ toTitleCase(row_hash['text_address'])
+ "</li>" );
} else {
list.append( "<li><b>" + phrases['printable_name_phrase'] + "</b><br>"
+ phrases['cost_phrase'] + "<br>"
+ toTitleCase(row_hash['text_address'])
+ "</li>" );
}
});
} else {
list.append( "<li>If you find some ATMs on the map I'll print out the details here.</li>");
}
}
function initialize() {
// Create map
var san_francisco = new google.maps.LatLng(37.7833, -122.4167);
var mapOptions = {
zoom: no_geolocation_zoom,
disableDefaultUI: true,
center: san_francisco,
styles: [
{
featureType: "poi",
elementType: "all",
stylers: [
{ visibility: "off" }
]
}
]};
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
// Try HTML5 geolocation
navigator.geolocation.getCurrentPosition(foundLocation, handleNoGeolocation);
// Search
var input = (document.getElementById('pac-input'));
map.controls[google.maps.ControlPosition.TOP_LEFT ].push(input);
var searchBox = new google.maps.places.SearchBox((input));
// Listen for the event fired when the user selects an item from the
// pick list and get the first place that matches.
google.maps.event.addListener(searchBox, 'places_changed', function() {
place = searchBox.getPlaces()[0];
// Get the icon, place name, and location.
var image = {
url: place.icon,
size: new google.maps.Size(71, 71),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(17, 34),
scaledSize: new google.maps.Size(25, 25)
};
// Remove current marker if it exists and add the new one
if (marker) {marker.setMap(null)};
marker = new google.maps.Marker({
map: map,
icon: image,
title: place.name,
position: place.geometry.location
});
// Center and zoom map to place
map.setCenter(place.geometry.location)
map.setZoom(default_zoom);
});
// Bias the SearchBox results towards places that are within the bounds of the
// current map's viewport.
google.maps.event.addListener(map, 'bounds_changed', function() {
var bounds = map.getBounds();
searchBox.setBounds(bounds);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<header>
<div class="header-content">
<img id="logo" class="logo-img" src="assets/images/retail-icon.png" alt="">
<h1 id="title-thick" class="title">EBT</h1>
<h1 id="title-regular"class="title">Near</h1>
<h1 id="title-thin" class="title">Me</h1>
<button id="toggle-target">
<span id="close-icon" class="js-geomicon toggle-icon" data-icon="close"></span>
<span id="search-icon" class="js-geomicon toggle-icon" data-icon="search"></span>
</button>
</div>
<input id="pac-input" class="sb-search-input" placeholder="Search by address" type="search" name="search">
</header>
</div>
<div id="map-canvas"></div>
<div id="printable-list-div"><ul></ul></div>
</body>
</html>
<!-- I N J E C T G E O M I C O N S -->
<script>
var icons = document.querySelectorAll('.js-geomicon');
Geomicons.inject(icons);
</script>
<!-- S H O W A N D H I D E S E A R C H -->
<script>
// With the element initially shown, we can hide it slowly:
$( "#toggle-target" ).click(toggleSearchBox);
function toggleSearchBox() {
if ($("#pac-input").is(':visible')) {
$( "#pac-input" ).hide();
$( "#close-icon").hide();
$( "#search-icon").show();
} else {
$("#pac-input").show();
$("#search-icon").hide();
$("#close-icon").show();
}
}
</script>