/
index.html
209 lines (196 loc) · 6.72 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
<html>
<head>
<meta charset=utf-8 />
<title>Where am I? - maybe :)</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
<script src='https://api.mapbox.com/mapbox.js/v2.3.0/mapbox.js'></script>
<link href='https://api.mapbox.com/mapbox.js/v2.3.0/mapbox.css' rel='stylesheet' />
<style type="text/css">
@import url(https://fonts.googleapis.com/css?family=Parisienne);
body {
padding: 0;
margin: 0;
font-family: 'Parisienne', cursive;
font-size: 20px;
}
.leaflet-popup-content {
font-family: 'Parisienne', cursive;
font-size: 18px;
text-align: center;
}
.leaflet-popup-content b {
font-size: 20px;
}
.leaflet-popup-content-wrapper {
background: rgba(255, 255, 255, 0.8);
}
a, a:visited {
text-decoration: none;
color: #894522;
}
#log-wrapper {
width: 400px;
height: 100%;
overflow: scroll;
position: absolute;
right: 0px;
padding: 0;
margin:0;
background: rgba(255, 255, 255, 0.7);
z-index: 1;
}
#log {
text-align: center;
padding: 15px;
}
ul {
padding: 0;
margin: 0;
text-align: center;
font-size: 28px;
font-weight: bold;
list-style: none;
}
li {
margin: 10px 0px;
}
li.past {
text-decoration: line-through;
color: #ccc;
}
li.future {
color: #aaa;
font-size: 22px;
}
li.future .date {
font-size: 14px;
}
.inspiration {
font-size: 12px;
margin-top: 3px;
color: #bbb;
}
#map {
position: absolute;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
margin: 0;
}
</style>
</head>
<body>
<div id="log-wrapper">
<div id="log">
<h1>Where am <a href="http://michaelbumann.com">I</a>?</h1>
<p class="meet">
let's meet: <br>
<a href="mailto:hello@michaelbumann.com">hello@michaelbumann.com</a> or <a href="https://twitter.com/bumi">@bumi</a>
</p>
<ul class="location-list">
<li>loading...</li>
</ul>
<p>
have a look at my <a href="http://michaelbumann.com">blog</a> and my <a href="http://flickr.com/bumi">flickr stream</a>
</p>
</div>
</div>
<div id="map"></div>
<script type="text/javascript">
var future = [];
var past = [];
var currentCity, currentState, currentCountry, currentMessage, nextCity, nextState, nextCountry, nextMessage;
L.mapbox.accessToken = 'pk.eyJ1IjoiYnVtaSIsImEiOiJPUFlmZXBBIn0.4k5NFJ-Jx4g-BtdGI-RDKg';
var map = L.mapbox.map('map', 'bumi.pd2gg851', {zoomControl: false}).setView([0,0], 2);
$.get('https://api.github.com/repos/bumi/travels/commits?sha=locations', function(commits) {
$('.location-list li').remove();
commits = commits.sort(function(c1, c2) {
var d1 = new Date(c1.commit.author.date);
var d2 = new Date(c2.commit.author.date);
if(d1 < d2) { return 1; }
if(d1 > d2) { return -1; }
return 0;
});
for(var i=0; i < commits.length; i++) {
try {
var c = commits[i].commit;
var commitMessage = c.message.split("\n");
var data = JSON.parse(commitMessage[commitMessage.length-1]);
var arrival = new Date(c.author.date);
var area = data.city || data.state || 'somewhere';
var message = area + ', ' + data.country;
if(arrival > new Date()) {
$('.next-location').html('Next: ' + message + ' (' + arrival.toDateString() + ')'); // assumin the last commit in the future is the next stop. which is wrong, needs to get smarter and calculate the nearest in the future
$('.location-list').append('<li class="future">' + message + ' <span class="date">(' + arrival.toDateString() + ')<span></li>');
if(future.length === 0) {
nextCity = data.city;
nextState = data.state;
nextCountry = data.country;
nextMessage = message;
}
loadingNextLocation(data.city, data.state, data.country, message);
future.push(c);
} else {
var cssClass = "past"; //default
if(past.length === 0) {
$('.current-location').html(message); // assuming the first in the past is the current location
currentCity = data.city;
currentState = data.state;
currentCountry = data.country;
currentMessage = message;
cssClass = "current";
loadCurrentLocation(currentCity, currentState, currentCountry, message);
}
$('.location-list').append('<li class="' + cssClass +'">' + message + '</li>');
past.push(c);
}
$('.location').show();
} catch(e) {
}
};
});
function loadCurrentLocation(city, state, country, message) {
var geocodeSearch = '';
if(city) { geocodeSearch += (' ' + city) }
if(geocodeSearch === '' && state) { geocodeSearch += (' ' + state) } // we only use the state if we do not have a city. city and country should be enough. in fact it seems to work better.
if(country) { geocodeSearch += (' ' + country) }
if(country == '') { return }
$.getJSON('https://nominatim.openstreetmap.org/search?format=json&q=' + geocodeSearch, function(data) {
var result = data[0];
if(result) {
var coordinates = [result.lat, result.lon];
var myIcon = L.mapbox.marker.icon({'marker-size': 'medium', 'marker-symbol': 'star','marker-color': '#894522'});
var marker = L.marker(coordinates, {icon: myIcon, title: 'currently ' + city})
marker.bindPopup('Find me in: <br><b>' + message + '</b>');
marker.addTo(map);
setTimeout(function() {
map.panTo(coordinates, {animate: true});
}, 500);
setTimeout(function() {
map.setView(coordinates, 5, {zoom: {animate: true}});
}, 1500);
}
});
}
function loadingNextLocation(city, state, country, message) {
var geocodeSearch = '';
if(city) { geocodeSearch += (' ' + city) }
if(geocodeSearch === '' && state) { geocodeSearch += (' ' + state) } // we only use the state if we do not have a city. city and country should be enough. in fact it seems to work better.
if(country) { geocodeSearch += (' ' + country) }
if(country == '') { return }
$.getJSON('https://nominatim.openstreetmap.org/search?format=json&q=' + geocodeSearch, function(data) {
var result = data[0];
if(result) {
var coordinates = [result.lat, result.lon];
var myIcon = L.mapbox.marker.icon({'marker-size': 'small', 'marker-symbol': 'star','marker-color': '#666'});
var marker = L.marker(coordinates, {icon: myIcon, title: 'Next stop ' + city})
marker.bindPopup('Next stop: <br><b>' + message + '</b>');
marker.addTo(map);
}
});
}
</script>
</body>
</html>