-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex_mammal.html
More file actions
381 lines (349 loc) · 18.9 KB
/
index_mammal.html
File metadata and controls
381 lines (349 loc) · 18.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Megafauna Mapper (demo)</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"> Megafauna Mapper</h1>
</header>
<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="10" max="50" 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>
</div>
<div id="infoSideBar">
<div>
<header>
<h1>Acknowledgements</h1>
<a class="closebtn" onclick="openCloseNav()">×</a>
</header>
<p>Range Mapper (megafauna demo) 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: FAUNMAP, 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.
<b>Symbol Legend:</b> The small, hollow circles represent samples dated after the timestamp of the animation, the large filled circles represent samples dated at the timestamp, the small, filled circles represent samples dated prior to the timestamp.
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.. (in revision). Range Mapper: An Adaptable Process for Making and Using Interactive, Animated Web Maps of Late-Quaternary Open Paleoecological Data. Open Quaternary.</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 allIceSource = ['na_ice', 'europe_ice', ''];
const allExtents = [[-92, 43], [20, 57], [145, -27]];
const allTaxaTypes = ['woollymammoth','americanmastodon']//'woollymammoth', 'americanmastodon'];
const legendText = ['Woolly Mammoth (<i>Mammuthus</i>)', 'American Mastodon (<i>Mammut americanum</i>)']
// 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'];
// 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 = 20;
// Create map container and sets map location & zoom
var map = new mapboxgl.Map({
container: 'map',
style: carto.basemaps.positron,
center: currentExtent,
zoom: 6
});
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('mammal');
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];
@animation: animation(linear($time), @duration, fade(@duration*0.1,@duration*0.05));
@taxa: $taxa;
@v_histogram: viewportHistogram($taxa);
@opacity: opacity(ramp(@taxa,@palette), 1);
color: @opacity;
width: 40;
filter: @animation;
strokeWidth: 0.2;
strokeColor: opacity(ramp(@taxa,@palette),0.2);
`);
// Creates base Carto viz object for taxa of interest
const baseViz = new carto.Viz(`
@palette: [#339999, #fad620, #ff5233, #000075, #336699, #996699, #ff9b19, #C7003A, #511849];
@taxa: $taxa;
@opacity: opacity(ramp(@taxa,@palette), 0.0);
color: @opacity;
width: 15
strokeWidth: 2;
strokeColor: ramp(@taxa,@palette);
` );
// Creates Carto viz object for taxa of interest
const pastViz = new carto.Viz(`
@duration: ${initialDuration}
@palette: [#339999, #fad620, #ff5233, #000075, #336699, #996699, #ff9b19, #C7003A, #511849];
@taxa: $taxa;
@animation: animation(linear($time), @duration, fade(@duration*0.05,hold));
@opacity: opacity(ramp(@taxa,@palette), 0.5);
color: @opacity;
width: 15;
filter: @animation;
strokeWidth: 0.2;
strokeColor: opacity(ramp(@taxa,@palette),0.2);
` );
// Creates Carto map layers for taxa and ice
const baseLayer = new carto.Layer('baselayer', taxaSource, baseViz);
const pastLayer = new carto.Layer('pastlayer', taxaSource, pastViz);
const taxaLayer = new carto.Layer('layer', taxaSource, taxaViz);
var iceLayer = createIceLayer(0);
// Add layers to map
baseLayer.addTo(map);
pastLayer.addTo(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
pastViz.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();
pastViz.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();
pastViz.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);
pastViz.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);
});
// 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,@duration*.05))
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
}
}
function updateLegend(){
generateLegend();
};
// 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);
};
};
// 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) {
baseLayer.hide()
taxaLayer.hide()
pastLayer.hide()
} else {
if (taxaLayer.visible === false) {
baseLayer.show()
taxaLayer.show()
pastLayer.show()
}
taxaViz.filter.blendTo(s.and(s.var('animation'),s.in(s.prop('taxa'), taxaTypes)));
pastViz.filter.blendTo(s.and(s.var('animation'),s.in(s.prop('taxa'), taxaTypes)));
baseViz.filter.blendTo(s.in(s.prop('taxa'), taxaTypes));
}
taxaViz.variables.animation.setProgressPct(last);
pastViz.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];
};
// 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";
} else {
document.getElementById("infoSideBar").style.width = "0";
document.getElementById("infoSideBar").style.padding = "0";
document.getElementById("main").style.marginRight = "0";
}
};
// Hides loader after layer is loaded
function hideLoader() {
document.getElementById('loader').style.opacity = '0';
}
</script>
</body>
</html>