-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
247 lines (219 loc) · 7.75 KB
/
index.html
File metadata and controls
247 lines (219 loc) · 7.75 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
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
<html lang="en">
<head>
<title>STI</title>
<meta name="viewport" content="width=device-width">
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script src='locations.js'></script>
<script src='https://api.tiles.mapbox.com/mapbox.js/v2.1.5/mapbox.js'></script>
<script src="turf.js" charset="utf-8"></script>
<link href='https://api.tiles.mapbox.com/mapbox.js/v2.1.5/mapbox.css' rel='stylesheet' />
<link href='http://fonts.googleapis.com/css?family=Lato:300,400' rel='stylesheet' type='text/css'>
<link href='static/css/font-awesome.min.css' rel='stylesheet' />
<style>
body {
padding:0;
margin:0;
font-family: 'Lato', sans-serif;
font-weight:300;
}
form {}
form input {
position:fixed;
top:0;
width:100%;
font-size:1.5em;
padding:10px;
background:rgba(255,255,255,0.8);
-webkit-transition: .3s;
-moz-transition: .3s;
-ms-transition: .3s;
-o-transition: .3s;
transition: .3s;
border:none;
font-family: 'Lato', sans-serif;
font-weight:300;
}
input:-webkit-autofill {
color: #fff !important;
}
form input:focus {
outline:none;
background:rgba(255,255,255,1);
}
#map {
position:absolute;
height:100%;
width:100%;
}
#geolocate {
position:fixed;
bottom:10px;
left:10px;
font-size:1.6em;
background:transparent;
border:none;
}
#geolocate:focus {
outline:none;
}
#geolocate .fa-refresh,
#geolocate.working .fa-crosshairs {
display:none;
}
#geolocate.working .fa-refresh {
display:block;
-webkit-animation-name: spin;
-webkit-animation-duration: 1s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
-moz-animation-name: spin;
-moz-animation-duration: 1s;
-moz-animation-iteration-count: infinite;
-moz-animation-timing-function: linear;
-ms-animation-name: spin;
-ms-animation-duration: 1s;
-ms-animation-iteration-count: infinite;
-ms-animation-timing-function: linear;
-o-transition: rotate(3600deg);
}
@-moz-keyframes spin {
from { -moz-transform: rotate(0deg); }
to { -moz-transform: rotate(360deg); }
}
@-webkit-keyframes spin {
from { -webkit-transform: rotate(0deg); }
to { -webkit-transform: rotate(360deg); }
}
@keyframes spin {
from {transform:rotate(0deg);}
to {transform:rotate(360deg);}
}
</style>
</head>
<body>
<div id="map"></div>
<form id="address_form">
<input id="address_input" type="text" class="" placeholder="Enter an address..." autocomplete="off">
</form>
<button id="geolocate" onclick="geolocate()">
<i class="fa fa-crosshairs"></i>
<i class="fa fa-refresh"></i>
</button>
<script>
L.mapbox.accessToken = 'pk.eyJ1Ijoic3ZtYXR0aGV3cyIsImEiOiJVMUlUR0xrIn0.NweS_AttjswtN5wRuWCSNA';
var map = L.mapbox.map('map', 'svmatthews.l7jici43');
var stiLocations = L.mapbox.featureLayer(locations).addTo(map);
map.fitBounds(stiLocations.getBounds());
map.zoomControl.removeFrom(map);
var input = document.getElementById('address_input');
var geolocateButton = document.getElementById('geolocate');
var locationStore;
$.ajax({
url: 'https://brigades.opendatanetwork.com/resource/rj82-n357.json',
async: true,
dataType: "json",
success: setLocations,
error: function(e) {
console.error(e);
}
});
function setLocations (data) {
console.log('location store initialized');
locationStore = data;
}
// checks when a key is pressed in the input field
// if the key is 13 (enter, return) then it fires
// the geocode() function
$("input").keypress(function(event) {
if (event.which == 13) {
event.preventDefault();
geocode();
}
});
function geocode(e) {
var token = 'pk.eyJ1IjoiY29kZWZvcnJ2YSIsImEiOiJuUG5EQ0FzIn0.0IA_livuMSbj19KvV3qd0w';
var query = input.value;
$.ajax({
url: 'http://api.tiles.mapbox.com/v4/geocode/mapbox.places/' + query + '.json?access_token=' + token + '&callback=jsonloaded',
async: true,
dataType: "json",
success: point,
error: function(e) {
console.error(e);
}
});
}
function geolocate() {
console.log('[ GEOLOCATING USER ]');
if (navigator.geolocation) {
geolocateButton.className = 'working';
navigator.geolocation.getCurrentPosition(function(position){
geolocateButton.className = '';
console.log(position);
nearestFunc([position.coords.longitude, position.coords.latitude]);
});
} else {
console.error("[ ERROR: Geolocation is not supported by this browser. ]");
}
}
function point(res) {
if (res.features == 0) geocode_null();
else {
nearestFunc(res.features[0].geometry.coordinates);
}
}
// nearestFunc accepts a [lat,lng] array to be used
// to search for the nearest STI center
function nearestFunc(coords) {
// create point geojson with turf.point()
var point = turf.point([coords[0], coords[1]], {
"marker-color": "#0074D9",
"title": "Starting Point",
"marker-symbol": "building"
});
// create turf feature collection with locations geojson defined in locations.js
var fc = turf.featurecollection(locations.features);
// create nearest object to update properties
var nearest = turf.nearest(point, turf.featurecollection(locations.features));
// update properties of nearest location
nearest.properties["marker-color"] = "#2ECC40";
nearest.properties["marker-symbol"] = "hospital";
console.log("[ NEAREST ]:", nearest);
// add searched point to map
L.mapbox.featureLayer().setGeoJSON(point).addTo(map);
// update map with newly styled location
stiLocations.setGeoJSON(locations.features);
}
function geocode_null() {
console.log('[ ERROR: Sorry, there we cannot find that address. ]');
}
function polygon_null() {
console.log('[ ERROR: This point does not exist within the polygon areas. ]');
}
// Note that calling `.eachLayer` here depends on setting GeoJSON _directly_
// above. If you're loading GeoJSON asynchronously, like from CSV or from a file,
// you will need to do this within a `featureLayer.on('ready'` event.
stiLocations.eachLayer(function(layer) {
// here you call `bindPopup` with a string of HTML you create - the feature
// properties declared above are available under `layer.feature.properties`
var content = '<h2>' + layer.feature.properties.Name + '<\/h2>' + //Fetches the name of the clinic
'<p><b>Address:</b> ' + layer.feature.properties.address;//Gives the first part of the address
if(layer.feature.properties.address_2 === ""){//checks for a second part (Suite number, etc.)
content += '<br \/> <b>Phone Number:</b> ' + layer.feature.properties.Phone_Number + '<br \/>' + //Adds other data
'<b>Hours:</b> ' + layer.feature.properties.Appointments_Hours + '<br \/>' +
'<b>Services:</b> ' + layer.feature.properties.Services_Offered + '<br \/>' +
'<b>Cost:</b> ' + layer.feature.properties.Payment + '<br \/> </p>';
}
else{//If there is a second part to address, appends here and then the rest
content += ', ' + layer.feature.properties.address_2 + '<br \/>' +
'<b>Phone Number:</b> ' + layer.feature.properties.Phone_Number + '<br \/>' +
'<b>Hours:</b> ' + layer.feature.properties.Appointments_Hours + '<br \/>' +
'<b>Services:</b> ' + layer.feature.properties.Services_Offered + '<br \/>' +
'<b>Cost:</b> ' + layer.feature.properties.Payment + '<br \/> </p>';
}
layer.bindPopup(content);//Puts the content var created above into the Popup
});
</script>
</body>
</html>