-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
305 lines (296 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
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
<!doctype html><meta charset=utf-8><title> Spacetime Locator </title>
<style>
html { max-width: 12cm; margin: auto; }
.centered { text-align: center; font-weight: bold; font-family: monospace; }
.logo { position: relative; top: 5px; }
.clickable { cursor: pointer; }
#spashNode { font-size: 3em; }
#googleMapNode { height: 400px; width: 100%; margin-top: 15px; display: none; }
footer { font-size: 0.9em; }
</style>
<h1> Spash: Spacetime Locator </h1>
<p class=centered>
<a href='https://github.com/espadrine/spash'>
<svg class=logo width="20" height="20" viewBox="12 12 40 40">
<path d="M32,13.4c-10.5,0-19,8.5-19,19c0,8.4,5.5,15.5,13,18c1,0.2,1.3-0.4,1.3-0.9c0-0.5,0-1.7,0-3.2 c-5.3,1.1-6.4-2.6-6.4-2.6C20,41.6,18.8,41,18.8,41c-1.7-1.2,0.1-1.1,0.1-1.1c1.9,0.1,2.9,2,2.9,2c1.7,2.9,4.5,2.1,5.5,1.6 c0.2-1.2,0.7-2.1,1.2-2.6c-4.2-0.5-8.7-2.1-8.7-9.4c0-2.1,0.7-3.7,2-5.1c-0.2-0.5-0.8-2.4,0.2-5c0,0,1.6-0.5,5.2,2 c1.5-0.4,3.1-0.7,4.8-0.7c1.6,0,3.3,0.2,4.7,0.7c3.6-2.4,5.2-2,5.2-2c1,2.6,0.4,4.6,0.2,5c1.2,1.3,2,3,2,5.1c0,7.3-4.5,8.9-8.7,9.4 c0.7,0.6,1.3,1.7,1.3,3.5c0,2.6,0,4.6,0,5.2c0,0.5,0.4,1.1,1.3,0.9c7.5-2.6,13-9.7,13-18.1C51,21.9,42.5,13.4,32,13.4z"/>
</svg></a>
<code class=selectable>npm install spash</code>
</p>
<p>
Every day, humanity goes more vertical. Petty constraints like gravity are
defied by <em>planes, kilometric skyscrapers, ambitious space programs</em>.
<a href="http://iss.astroviewer.net">The ISS</a> peacefully maintains
our orbital presence on the planet, and Elon Musk is already planning
<a href="https://en.wikipedia.org/wiki/Interplanetary_Transport_System">
a Martian settlement</a>.
</p>
<p>
Your place in the universe gets more important by the second. Here is its
identifier, encoding your <em>planet</em>, <em>latitude</em>,
<em>longitude</em>, <em>altitude</em>, and optionally <em>instant in
time</em>:
</p>
<section class=centered>
<output id=spashNode>E.ek0uvhuQQ1q</output><br>
<input type=button id=addDigitNode value='+'>
<input type=button id=rmDigitNode value='-'>
<input type=button id=editNode value='Edit'>
<label><input type=checkbox id=showTimeNode> Show time</label>
<label><input type=checkbox id=showMapNode> Show map</label>
</section>
<div id=googleMapNode></div>
<p id=geolocNode></p>
<p id=precisionNode></p>
<p id=noGeolocNode>
Your device does not allow access to geolocation data. Using a default location.
</p>
<p id=warningsNode></p>
<footer>
<p>
Full <a href=https://github.com/espadrine/spash/blob/master/Readme.md>
specification</a>.
Inspired by <a href=https://en.wikipedia.org/wiki/Geohash>Geohash</a>.
Licensed <a href=https://creativecommons.org/publicdomain/zero/1.0/>CC0</a>.
Built by <a href=https://twitter.com/espadrine>Thaddée Tyl</a>.
</p>
</footer>
<script src=./spash.js></script>
<script>
var geoloc = {
coords: {
latitude: 51.5221656,
longitude: -0.1086239,
altitude: 22.725,
accuracy: 2,
altitudeAccuracy: 1e-9,
},
timestamp: Date.now(),
};
var geoSpash;
var digits = 11;
var setGeoloc = function(geo) {
geoloc = geo;
geoSpash = spash.encode(geo, digits, 6);
var hash = geoSpash.iau + '.' + geoSpash.geolocHash;
if (showTimeHash) { hash += '.' + geoSpash.timeHash; }
spashNode.value = hash;
location.hash = hash;
showGeoloc();
accuracyWarnings(geoSpash, geo);
};
var gotGeoloc = function(geo) {
noGeolocNode.style.display = 'none';
setGeoloc(geo);
};
var noGeolocWarning = function() {
noGeolocNode.style.display = 'block';
setGeoloc(geoloc);
};
if (!location.hash) {
navigator.geolocation.getCurrentPosition(gotGeoloc, noGeolocWarning, {
enableHighAccuracy: true,
timeout: 25000,
maximumAge: 0
});
} else {
// The address bar already holds a hash.
addEventListener('DOMContentLoaded', function() {
try {
updateSpash(location.hash);
} catch (e) { return; }
});
}
var mapLink = function(geoloc, digits) {
return "https://www.google.fr/maps/@" + geoloc.coords.latitude +
"," + geoloc.coords.longitude + "," + getZoomFromDigits(digits) + "z";
};
var showGeoloc = function() {
var values = [
'<a href="' + mapLink(geoloc, digits) + '">Map</a>',
'<span class="clickable" onclick="changeLatitude(event)">' +
'Latitude</span>: ' + displayNumber(geoloc.coords.latitude) + '°' +
'</span>',
'<span class="clickable" onclick="changeLongitude(event)">' +
'Longitude</span>: ' + displayNumber(geoloc.coords.longitude) + '°' +
'</span>',
'<span class="clickable" onclick="changeAltitude(event)">' +
'Altitude</span>: ' + displayNumber(geoloc.coords.altitude) + ' metres' +
'</span>',
];
if (showTimeHash) {
values.push('<span class="clickable" onclick="changeTime(event)">' +
'Time</span>: ' + new Date(geoloc.timestamp).toISOString());
}
geolocNode.innerHTML = values.join('<br>');
};
var accuracyWarnings = function(geoSpash, geo) {
var accuracies = [
'± ' + displayNumber(geoSpash.earthLatError) + ' metres (latitude)',
'± ' + displayNumber(geoSpash.earthLongError) + ' metres (longitude)',
'± ' + displayNumber(geoSpash.altError) + ' metres (altitude)',
];
if (showTimeHash) {
accuracies.push('± ' + geoSpash.timeError + ' seconds (time)');
}
precisionNode.innerHTML = accuracies.join('<br>');
var geoAccuracy = geo.coords.accuracy || Infinity; // meters
var altAccuracy = (geo.coords.altitudeAccuracy) || Infinity;
var warn = [];
if (geoAccuracy > geoSpash.earthLongError ||
geoAccuracy > geoSpash.earthLatError) {
warn.push('Geographic coordinates are not accurate enough for this level of precision.');
}
if (geo.coords.altitudeAccuracy === null) {
warn.push('Altitude measurement unavailable; using sea level.');
} else if (altAccuracy > geoSpash.altError) {
warn.push('Altitude measurement is not accurate enough for this level of precision.');
}
warningsNode.innerHTML = warn.join('<br>');
};
var addDigit = function(event) {
digits++;
setGeoloc(geoloc);
setMapCenter(geoloc);
};
var rmDigit = function(event) {
if (digits <= 0) { return; }
digits--;
setGeoloc(geoloc);
setMapCenter(geoloc);
};
var changeLatitude = function(event) {
var newLat = prompt('Enter a new latitude.');
if (newLat === null) {return;}
newLat = +newLat;
if (newLat !== newLat) {return;}
geoloc.coords.latitude = newLat;
setGeoloc(geoloc);
setMapCenter(geoloc);
};
var changeLongitude = function(event) {
var newLong = prompt('Enter a new longitude.');
if (newLong === null) {return;}
newLong = +newLong;
if (newLong !== newLong) {return;}
geoloc.coords.longitude = newLong;
setGeoloc(geoloc);
setMapCenter(geoloc);
};
var changeAltitude = function(event) {
var newAlt = prompt('Enter a new altitude, in metres.');
if (newAlt === null) {return;}
newAlt = +newAlt;
if (newAlt !== newAlt) {return;}
geoloc.coords.altitude = newAlt;
setGeoloc(geoloc);
setMapCenter(geoloc);
};
var changeTime = function(event) {
var newTime = prompt('Enter a new time, in ISO 8601.');
if (newTime === null) {return;}
newTime = +new Date(newTime);
if (+newTime !== newTime) {return;}
geoloc.timestamp = newTime;
setGeoloc(geoloc);
setMapCenter(geoloc);
};
var updateSpash = function(newSpash) {
var newGeo = spash.decode(newSpash);
var parts = newSpash.split('.');
digits = parts[1].length;
setShowTimeHash(!!parts[2]);
setGeoloc(newGeo);
setMapCenter(geoloc);
};
var edit = function(event) {
var newSpash = prompt('Enter a spash.');
try {
updateSpash(newSpash);
} catch(e) {
alert('Invalid Spash');
}
};
var showTimeHash = false;
var setShowTimeHash = function(show) {
showTimeHash = show;
showTimeNode.checked = show;
setGeoloc(geoloc);
};
var showTimeChanged = function(event) {
setShowTimeHash(event.target.checked);
};
var showMap = false;
var showMapChanged = function(event) {
showMap = event.target.checked;
if (showMap) {
loadMapLibrary();
googleMapNode.style.display = 'block';
} else {
googleMapNode.style.display = 'none';
}
};
var hashChanged = function(event) {
try {
updateSpash(location.hash);
} catch (e) { return; }
};
addDigitNode.addEventListener('click', addDigit);
rmDigitNode.addEventListener('click', rmDigit);
editNode.addEventListener('click', edit);
showTimeNode.addEventListener('change', showTimeChanged);
showMapNode.addEventListener('change', showMapChanged);
addEventListener('hashchange', hashChanged);
var displayNumber = function(num) {
num = num || 0;
if (num >= 1000) { return num.toFixed(0);
} else if (num >= 1) { return num.toFixed(2);
} else { return num.toPrecision(2); }
};
// Google Map
var googleMap, googleMapMarker;
var getZoomFromDigits = function(digits) {
return Math.floor(digits * 19 / 11);
};
var setMapCenter = function(geoloc) {
if (!googleMap) { return; }
var latLng = {
lat: geoloc.coords.latitude,
lng: geoloc.coords.longitude,
};
googleMap.setCenter(latLng);
var zoom = getZoomFromDigits(digits);
googleMap.setZoom(zoom);
googleMapMarker.setPosition(latLng);
};
var geolocAtFetchedElevation = geoloc;
var setSpashFromMapCenter = function() {
if (!googleMap) { return; }
var center = googleMap.getCenter();
var latLng = {lat: center.lat(), lng: center.lng()};
geoloc.coords.latitude = latLng.lat;
geoloc.coords.longitude = latLng.lng;
setGeoloc(geoloc);
setGeoloc(spash.decode(geoSpash.hash));
latLng = {
lat: geoloc.coords.latitude,
lng: geoloc.coords.longitude,
};
googleMapMarker.setPosition(latLng);
};
var initMap = function() {
googleMap = new google.maps.Map(googleMapNode);
googleMapMarker = new google.maps.Marker({map: googleMap});
googleMap.addListener('center_changed', setSpashFromMapCenter);
setMapCenter(geoloc);
}
var mapLibraryLoaded = false;
var loadMapLibrary = function() {
if (mapLibraryLoaded) { return; }
mapLibraryLoaded = true;
var script = document.createElement('script');
script.async = true;
script.defer = true;
script.src = "https://maps.googleapis.com/maps/api/js?key=AIzaSyB7tgHIP7-P8j_nV1W1ahUdXcXwB1fK18c&callback=initMap";
document.body.appendChild(script);
};
</script>