-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
526 lines (389 loc) · 26.1 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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<link href="https://fonts.googleapis.com/css?family=Noto+Sans" rel="stylesheet">
<title>iNaturalist LIVE</title>
<link rel="shortcut icon" type="image/png" href="https://www.inaturalist.org/favicon.ico" />
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" integrity="sha512-puBpdR0798OZvTTbP4A8Ix/l+A4dHDD0DGqYW6RQ+9jxkRFclaxxQb/SJAWZfWAkuyeQUytO7+7N4QKrDh+drA==" crossorigin="" />
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.4.1/css/all.css" integrity="sha384-5sAR7xN1Nv6T6+dT2mhtzEpVJvfS3NScPQTrOxhwjIuvcA67KV2R5Jz6kr4abQsz" crossorigin="anonymous">
<link rel="stylesheet" href="style.css">
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-71775228-3"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-71775228-3');
</script>
</head>
<body>
<div class="topper">
<a class="toggler2" style="pointer-events: all;"><i class="fas fa-times" style="float: right; opacity: 0.2;"> close</i></a>
<p><b>Welcome to iNaturalist LIVE!</b></p><p> This webpage provides a live visualisation of whats happening on iNaturalist right now!
iNaturalist is a platform for sharing observations of wildlife and identifying these observations as different species. Watch as markers appear on the map either representing someone uploading their observations or providing an identification. Click on each marker to be taken to the iNaturalist website to learn more about that observation or identification.</p>
</div>
<div class="row">
<div class="column left"><div id="map"></div> </div>
<div class="column right">
<h3 class="ticktitle"> <!--<a><i class="fas fa-angle-double-right" onclick="hideticker()"></i></a> -->Latest activity</h3>
<!--
<p class="ticktitle">Filter: <i class="fas fa-camera"></i><input type="checkbox" name="vehicle1" value="Bike" checked> <i style="color:#74ac00" class="fas fa-running"></i><input type="checkbox" name="vehicle1" value="Bike" checked> <i style="color:#74ac00" class="fas fa-check"></i><input type="checkbox" name="vehicle1" value="Bike" checked> <i style="color:tomato" class="fas fa-bolt"></i><input type="checkbox" name="vehicle1" value="Bike" checked></p>
-->
<div id="ticker"></div>
</div>
</div>
<div class="footer">
<div class="box" id="thingy">
<a class="toggler" style="pointer-events: all;"><i class="fas fa-times" style="float: right; opacity: 0.2;"> close</i></a>
<p>There are currently</p>
<h1 id="counter"></h1>
<p>verifiable observations on iNaturalist</p>
<p><a href="https://www.inaturalist.org/observations" target="_blank" class="button">Explore observations</a></p>
</div>
<p>
Observations: <span class="tooltip"><span class="fa-stack"><i class="fas fa-circle fa-stack-2x fa-inverse" style="text-shadow: 0 0 3px rgba(0, 0, 0, 0.1);"></i><i class="fas fa-camera fa-stack-1x"></i></span>
<span class="tooltiptext">A photographic observation uploaded to iNaturalist</span>
</span>
Identifications: <span class="tooltip"><span class="fa-stack"><i class="fas fa-circle fa-stack-2x fa-inverse" style="text-shadow: 0 0 3px rgba(0, 0, 0, 0.1);"></i><i class="fas fa-trophy fa-stack" style="color:#74ac00"></i></span>
<span class="tooltiptext"><b>Improving:</b> First suggestion of this taxon that the community subsequently agreed with. This identification helped refine the community taxon.</span>
</span>
<span class="tooltip"><span class="fa-stack"><i class="fas fa-circle fa-stack-2x fa-inverse" style="text-shadow: 0 0 3px rgba(0, 0, 0, 0.1);"></i><i class="fas fa-running fa-stack" style="color:#74ac00"></i></span>
<span class="tooltiptext"><b>Leading:</b> Taxon descends from the community taxon. This identification could be leading toward the right answer.</span>
</span>
<span class="tooltip"><span class="fa-stack"><i class="fas fa-circle fa-stack-2x fa-inverse" style="text-shadow: 0 0 3px rgba(0, 0, 0, 0.1);"></i><i class="fas fa-check fa-stack" style="color:#74ac00"></i></span>
<span class="tooltiptext"><b>Supporting:</b> Taxon is the same as the community taxon. This identification supports the community ID.
</span>
</span>
<span class="tooltip"><span class="fa-stack"><i class="fas fa-circle fa-stack-2x fa-inverse" style="text-shadow: 0 0 3px rgba(0, 0, 0, 0.1);"></i><i class="fas fa-bolt fa-stack" style="color:tomato"></i></span>
<span class="tooltiptext"><b>Maverick:</b> Taxon is not a descendant or ancestor of the community taxon. The community does not agree with this identification.
</span>
</span>
</p>
<p><a class="toggler">Show/hide the counter</a> - Made by <u><a href="https://bsky.app/profile/simon-rolph.com" target="_blank">Simon</a></u>
</p>
</div>
<!-- countUp.js is the javascript thiong that makes the nice smooth counter in the middle of the page -->
<script src="countUp.js"></script>
<!-- leaflet.js is the map library -->
<script src="https://unpkg.com/[email protected]/dist/leaflet.js" integrity="sha512-nMMmRyTVoLYqjP9hrbed9S+FzjZHW5gY1TWCHA5ckwXZBadntCNs8kEqAWdrb9O7rxbCaA4lKTIWjDXZxflOcA==" crossorigin=""></script>
<script src="jquery-3.3.1.min.js"></script>
<script>
// for toggling the big counter number
$(document).ready(function() {
$(".toggler").click(function() {
$(".box").toggle();
});
});
</script>
<script>
// for getting rid of the welcome message
$(document).ready(function() {
$(".toggler2").click(function() {
$(".topper").toggle();
});
});
observationtick
</script>
<script>
function hideticker(){
document.getElementsByClassName("left")[0].style.width = '100%';
document.getElementsByClassName("right")[0].style.width = '0%';
}
var mymap = L.map('map').setView([0, -0.09], 1.5);
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(mymap);
var layerInds = L.layerGroup().addTo(mymap);
var layerObvs = L.layerGroup().addTo(mymap);
var obs = new L.DivIcon({
className: 'my-div-icon',
html: '<span class="fa-stack"><i class="fas fa-circle fa-stack-2x fa-inverse" style="text-shadow: 0 0 3px rgba(0, 0, 0, 0.2);"></i><i class="fas fa-camera fa-stack-1x"></i></span>'
});
var ind = new L.DivIcon({
className: 'my-div-icon',
html: '<span class="fa-stack"><i class="fas fa-circle fa-stack-2x fa-inverse" style="text-shadow: 0 0 3px rgba(0, 0, 0, 0.2);"></i><i class="fas fa-check fa-stack" style="color:#74ac00"></i></span>'
});
var ind2 = new L.DivIcon({
className: 'my-div-icon',
html: '<span class="fa-stack"><i class="fas fa-circle fa-stack-2x fa-inverse" style="text-shadow: 0 0 3px rgba(0, 0, 0, 0.2);"></i><i class="fas fa-trophy fa-stack" style="color:#74ac00"></i></span>'
});
var ind3 = new L.DivIcon({
className: 'my-div-icon',
html: '<span class="fa-stack"><i class="fas fa-circle fa-stack-2x fa-inverse" style="text-shadow: 0 0 3px rgba(0, 0, 0, 0.2);"></i><i class="fas fa-running fa-stack" style="color:#74ac00"></i></span>'
});
var ind4 = new L.DivIcon({
className: 'my-div-icon',
html: '<span class="fa-stack"><i class="fas fa-circle fa-stack-2x fa-inverse" style="text-shadow: 0 0 3px rgba(0, 0, 0, 0.2);"></i><i class="fas fa-bolt fa-stack" style="color:tomato"></i></span>'
});
uuids = [];
// This function adds a zero so that numbers are are always to 2 digets
function addZero(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}
function getTheDate(secondsdiff) {
var d = Math.floor((new Date()).getTime() / 1000) + secondsdiff
//console.log(d);
var da = new Date(0); // The 0 there is the key, which sets the date to the epoch
da.setUTCSeconds(d);
// make the date in the right format for the API call
// example correct format: 2018-10-14T12%3A44%3A24%2B00%3A00
var outDate = String(addZero(da.getUTCFullYear())) + "-" + String(addZero(da.getUTCMonth() + 1)) + "-" + String(addZero(da.getUTCDate())) + "T" + String(addZero(da.getUTCHours())) + "%3A" + String(addZero(da.getUTCMinutes())) + "%3A" + String(addZero(da.getUTCSeconds())) + "%2B00%3A00";
return (outDate)
}
// options for the counter
var options = {
useEasing: true,
useGrouping: true,
separator: ',',
decimal: '.',
};
// INITIAL COUNTER NUMBER
// Create a request variable and assign a new XMLHttpRequest object to it.
var request = new XMLHttpRequest();
var theDate = getTheDate(0)
request.open('GET', 'https://api.inaturalist.org/v1/observations?verifiable=true&created_d2=' + theDate + '&page=1&per_page=0&order=desc&order_by=created_at', true);
request.onload = function() {
// Begin accessing JSON data here
var data = JSON.parse(this.response);
if (request.status >= 200 && request.status < 400) {
numAnim = new CountUp("counter", data["total_results"] - 2, data["total_results"], 0, 15);
var start_num = data["total_results"];
if (!numAnim.error) {
numAnim.start();
} else {
console.error(numAnim.error);
}
} else {
console.log('error');
}
}
// Send request
request.send();
//
// updating the big number of observations count, this updates every 15 seconds
window.setInterval(function(){
// Create a request variable and assign a new XMLHttpRequest object to it.
var request = new XMLHttpRequest();
// Open a new connection, using the GET request on the URL endpoint
var theDate = getTheDate(0)
request.open('GET', 'https://api.inaturalist.org/v1/observations?verifiable=true&created_d2=' + theDate + '&page=1&per_page=0&order=desc&order_by=created_at', true);
request.onload = function() {
// Begin accessing JSON data here
var data = JSON.parse(this.response);
if (request.status >= 200 && request.status < 400) {
//console.log(data["total_results"]);
numAnim.update(data["total_results"]);
} else {
console.log(data);
}
}
// Send request
request.send();
}, 15000);
// getting observations and identifications
window.setInterval(function() {
// Same again for observations SINCE date (minus 15 seconds) (for adding markers)
var theDate2 = getTheDate(-10);
var request2 = new XMLHttpRequest();
request2.open('GET', 'https://api.inaturalist.org/v1/observations?verifiable=true&created_d1=' + theDate2 + '&page=1&per_page=40&order=desc&order_by=created_at', true);
request2.onload = function() {
// Begin accessing JSON data here
var data2 = JSON.parse(this.response);
if (request2.status >= 200 && request2.status < 400) {
//console.log(data2["total_results"]);
// lopp through results of recently added observations
for (i = 0; i < data2["total_results"]; i++) {
var coords = data2["results"][i]["location"].split(",");
var uuid = data2["results"][i]["uuid"];
if (uuids.includes(uuid) == false) {
uuids.push(uuid);
//console.log(data2["results"][i])
//if(data2["results"][i]["uuid"])
var marker = L.marker([coords[0], coords[1]], {icon: obs})
marker.url = 'https://www.inaturalist.org/observations/' + data2["results"][i]["id"]
// ad a click event to open the observation page in a new tab
marker.on('click', function() {
window.open(this.url, '_blank');
});
var name = "Unknown";
var common_name = "";
// get the guess name from the API
if (data2["results"][i]["identifications"].length > 0) {
var name = data2["results"][i]["identifications"][0]["taxon"]["name"];
common_name = data2["results"][i]["identifications"][0]["taxon"]["preferred_common_name"];
if (common_name === undefined){
common_name = "";
} else {
common_name = "("+common_name+")";
}
}
var iconurl = "<img class='profilepic' src='https://www.inaturalist.org/attachment_defaults/users/icons/defaults/thumb.png'>";
if (data2["results"][i]["user"]["icon"] != null){
var iconurl = "<img class='profilepic' src='" + data2["results"][i]["user"]["icon"]+"'> " ;
};
var name = name.charAt(0).toUpperCase() + name.substr(1);
//add all the info to the popup
marker.bindPopup("<a target='_blank' href='"+marker.url+"'><img src='" + data2["results"][i]["photos"][0]["url"] + "'></a> <br><i>" + name + "</i><br> Observed by " + iconurl + data2["results"][i]["user"]["login"] + "<br>on " + data2["results"][i]["observed_on"], {
autoClose: true,
autoPan: false
});
//make it so the marker appears on mouse rollover and dissapears when roll off
marker.on('mouseover', function(e) {
this.openPopup();
});
marker.on('mouseout', function(e) {
this.closePopup();
});
// add the marker
marker.addTo(layerObvs);
//var marker_id = layerObvs.getLayerId(marker);
marker.marker_id = layerObvs.getLayerId(marker);
//console.log(layerObvs.getLayerId(marker));
layerObvs.getLayer(marker.marker_id).openPopup();
// ticker stuff
var newtick = document.createElement("div");
newtick.classList.add("tick");
newtick.classList.add("observationtick");
newtick.innerHTML = "<a style='display:block;' href = '" +marker.url+"' target = '_blank'> " + iconurl + data2["results"][i]["user"]["login"] + " observed <i class='fas fa-camera'></i> <i>" + name +"</i> "+common_name + "</a>" ;
newtick.href = marker.url;
newtick.setAttribute('id', "marker"+marker.marker_id);
newtick.setAttribute('target', '_blank');
newtick.setAttribute('onmouseenter', "layerObvs.getLayer("+marker.marker_id+").openPopup();");
ticker = document.getElementById("ticker");
ticker.insertBefore(newtick, ticker.firstChild);
// remove the marker + ticker after a set time preiod
window.setTimeout(function(markerid) {
//console.log(markerid);
document.getElementById("marker"+markerid).remove();
mymap.removeLayer(layerObvs.getLayer(markerid));
},300000,marker.marker_id);
}
}
} else {
console.log(data2);
}
}
request2.send();
// identifications
var request3 = new XMLHttpRequest();
request3.open('GET', 'https://api.inaturalist.org/v1/identifications?current=true&d1=' + theDate2 + '&order=desc&order_by=created_at', true);
request3.onload = function() {
// Begin accessing JSON data here
var data3 = JSON.parse(this.response);
if (request2.status >= 200 && request2.status < 400) {
//console.log(data3["total_results"]);
//layerInds.clearLayers();
// lopp through results of recently added observations
for (i = 0; i < data3["total_results"]; i++) {
var shouldmap = (data3["results"][i]["own_observation"] == false || data3["results"][i]["observation"]["identifications_count"] > 1 );
//console.log(shouldmap)
if (data3["results"][i]["observation"]["photos"][0] != null && data3["results"][i]["observation"]["location"] != null && shouldmap == true) {
//console.log(data3);
var coords = data3["results"][i]["observation"]["location"].split(",");
var uuid = data3["results"][i]["uuid"];
if (uuids.includes(uuid) == false) {
uuids.push(uuid);
//console.log(data3["results"][i]["category"])
if (data3["results"][i]["category"] == "improving") {
var marker = L.marker([coords[0], coords[1]], {
icon: ind2
});
} else if (data3["results"][i]["category"] == "leading") {
var marker = L.marker([coords[0], coords[1]], {
icon: ind3
});
} else if (data3["results"][i]["category"] == "maverick") {
var marker = L.marker([coords[0], coords[1]], {
icon: ind4
});
} else {
var marker = L.marker([coords[0], coords[1]], {
icon: ind
});
}
marker.url = 'https://www.inaturalist.org/observations/' + data3["results"][i]["observation"]["id"]
// ad a click event to open the observation page in a new tab
marker.on('click', function() {
window.open(this.url, '_blank');
});
//console.log(data3["results"][i]["observation"]["photos"][0]["url"]);
// get the guess name from the API
// should really do another API call to get the actual ID because it gets null quite often
var guess = data3["results"][i]["taxon"]["name"];
if (guess == null) {
var guess = "Unknown";
}
var guess = guess.charAt(0).toUpperCase() + guess.substr(1);
var iconurl = "<img class='profilepic' src='https://www.inaturalist.org/attachment_defaults/users/icons/defaults/thumb.png'>";
if (data3["results"][i]["user"]["icon"] != null){
var iconurl = "<img class='profilepic' src='" + data3["results"][i]["user"]["icon"]+"'> " ;
};
var iconurlobvs = "<img class='profilepic' src='https://www.inaturalist.org/attachment_defaults/users/icons/defaults/thumb.png'>";
if (data3["results"][i]["observation"]["user"]["icon"] != null){
var iconurlobvs = "<img class='profilepic' src='" + data3["results"][i]["observation"]["user"]["icon"]+"'> " ;
};
//add all the info to the popup
marker.bindPopup("<a href='"+'https://www.inaturalist.org/observations/' + data3["results"][i]["observation"]["id"]+"'><img src='" + data3["results"][i]["observation"]["photos"][0]["url"] + "'></a> <br><i>" + guess + "</i><br> Identified by "+ iconurl + data3["results"][i]["user"]["login"] +"<br>Observed by " + iconurlobvs + " "+ data3["results"][i]["observation"]["user"]["login"], {
autoClose: true,
autoPan: false
});
//make it so the marker appears on mouse rollover and dissapears when roll off
marker.on('mouseover', function(e) {
this.openPopup();
});
marker.on('mouseout', function(e) {
this.closePopup();
});
// get the guess name from the API
//console.log(data3["results"][i]);
common_name = data3["results"][i]["observation"]["taxon"]["preferred_common_name"];
if (common_name === undefined){
common_name = "";
} else {
common_name = "("+common_name+")";
}
// add the marker
marker.addTo(layerInds);
//var marker_id = layerObvs.getLayerId(marker);
marker.marker_id = layerInds.getLayerId(marker);
// ticker stuff
var newtick = document.createElement("div");
newtick.classList.add("tick");
newtick.innerHTML = "<a style='display:block;' href = '" +marker.url+"' target = '_blank'> " + iconurl + data3["results"][i]["user"]["login"] + " identified <i>" + guess +"</i> "+common_name + " observed by " + iconurlobvs+ data3["results"][i]["observation"]["user"]["login"] +" </a>";
newtick.href = marker.url;
newtick.setAttribute('target', '_blank');
newtick.setAttribute('id', "marker"+marker.marker_id);
newtick.setAttribute('onmouseenter', "layerInds.getLayer("+marker.marker_id+").openPopup();");
ticker = document.getElementById("ticker");
ticker.insertBefore(newtick, ticker.firstChild);
// remove the marker + ticker after a set time preiod
window.setTimeout(function(markerid) {
//console.log(markerid);
document.getElementById("marker"+markerid).remove();
mymap.removeLayer(layerInds.getLayer(markerid));
},300000,marker.marker_id);
}
}
}
} else {
console.log(data3);
}
}
request3.send();
// remove too many tickers
}, 6000);
// window.setInterval(function() {
// layerInds.clearLayers();
// layerObvs.clearLayers();
// var myNode = document.getElementById("ticker");
// myNode.innerHTML = '';
// uuids = [];
// }, 300000);
</script>
</body>
</html>