-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
447 lines (417 loc) · 21.9 KB
/
index.html
File metadata and controls
447 lines (417 loc) · 21.9 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
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Range Mapper</title>
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.11/lodash.min.js"></script>
<script src="https://libs.cartocdn.com/carto-vl/v1.4.4/carto-vl.min.js"></script>
<script src="https://api.tiles.mapbox.com/mapbox-gl-js/v1.0.0/mapbox-gl.js"></script>
<link href="https://api.tiles.mapbox.com/mapbox-gl-js/v1.0.0/mapbox-gl.css" rel="stylesheet" />
<link href="https://carto.com/developers/carto-vl/v1.4.4/examples/maps/style.css" rel="stylesheet">
<link rel="stylesheet" href="css/font-awesome.min.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div id="main">
<div id="map"></div>
<aside class="toolbox" id="animation-toolbox">
<div class="box" id="animation-box">
<div id="btnbox">
<button class="openbtn" onclick="openCloseNav()">ⓘ</button>
</div>
<header>
<h1 id="animation-header"> Range Mapper</h1>
</header>
<hr/>
<div class="select">
<select class="mySelectArrow" id="standard-select" autocomplete="off" onchange="updateMap(taxaLayer)"> <!-- dropdown selector -->
<option value="northamerica">North America</option>
<option value="europe">Europe</option>
<option value="oceania">Oceania</option>
</select>
</div>
<hr/>
<section id="animation-section">
<p class="animation-rangebar" id="legend-head-text">Years Before Present: <span id="js-current-time" id="open-legend-head-text"></span>
</p>
</section>
<section id="animation-section">
<p class="animation-rangebar">
<button><img id="js-play-pause-button" src="img/pause.png"></button>
<input type="range" id="js-progress-range" min="0" max="1" step="0.04">
</p>
</section>
<hr/>
<section id="animation-section">
<div class="animation-rangebar">Duration (seconds):
<input type="range" id="js-duration-range" min="16" max="60" step="2">
<span style="margin-left: 2px" class="open-sans" id="js-duration-span"></span>
</div>
</section>
<hr/>
<!-- Taxa legend data -->
<section>
<div id="controls">
<ul id="content" class="taxa-content"></ul>
</div>
</section>
</div>
</aside>
<!-- Percent abundance legend -->
<div class="box" id="legend-box">
<header id="legend-head-text">
<div>Percent Abundance</div>
</header>
<div id="circ-box">
<ul id="circ-content" class="legend-content"> </ul>
</div>
<div id="logo-div">
<img id="neotoma-logo" src="img/neotomalogo.png" alt="neotoma paleoecology database logo">
<img id="database-logo" src="img/CABAH_logo.png" style="opacity:0%" alt="constituent database logo">
</div>
</div>
</div>
<div id="infoSideBar">
<div>
<header>
<h1>Acknowledgements</h1>
<a class="closebtn" onclick="openCloseNav()">×</a>
</header>
<p>Range Mapper was created by Adrian George, Sydney Widell, Rob Roth, and Jack Williams at the University of Wisconsin-Madison Geography Department and Cartography Lab. The dynamic visualizations are based on
fossil pollen recovered from lake and bog sediments going back to the last Ice Age. Data were obtained from the <a href="http://www.neotomadb.org">Neotoma Paleoecology Database</a>
and its constituent databases: the North American Pollen Database, the European Pollen Database and Alpine Pollen Database, and the Indo-Pacific Pollen Database. The work of data contributors, data stewards,
and the Neotoma community is gratefully acknowledged. Ice sheet data is from Dalton et al (2020) and Hughes et al (2016) - see full citations below.
This work would not have been possible without funding support from NSF (Grant EAR-1550707), the University of Wisconsin–Madison Graduate School, and the Minnie Riess Detling Trust.</p>
<p><b>Code Source:</b> To view our code and make your own maps using data from the Neotoma Paleoecology Database, visit our <a href="https://github.com/NeotomaDB/RangeMapper">GitHub repository</a>. </p>
<p><b>Citation:</b> George, A.K., Roth, R.E., Widell, S. and Williams, J.W., 2023. Range Mapper: An Adaptable Process for Making and Using Interactive, Animated Web Maps of Late-Quaternary Open Paleoecological Data. Open Quaternary, 9(1), p.15.DOI: https://doi.org/10.5334/oq.114
</p>
<p><b>Ice Sheet Citations:</b> Dalton, A.S., Margold, M., Stokes, C.R., Tarasov, L., Dyke, A.S., Adams, R.S., Allard, S., Arends, H.E., Atkinson, N., Attig, J.W., et al. (2020). An updated radiocarbon-based ice margin chronology for
the last deglaciation of the North American Ice Sheet Complex. Quaternary Science Reviews 234, 106223.</p>
<p>Hughes, A.L.C., Gyllencreutz, R., Lohne, Ø.S., Mangerud, J., and Svendsen, J.I. (2016). The last Eurasian ice sheets – a chronological database and time-slice reconstruction, DATED-1. Boreas 45, 1–45.</p>
</div>
</div>
<div id="loader">
<div class="CDB-LoaderIcon CDB-LoaderIcon--big">
<svg class="CDB-LoaderIcon-spinner" viewBox="0 0 50 50">
<circle class="CDB-LoaderIcon-path" cx="25" cy="25" r="20" fill="none"></circle>
</svg>
</div>
</div>
<script>
const s = carto.expressions;
const allTaxaSource = ['northamericapollen', `europepollen`, `oceaniapollen`];
const allIceSource = ['na_ice', 'europe_ice', ''];
const allExtents = [[-115, 50], [20, 57], [145, -27]];
const allTaxaTypes = ['alder', 'beech', 'elm', 'grasses', 'hemlock', 'oak', 'ragweed', 'sedges', 'spruce', 'pine', 'sheoak', 'eucalyptus', 'celerypine', 'cypresspine', 'southernbeech'];
const legendText = ['Alder (<i>Alnus</i>)', 'Beech (<i>Fagus</i>)', 'Elm (<i>Ulmus</i>)', 'Grasses (Poaceae)', 'Hemlock (<i>Tsuga</i>)', 'Oak (<i>Quercus</i>)', 'Ragweed (<i>Ambrosia</i>)', 'Sedges (Cyperaceae)', 'Spruce (<i>Picea</i>)', 'Pine (<i>Pinus</i>)', 'She-Oak (<i>Casuarina</i>)', 'Eucalyptus (<i>Eucalyptus</i>)', 'Celery Pine (<i>Phyllocladus</i>)', 'Cypress-Pine (<i>Callitris</i>)', 'Southern Beech (<i>Nothofagus</i>)']
const taxaColors = ['#339999', '#fad620', '#ff5233', '#000075', '#336699', '#996699', '#ff9b19', '#C7003A', '#ADD55C', '#511849'];
const databaseLogos = ["img/CABAH_logo.png","img/epd_logo.png","img/CABAH_logo.png"]
// Loop creates taxa legend dictionary to connect the taxa names for plotting the data (allTaxaTypes) with the legend labels (legendText)
const legendKeys = {};
for (const x of allTaxaTypes) {
legendKeys[x] = legendText[allTaxaTypes.indexOf(x)];
}
// Create variable for center coordinates of map
let currentExtent = allExtents[0];
// Create variable for initial length of animation
let initialDuration = 31.5;
// Create map container and sets map location & zoom
var map = new mapboxgl.Map({
container: 'map',
style: carto.basemaps.positron,
center: currentExtent,
zoom: 3
});
const nav = new mapboxgl.NavigationControl(); // Add zoom buttons
map.addControl(nav, 'bottom-left');
// input CARTO username and apiKey
carto.setDefaultAuth({
username: 'aegeorge2',
apiKey: 'nXTHpm3Qbb6MZX5ieYvVFA'
});
document.getElementById('js-duration-span').innerHTML = initialDuration;
// Sets pollen data source by name
let taxaSource = new carto.source.Dataset(allTaxaSource[0]);
var taxaTypes = allTaxaTypes
// Creates Carto viz object for taxa of interest
const taxaViz = new carto.Viz(`
@duration: ${initialDuration}
@palette: [#339999, #fad620, #ff5233, #000075, #336699, #996699, #ff9b19, #C7003A, #511849, #ADD55C];
@animation: animation(linear($time), @duration, fade(@duration*0.05,@duration*0.025));
@taxa: $taxa;
@v_histogram: viewportHistogram($taxa);
@opacity: opacity(ramp(@taxa,@palette), 0.45);
color: @opacity;
width: (30*(($samples / 15) ^ 0.5716));
filter: @animation;
strokeWidth: 0.2;
strokeColor: opacity(ramp(@taxa,@palette),0.2);
`);
// Creates Carto map layers for taxa and ice
const taxaLayer = new carto.Layer('layer', taxaSource, taxaViz);
var iceLayer = createIceLayer(0);
// Add layers to map
taxaLayer.addTo(map);
iceLayer.addTo(map);
// Creates Javascript objects for each html button/slider for the animation
const $playPauseButton = document.getElementById('js-play-pause-button');
const $durationRange = document.getElementById('js-duration-range');
const $progressRange = document.getElementById('js-progress-range');
const $spanDuration = document.getElementById('js-duration-span');
const $currentTime = document.getElementById('js-current-time');
const $continentSelection = document.getElementById('continent-selector')
// Save initial time range value
let last = $progressRange.value;
// Listen to interaction events
$durationRange.addEventListener('change', () => {
const duration = parseInt($durationRange.value, 10);
// Update animation duration
taxaViz.variables.duration = $spanDuration.innerHTML = duration
iceViz.variables.duration = $spanDuration.innerHTML = duration
});
// Play & pause button functions
// Listens for clicks on the play/pause button
$playPauseButton.addEventListener('click', playPause);
function playPause() {
paused = taxaViz.variables.animation._paused;
if (paused === false) {
// Pause the animations
taxaViz.variables.animation.pause();
iceViz.variables.animation.pause();
document.getElementById("js-play-pause-button").src="img/play.png";
} else {
// Play the animations
taxaViz.variables.animation.play();
iceViz.variables.animation.play();
document.getElementById("js-play-pause-button").src="img/pause.png";
}
};
// Listens for and updates animation progress when the slider is clicked
$progressRange.addEventListener('change', () => {
// Update animation progress
taxaViz.variables.animation.setProgressPct($progressRange.value);
iceViz.variables.animation.setProgressPct($progressRange.value);
last = $progressRange.value;
});
// Listen to layer events & updates the time bar
taxaLayer.on('updated', () => {
if ($progressRange.value == last) {
$progressRange.value = taxaViz.variables.animation.getProgressPct();
last = $progressRange.value;
}
$currentTime.innerText = parseInt(Math.round(taxaViz.variables.animation.getProgressValue()/500)*500);
});
// Creates taxa proportion circle legend
var legendSizes = [25,50,100]
let widthLegendList = '';
legendSizes.forEach(currentSize => {
currentWidth = 30*Math.pow((currentSize/15),0.5716)
widthLegendList +=
`<li id="legendList"><div class="circle" id="circle${currentSize}" style="width:${currentWidth}px; height:${currentWidth}px;"></div> ${currentSize}</li>`;
});
// Place list items in the content section of the title/legend box
document.getElementById('circ-content').innerHTML = widthLegendList;
// When layer loads, trigger legend event
taxaLayer.on('loaded', () => {
updateLegend();
hideLoader();
});
// Function to create carto viz object for North American & European ice sheets
function createIceViz(){
var iceViz = new carto.Viz(`
@duration:${initialDuration}
@animation: animation(linear($age),@duration, fade(hold,.25))
color: #99daf2
strokeWidth: 0
filter: @animation
`);
return iceViz
}
// Function to create carto layer for ice sheets
function createIceLayer(n){
// If North America (0) or Europe (1), create ice sheet
if (n === 0 || n === 1){
var iceSource = new carto.source.Dataset(allIceSource[n]);
iceViz = createIceViz();
const iceLayer = new carto.Layer('icesheets', iceSource, iceViz);
return iceLayer
}
}
// Fuction to change visualization based on dropdown menu selection
function updateMap(taxaLayer) {
n = setContinent()
// If Oceania, hide ice sheet & add CABAH logo
if (n === 2){
iceLayer.hide()
// If North America or Europe, update ice sheet
} else {
var iceSource = new carto.source.Dataset(allIceSource[n]);
iceLayer.update(iceSource, iceViz);
iceLayer.show()
};
// Update logos
// If North America, make logo transparent
if (n === 0){
document.getElementById("database-logo").style.opacity = "0%";
// If Europe or Oceania, update logo
} else {
document.getElementById("database-logo").src=databaseLogos[n];
document.getElementById("database-logo").style.opacity = "100%";
};
// Update taxaSource & layer
let taxaSource = new carto.source.Dataset(allTaxaSource[n]);
taxaTypes = allTaxaTypes
taxaViz.filter.blendTo(s.and(s.var('animation'),s.in(s.prop('taxa'), taxaTypes)))
const layerPromise = taxaLayer.update(taxaSource, taxaViz);
currentExtent = allExtents[n];
const promiseB = layerPromise.then(map.panTo(currentExtent));
const promiseC = promiseB.then(checkLegend);
promiseC.then(updateLegend);
};
function updateLegend(){
generateLegend();
checkTwo();
};
// Creates HTML legend and legend listeners
function generateLegend() {
// Request data for legend from the layer viz
let legend = taxaLayer.viz.color.getLegendData();
// Create list elements for legend
legend.data.reverse()
let legendList = legend.data.map((legend, index) => {
const color = rgbaToHex(legend.value);
const bordercol = rgbToHex(legend.value);
const key = legend.key; //.toLowerCase().replace(' ', '-');
const selected = taxaTypes.includes(legend.key);
// Use "js-checkbox" class to get all the checkbox elements from the widget
// Use "data-taxa-type" attribute to set the category for each checkbox
return `
<li>
<input
id="js-checkbox-${key}"
class="js-checkbox"
type="checkbox"
name="categories"
data-taxa-type="${legend.key}"
visible="true"
checked>
<span class="point-mark" style="background-color:${color}; border: 1px solid ${bordercol}"></span>
<label for="js-checkbox-${key}"> ${legendKeys[key]} </label>
</li>\n`;
}).join('');
document.getElementById('content').innerHTML = legendList;
// 1. Get all the category checkboxes
const checkboxes = document.getElementsByClassName('js-checkbox');
// 2. Add an event listener to each category checkbox
for (let i in checkboxes) {
const checkbox = checkboxes.item(i);
checkbox.addEventListener('change', toggleCategory);
};
};
// Show only spruce & oak or southern beech & eucalyptus based on continent
function checkTwo(){
var checkboxes = new Array();
checkboxes = document.getElementsByClassName('js-checkbox');
for (var i=0; i<checkboxes.length; i++) {
// 1. Get the clicked checkbox element from the event
const checkboxElement = checkboxes[i];
// 2. Get the category through the "data-taxa-type" attribute
const category = checkboxElement.getAttribute('data-taxa-type');
// Only removes taxa from map not listed above
switch(category){
case 'spruce':
case 'oak':
case 'southernbeech':
case 'eucalyptus':
break;
default:
// 3. Toggle the chosen category from the global taxaTypes array
taxaTypes = _toggle(taxaTypes, category);
// 4. Check / uncheck the checkbox element
checkboxElement.checked = taxaTypes.includes(category);
};
};
// 5. Update the filter
taxaViz.filter.blendTo(s.and(s.var('animation'),s.in(s.prop('taxa'), taxaTypes)));
};
// When checkbox is selected, turns layer for selected taxa on and off
function toggleCategory(event) {
// 1. Get the clicked checkbox element from the event
const checkboxElement = event.currentTarget;
// 2. Get the category through the "data-taxa-type" attribute
const category = checkboxElement.getAttribute('data-taxa-type');
// 3. Toggle the chosen category from the global taxaTypes array
taxaTypes = _toggle(taxaTypes, category);
// 4. Check / uncheck the checkbox element
checkboxElement.checked = taxaTypes.includes(category);
// 5. Update the filter
if (taxaTypes.length === 0) {
taxaLayer.hide()
} else {
if (taxaLayer.visible === false) {
taxaLayer.show()
}
taxaViz.filter.blendTo(s.and(s.var('animation'),s.in(s.prop('taxa'), taxaTypes)));
}
taxaViz.variables.animation.setProgressPct(last);
iceViz.variables.animation.setProgressPct(last);
}
// Checks if legend data has been generated
function checkLegend(){
let legend = taxaLayer.viz.color.getLegendData();
return legend.data
};
//** Helper Methods **//
// A function to convert map colors to HEX values for legend border color
function rgbToHex(color) {
return hex = ("#" + ((1 << 24) + (color.r << 16) + (color.g << 8) + color.b).toString(16).slice(1));
}
// A function to convert map colors to HEXA values for legend
function rgbaToHex(color) {
hex = ("#" + ((1 << 24) + (color.r << 16) + (color.g << 8) + color.b).toString(16).slice(1));
a = Math.round(0.60 * 255).toString(16)
return hex + a;
}
// A function to toggle an element in an array
function _toggle(arr, item) {
return arr.includes(item) ? arr.filter(i => i !== item) : [...arr, item];
};
// Sets continent
function setContinent(){
let selectedContID = document.getElementById('standard-select');
let continentName = selectedContID.value
if (continentName == 'northamerica') {
n = 0
}
else if (continentName == 'europe') {
n = 1
}
else if (continentName == 'oceania') {
n = 2
}
return n
};
// Opens and closes sidebar
function openCloseNav() {
let selectedButton = document.getElementById("infoSideBar");
let sidebarWidth = selectedButton.style.width
if (sidebarWidth === '0px' || !sidebarWidth) {
document.getElementById("infoSideBar").style.width = "350px";
document.getElementById("infoSideBar").style.padding = "32px";
document.getElementById("main").style.marginRight = "300px";
document.getElementById("legend-box").style.marginRight = "350px";
} else {
document.getElementById("infoSideBar").style.width = "0";
document.getElementById("infoSideBar").style.padding = "0";
document.getElementById("main").style.marginRight = "0";
document.getElementById("legend-box").style.marginRight = "0";
}
};
// Hides loader after layer is loaded
function hideLoader() {
document.getElementById('loader').style.opacity = '0';
}
</script>
</body>
</html>