-
Notifications
You must be signed in to change notification settings - Fork 0
/
v02.html
661 lines (504 loc) · 24.5 KB
/
v02.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
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
<!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">
<style>
body {
background-color: #ffffff;
text-align: center;
font-family: 'Noto Sans', sans-serif;
}
.custom .leaflet-popup-tip,
.custom .leaflet-popup-content-wrapper {
background: #e93434;
color: #ffffff;
}
h1 {
color: #74ac00;
font-size: 102px;
margin-bottom: -25px;
margin-top: -25px;
}
html,
body,
#map {
height: 100%;
width: 100%;
padding: 0px;
margin: 0px;
}
#map {
z-index: 1;
}
.box {
/* bring your own prefixes */
z-index: 10;
background-color: rgba(255, 255, 255, 0.57);
padding: 10px;
pointer-events: none;
}
a:hover {
cursor: pointer;
}
.leaflet-popup-content-wrapper {
background-color: rgba(255, 255, 255, 0.57);
text-align: center;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
padding: 5px;
}
.leaflet-popup-content-wrapper .leaflet-popup-content {
background-color: rgba(255, 255, 255, 0);
}
.leaflet-popup-tip-container {
background-color: rgba(255, 255, 255, 0);
}
.leaflet-popup-tip {
background-color: rgba(255, 255, 255, 0);
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
}
img {
height:70px;
}
.button {
background-color: #74ac00;
border: none;
color: white;
padding: 10px 15px;
text-align: center;
text-decoration: none;
display: inline-block;
margin: 4px 2px;
cursor: pointer;
border-radius: 25px;
pointer-events: all;
}
.footer {
bottom: 0%;
left: 50%;
position: fixed;
transform: translate(-50%, 0%);
z-index: 10;
}
.topper {
left: 50%;
position: fixed;
transform: translate(-50%, 0%);
z-index: 10;
background-color: rgba(255, 255, 255, 0.57);
padding: 10px;
text-align: left;
}
.leaflet-marker-icon,
.leaflet-marker-shadow {
-webkit-animation: fadein 3s;
/* Safari, Chrome and Opera > 12.1 */
-moz-animation: fadein 3s;
/* Firefox < 16 */
-ms-animation: fadein 3s;
/* Internet Explorer */
-o-animation: fadein 3s;
/* Opera < 12.1 */
animation: fadein 3s;
}
@keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
/* Firefox < 16 */
@-moz-keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
/* Safari, Chrome and Opera > 12.1 */
@-webkit-keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
/* Internet Explorer */
@-ms-keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
/* Opera < 12.1 */
@-o-keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
/* tool tip */
/* Tooltip container */
.tooltip {
position: relative;
display: inline-block;
}
/* Tooltip text */
.tooltip .tooltiptext {
visibility: hidden;
width: 200px;
background-color: #555;
color: #fff;
text-align: center;
padding: 3px 0px;
border-radius: 6px;
/* Position the tooltip text */
position: absolute;
z-index: 1;
bottom: 125%;
left: 50%;
margin-left: -100px;
/* Fade in tooltip */
opacity: 0;
transition: opacity 0.3s;
}
/* Tooltip arrow */
.tooltip .tooltiptext::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: #555 transparent transparent transparent;
}
/* Show the tooltip text when you mouse over the tooltip container */
.tooltip:hover .tooltiptext {
visibility: visible;
opacity: 1;
}
</style>
</head>
<body>
<div class="topper">
<a class="toggler2" style="pointer-events: all;"><i class="fas fa-times" style="float: right; opacity: 0.2;"></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 id="map"></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;"></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> - Map clears every 5 mins - Made by <a href="https://twitter.com/simon_rolph" target="_blank">Simon</a>
</p>
</div>
<script>
window.twttr = (function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0],
t = window.twttr || {};
if (d.getElementById(id)) return t;
js = d.createElement(s);
js.id = id;
js.src = "https://platform.twitter.com/widgets.js";
fjs.parentNode.insertBefore(js, fjs);
t._e = [];
t.ready = function(f) {
t._e.push(f);
};
return t;
}(document, "script", "twitter-wjs"));
</script>
<script src="countUp.js"></script>
<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>
$(document).ready(function() {
$(".toggler").click(function() {
$(".box").toggle();
});
});
</script>
<script>
$(document).ready(function() {
$(".toggler2").click(function() {
$(".topper").toggle();
});
});
</script>
<script>
var mymap = L.map('map').setView([0, -0.09], 1.5);
L.tileLayer('https://stamen-tiles-{s}.a.ssl.fastly.net/terrain-background/{z}/{x}/{y}{r}.{ext}', {
attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> — Map data © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
subdomains: 'abcd',
minZoom: 2,
maxZoom: 11,
ext: 'png'
}).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, 5);
var start_num = data["total_results"];
if (!numAnim.error) {
numAnim.start();
} else {
console.error(numAnim.error);
}
} else {
console.log('error');
}
}
// Send request
request.send();
//
// updater
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('error');
}
}
// Send request
request.send();
// 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";
// get the guess name from the API
// should really do another API call to get the actual ID because it gets null quite often
if (data2["results"][i]["identifications"].length > 0) {
var name = data2["results"][i]["identifications"][0]["taxon"]["name"];
}
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 " + 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);
//mymap.addLayer(marker);
marker.openPopup();
// sometimes it add the same marker twice so could use the uuid to make sure it doesn't
//data2["results"][i]["uuid"];
}
}
} else {
console.log('error');
}
}
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);
//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 " + data3["results"][i]["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();
});
// add the marker
marker.addTo(layerInds);
//mymap.addLayer(marker);
//console.log(layerInds.getLayers());
}
}
}
} else {
console.log('error');
}
}
request3.send();
}, 6000);
window.setInterval(function() {
layerInds.clearLayers();
layerObvs.clearLayers();
uuids = [];
}, 300000);
</script>
</body>
</html>