-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
232 lines (209 loc) · 6.19 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
<html lang="en">
<head>
<title>Nearest Maptime</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<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='https://api.tiles.mapbox.com/mapbox.js/v2.2.1/mapbox.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox.js/v2.2.1/mapbox.css' rel='stylesheet' />
<script src='https://api.tiles.mapbox.com/mapbox.js/plugins/turf/v2.0.0/turf.min.js'></script>
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet">
<link rel='shortcut icon' href='http://maptime.io/img/favicon.png' type='image/x-icon' />
<style>
body {
padding:0;
margin:0;
font-family: sans-serif;
}
.cf:before,
.cf:after {
content:" ";
display:table;
}
.cf:after {
clear:both;
}
.cf {
*zoom:1;
}
body.showing_results .inner {
vertical-align: top;
}
body.showing_results #map {
opacity: 1;
}
#map {
position: absolute;
width: 100%;
height: 100%;
}
#map.before {
opacity: .3;
}
@media (min-width: 500px) {
.outer {
display: table;
position: absolute;
width: 100%;
height: 100%;
}
.inner {
display: table-cell;
vertical-align: middle;
}
}
#neighbor {
display: block;
padding: 1em;
margin: 1em auto;
max-width: 500px;
}
input {
float:left;
width: 80%;
font-size: 1.8em;
padding: .4em .5em;
text-weight: 100;
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
border: 1px solid #e5e5e5;
}
button {
float: left;
width: 20%;
border: none;
background: #444;
color: white;
height: 59px;
margin-left: -1px;
font-size: 1.3em;
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
cursor: pointer;
}
h1 {
font-weight: 100;
}
p.small {
font-size: .8em;
}
img {
display: block;
margin: .5em auto;
width: 80%;
height: auto;
}
</style>
</head>
<body>
<div id="map" class="before"></div>
<div class="outer">
<div class="inner">
<div id="neighbor">
<img src="logo.png">
<div class="field_group cf">
<input id="location" type="text" placeholder="Where are you?">
<button id="search" type="button"><i class="fa fa-search"></i></button>
</div>
<div id="neighbor_info">
<!--
<h1>The nearest Maptime chapter to <strong>walla walla</strong> is <strong>MaptimeBend</strong>.</h1>
<p>That's <strong>304 miles</strong> away as the crow flies. You should check them out at <a href="#">maptimebend</a> and talk to their organizer, Blair Deaver, if you'd like to get in touch.</p>
<p>If social media is your thing, follow them <a href="#">@maptimebend</a></p>
<p class="small">Not close enough? Why don't you look at <a href="#">starting your own Maptime!</a></p>
-->
</div>
</div>
</div>
</div>
<script>
var searchValue, chapters,
token = 'pk.eyJ1IjoiY3Vnb3MiLCJhIjoidGNnSlBNTSJ9.qPHDxAemDindkSskKNv90g';
// function map() {
// map = L.mapbox.accessToken = token;
// L.mapbox.map('map', 'cugos.jphcb71d');
// }
function search(value) {
$.ajax({
url: 'http://api.tiles.mapbox.com/v4/geocode/mapbox.places/'+value+'.json?access_token=' + token,
dataType: 'json',
async: true,
success: findNearest,
error: function (err) {
console.error(err);
}
});
}
function findNearest(res) {
try {
var p = res.features[0];
console.log(res.features[0]);
var point = {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [p.center[0], p.center[1]]
}
};
var nearest = turf.nearest(point, chapters);
var distance = parseInt(turf.distance(point, nearest, 'miles'));
console.log(nearest);
$('body').addClass('showing_results');
var near = nearest.properties;
var n = $('#neighbor_info');
n.html(function(e){
var html = '<h1>The nearest Maptime chapter to "' + searchValue + '" is <strong>' + near.title + '</strong>.</h1>';
html += '<p><strong>' + near.location + '</strong> is about <strong>' + distance + ' miles</strong> away as the crow flies. ';
if (near.website) {
html += ' You can learn more on <a href="' + near.website + '">their website</a>.';
}
if (near.organizers.length) {
if (near.organizers.length == 1) {
html += ' Keep an eye out for ' + near.organizers[0].name + ', their awesome organizer.';
} else {
var o = [];
html += ' Keep an eye out for either ';
for (var i = 0; i < near.organizers.length; i++) {
console.log(i, near.organizers.length);
if (i == near.organizers.length - 1) html += 'or ';
html += near.organizers[i].name + ', ';
}
html += 'the stallwart organizers.';
}
}
html += '</p>';
if (near.twitter) {
html += '<p>If you\'re into social media you can follow them at <a href="http://twitter.com/'+near.twitter+'">'+near.twitter+'</a> on Twitter.</p>';
}
html += '<p class="small">Not close enough? Why don\'t you look at <a href="http://maptime.io/start/">starting your own Maptime!</a></p>';
return html;
})
} catch (err) {
throw err + 'NO RESULTS FROM THE GEOCODER!'
}
}
function getChapters() {
$.ajax({
url: 'https://raw.githubusercontent.com/maptime/maptime.github.io/master/_data/chapters.json',
dataType: 'json',
async: true,
success: function(response) {
chapters = response;
}
});
}
function addEventListeners() {
$('#search').on('click', function(e){
e.preventDefault();
searchValue = $('#location').val();
search(searchValue);
});
}
$(document).ready(function(){
getChapters();
addEventListeners();
});
</script>
</body>
</html>