-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.html
More file actions
252 lines (235 loc) · 13.3 KB
/
test.html
File metadata and controls
252 lines (235 loc) · 13.3 KB
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
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/URI.js/1.19.2/URI.min.js"></script>
<style>
.test {
display:inline-block;
margin:10px;
vertical-align: top;
}
.progress {
width: 250px;
height: 8px;
background: #eee;
border-radius: 3px;
overflow: hidden;
margin-top: 4px;
}
.progress > .fill {
height: 100%;
width: 0%;
background: #4caf50;
transition: width .25s linear;
}
.progress.err > .fill { background: #c62828 }
.progress-label {
font-family: monospace;
font-size: 11px;
color: #444;
min-height: 1em;
}
</style>
<script>
var tests = [
{
title: 'Coral reefs and bleaching (implicit disableUI)',
src: 'https://thumbnails-v2.createlab.org/thumbnail?root=https%3A%2F%2Fheadless.earthtime.org%2F%23v%3D37.96643%2C27.0601%2C0.48%2ClatLng%26t%3D0.75%26ps%3D0%26l%3Dbdrk%2Ccb%26bt%3D0.75%26et%3D0.75%26startDwell%3D0%26endDwell%3D0%26fps%3D10&width=250&height=150&format=png&fps=10&tileFormat=mp4&startDwell=0&endDwell=0&fromScreenshot&baseMapsNoLabels'
},
{
title: 'Coral reefs and bleaching (minimalUI)',
src: 'https://thumbnails-v2.createlab.org/thumbnail?root=https%3A%2F%2Fheadless.earthtime.org%2F%23v%3D267429%2C611221%2C904411%2C969523%2Cpts%26t%3D0%26ps%3D50%26l%3Dblsat%2Ccb%26bt%3D19950101%26et%3D20051231%26startDwell%3D0%26endDwell%3D0%26fps%3D30&width=250&height=150&format=mp4&fps=30&tileFormat=mp4&startDwell=0&endDwell=0&fromScreenshot&minimalUI'
},
{
title: 'Coral reefs and bleaching (minimalUI)',
src: 'https://thumbnails-v2.createlab.org/thumbnail?root=https%3A%2F%2Fheadless.earthtime.org%2F%23v%3D267429%2C611221%2C904411%2C969523%2Cpts%26t%3D0%26ps%3D50%26l%3Dbdrk%2Ccb%26bt%3D20000101%26et%3D20051231%26startDwell%3D0%26endDwell%3D0%26fps%3D30&width=250&height=150&format=mp4&fps=30&tileFormat=mp4&startDwell=0&endDwell=0&fromScreenshot&minimalUI'
},
{
title: 'Coral reefs and bleaching 151px high (minimalUI)',
src: 'https://thumbnails-v2.createlab.org/thumbnail?root=https%3A%2F%2Fheadless.earthtime.org%2F%23v%3D267429%2C611221%2C904411%2C969523%2Cpts%26t%3D0%26ps%3D50%26l%3Dblsat%2Ccb%26bt%3D19950101%26et%3D20051231%26startDwell%3D0%26endDwell%3D0%26fps%3D30&width=250&height=151&format=mp4&fps=30&tileFormat=mp4&startDwell=0&endDwell=0&fromScreenshot&minimalUI'
},
{
title: 'Africa Landsat for Mobile Story (timestampOnlyUI)',
src: 'https://thumbnails-v2.createlab.org/thumbnail?root=https://headless.earthtime.org/%23v%3D935046%2C711459%2C1404483%2C975517%2Cpts%26t%3D0%26ps%3D50%26l%3Dblsat%26bt%3D20100101%26et%3D20161231%26startDwell%3D0%26endDwell%3D1%26fps%3D30&width=640&height=360&format=mp4&fps=30&tileFormat=mp4&startDwell=0&endDwell=1&fromScreenshot×tampOnlyUI=true'
},
{
title: 'Single frame fires with date and legend (minimalUI)',
src: 'https://thumbnails-earthtime.cmucreatelab.org/thumbnail?root=https%3A%2F%2Fheadless.earthtime.org%2F%23v%3D66511%2C260997%2C2059082%2C1381818%2Cpts%26t%3D18.1%26ps%3D0%26l%3Dblsat%2Cviirs%26bt%3D18.1%26et%3D18.1%26startDwell%3D0%26endDwell%3D0%26fps%3D30&width=1280&height=720&format=png&fps=30&tileFormat=mp4&startDwell=0&endDwell=0&fromScreenshot&minimalUI'
},
{
title: 'Fires at night with date bt/et',
src: 'https://thumbnails-v2.createlab.org/thumbnail?root=https%3A%2F%2Fheadless.earthtime.org%23v%3D568546%2C931906%2C939308%2C1140459%2Cpts%26t%3D0%26ps%3D50%26l%3Dbdrk%2Cviirs%26bt%3D20140917%26et%3D20141017%26startDwell%3D0%26endDwell%3D0%26fps%3D30&width=1280&height=720&format=mp4&fps=30&tileFormat=mp4&startDwell=0&endDwell=0&fromScreenshot&minimalUI'
},
{
title: 'TSIP single frame (timestampOnlyUI)',
src: 'https://thumbnails-v2.createlab.org/thumbnail?root=https://headless.earthtime.org/%23v%3D4.56342%2C0%2C1.01%2ClatLng%26ps%3D50%26l%3Dbdrk%2Cpure_earth_tsip_by_pollutants_top_7%26bt%3D20160101%26et%3D20161231%26startDwell%3D0%26endDwell%3D0&width=1280&height=720&format=mp4&fps=30&tileFormat=mp4&startDwell=0&endDwell=0&fromScreenshot×tampOnlyUI=true'
},
{
title: 'Coral reefs and bleaching (minimalUI and forceLegend)',
src: 'https://thumbnails-v2.createlab.org/thumbnail?root=https%3A%2F%2Fheadless.earthtime.org%2F%23v%3D37.96643%2C27.0601%2C0.48%2ClatLng%26t%3D0.75%26ps%3D0%26l%3Dbdrk%2Ccb%26bt%3D0.75%26et%3D0.75%26startDwell%3D0%26endDwell%3D0%26fps%3D10&width=820&height=600&format=png&fps=10&tileFormat=mp4&startDwell=0&endDwell=0&fromScreenshot&baseMapsNoLabels&minimalUI=true&forceLegend=true'
},
{
title: 'Coral reefs and bleaching (minimalUI and forceLegend and centerLegend)',
src: 'https://thumbnails-v2.createlab.org/thumbnail?root=https%3A%2F%2Fheadless.earthtime.org%2F%23v%3D37.96643%2C27.0601%2C0.48%2ClatLng%26t%3D0.75%26ps%3D0%26l%3Dbdrk%2Ccb%26bt%3D0.75%26et%3D0.75%26startDwell%3D0%26endDwell%3D0%26fps%3D10&width=820&height=600&format=png&fps=10&tileFormat=mp4&startDwell=0&endDwell=0&fromScreenshot&baseMapsNoLabels&minimalUI=true&forceLegend=true¢erLegend=true'
},
{
title: 'Edgar Thomson Breathe Cam',
src: 'https://thumbnails-v2.createlab.org/thumbnail?root=https://tiles.cmucreatelab.org/ecam/timemachines/westmifflin1/2020-05-28.timemachine/&width=256&height=144&startFrame=12577&format=mp4&fps=20&tileFormat=mp4&startDwell=0&endDwell=0&boundsLTRB=1715.5301190916311,1337.447788486891,2684.441934216162,1881.7802688939305&labelsFromDataset&nframes=22'
},
{
title: 'Sea-level-rise plus landsat',
src: 'https://thumbnails-v2.createlab.org/thumbnail?root=https%3A%2F%2Fheadless.earthtime.org%23v%3D1359018%2C817444%2C1371426%2C824424%2Cpts%26t%3D0%26ps%3D50%26l%3Dblsat%2Cslr4%26bt%3D0.03%26et%3D0.83%26startDwell%3D0%26endDwell%3D0%26fps%3D30&width=1280&height=720&format=mp4&fps=30&tileFormat=mp4&startDwell=0&endDwell=0&fromScreenshot&minimalUI'
},
{
title: 'Breathecam Clairton4 (export path, mp4)',
src: 'https://thumbnails-v2.createlab.org/thumbnail?root=https%3A%2F%2Fbreathecam.org%23v%3D4481%2C2121%2C4848%2C2327%2Cpts%26t%3D712.275%26ps%3D50%26bt%3D20260514232539%26et%3D20260514233221%26startDwell%3D0%26endDwell%3D0%26d%3D2026-05-14%26s%3Dclairton4%26fps%3D9&width=1280&height=720&format=mp4&fps=9&tileFormat=mp4&startDwell=0&endDwell=0&fromScreenshot&minimalUI&watermark=Breathe%20Project%7CCREATE%20Lab'
}
];
function thumbnail_media_type(url) {
var fields = url.split('&');
if (fields.indexOf('format=png') >= 0 || fields.indexOf('format=jpg') >= 0) {
return 'img';
} else {
return 'video';
}
}
function url_prefix(url) {
return URI(url).protocol() + '://' + URI(url).hostname();
}
function url_relative(url) {
return URI(url).relativeTo(url_prefix(url)).toString();
}
// Turn a /thumbnail URL into the matching /progress URL on the same host.
function progressUrlFor(src) {
return src.replace(/(\/\/[^/]+)\/thumbnail\?/, '$1/progress?');
}
// Attach a progress bar to `container`, poll /progress every 500 ms until the
// media element fires load or the endpoint reports done/error. Only meaningful
// when src is served by *this* host (the one that runs progress.rb).
function attachProgressBar(container, mediaEl, src) {
var $bar = $('<div class="progress"><div class="fill"></div></div>');
var $label = $('<div class="progress-label">starting…</div>');
container.append($bar).append($label);
var progUrl = progressUrlFor(src);
var stopped = false;
function stop() { stopped = true; }
function markDone() {
stopped = true;
$bar.removeClass('err');
$bar.find('.fill').css('width', '100%');
$label.text('done');
}
// On a media error (e.g. /thumbnail returned 400), the server has
// already written its specific error to .progress. Do one final poll
// so the bar shows the real "server_error: …" instead of a generic
// "media error". Paint the red bar synchronously; fill in the text
// once the poll resolves.
function markMediaError() {
stopped = true;
$bar.addClass('err');
$bar.find('.fill').css('width', '100%');
$label.text('media error');
fetch(progUrl, {cache: 'no-store'}).then(function(r) {
return r.ok ? r.json() : null;
}).then(function(d) {
if (d && (d.state === 'error' || d.state === 'server_error')) {
$label.text(d.state.replace('_', ' ') + ': ' + String(d.message || '').slice(0, 200));
}
}).catch(function() {/* swallow */});
}
// If the media element loaded successfully, the compute clearly finished
// — overwrite whatever stale state the last poll returned (e.g. an early
// "unknown" that fired before the server wrote .progress).
mediaEl.addEventListener('load', markDone); // <img>
mediaEl.addEventListener('loadeddata', markDone); // <video>
mediaEl.addEventListener('error', markMediaError);
function tick() {
if (stopped) return;
fetch(progUrl, {cache: 'no-store'}).then(function(r) {
return r.ok ? r.json() : null;
}).then(function(d) {
if (!d || stopped) return;
var $fill = $bar.find('.fill');
if (d.state === 'done') {
$fill.css('width', '100%');
$label.text('done');
stop();
} else if (d.state === 'error' || d.state === 'server_error') {
$bar.addClass('err');
$fill.css('width', '100%');
$label.text(d.state.replace('_', ' ') + ': ' + String(d.message || '').slice(0, 200));
stop();
} else if (d.frames_total) {
var pct = 100 * (d.frames_done || 0) / d.frames_total;
$fill.css('width', pct.toFixed(1) + '%');
$label.text((d.state || '') + ' ' + (d.frames_done || 0) + '/' + d.frames_total);
} else if (d.state === 'unknown' || !d.state) {
// /progress correctly returns "unknown" before the worker has
// written a .progress file. From this page we know the
// /thumbnail request is in flight, so relabel.
$label.text('Not yet started');
} else {
$label.text(d.state);
}
}).catch(function() {/* swallow polling errors */}).then(function() {
setTimeout(tick, 1000);
});
}
setTimeout(tick, 0);
}
function init() {
console.log('init');
for (var i = 0; i < tests.length; i++) {
var test = tests[i];
var title = test.title;
var node;
var media_type = thumbnail_media_type(test.src);
$("body").append(`<h2>${i} ${title} (${media_type})</h2>`);
var prefixes = [url_prefix(test.src), url_prefix(document.location)];
for (var j = 0; j < prefixes.length; j++) {
var src = prefixes[j] + "/" + url_relative(test.src);
if (j == 1) {
src += `&testepoch=${new Date().getTime()}`;
}
var host = URI(prefixes[j]).host();
var $container = $(`<div class="test">` +
` <${media_type} src="${src}" autoplay loop muted style="max-width:250px"></${media_type}>` +
`<br>${host}</div>`);
$('body').append($container);
// Only attach a progress bar to thumbnails served by *this* host;
// /progress isn't routed on other hosts.
if (URI(prefixes[j]).host() === URI(document.location).host()) {
var mediaEl = $container.find(media_type)[0];
attachProgressBar($container, mediaEl, src);
}
}
}
}
$(init);
</script>
</head>
<body>
<!--
<div class="test">
<video src="thumbnail?root=http://explorables.cmucreatelab.org/environmental-timemachines/shenango-20141005-20141006-tm/&boundsLTRB=2084.88990915391,1273.0414920286516,3791.489909153904,2519.6414920286475&width=320&height=240&frameTime=876.8333333333334&nframes=100&format=mp4&tileFormat=mp4&labels=2014-10-06%2009:30:31&recompute" autoplay="autoplay" loop="loop"></video><br>
100-frame video of Shenango with static label
</div>
<div class="test">
<img src="thumbnail?root=http://explorables.cmucreatelab.org/environmental-timemachines/shenango-20141005-20141006-tm/&boundsLTRB=2084.88990915391,1273.0414920286516,3791.489909153904,2519.6414920286475&width=320&height=240&frameTime=876.8333333333334&nframes=10&format=gif&tileFormat=mp4&labels=2014-10-06%2009:30:31&recompute"><br>
10-frame GIF of Shenango with static label
</div>
<div class="test">
<img src="thumbnail?root=http://explorables.cmucreatelab.org/environmental-timemachines/shenango-20141005-20141006-tm/&boundsLTRB=2084.88990915391,1273.0414920286516,3791.489909153904,2519.6414920286475&width=320&height=240&frameTime=876.8333333333334&format=jpg&tileFormat=mp4&labels=2014-10-06%2009:30:31&recompute"><br>
Single-frame JPG of Shenango with static label
</div>
<div class="test">
<img src="thumbnail?root=http://explorables.cmucreatelab.org/environmental-timemachines/shenango-20141005-20141006-tm/&boundsLTRB=2084.88990915391,1273.0414920286516,3791.489909153904,2519.6414920286475&width=320&height=240&frameTime=876.8333333333334&format=png&tileFormat=mp4&labels=2014-10-06%2009:30:31&recompute"><br>
Single-frame PNG of Shenango with static label
</div>
<div class="test">
<img src="thumbnail?root=http://earthengine.google.org/timelapse/data/20130507&boundsLTRB=-1070418.6821624064,661176.8681517515,1950212.7967361556,744089.7881861039&width=146&height=101&frameTime=0&recompute"><br>
World JPG from Earth Timelapse
</div>
-->
</body>
</html>