-
Notifications
You must be signed in to change notification settings - Fork 0
/
20220418chinook_stripedbass.html
154 lines (128 loc) · 3.47 KB
/
20220418chinook_stripedbass.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
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title>Chinook salmon & striped bass</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.mapbox.com/mapbox-gl-js/v2.6.1/mapbox-gl.js'></script>
<link href='https://api.mapbox.com/mapbox-gl-js/v2.6.1/mapbox-gl.css' rel='stylesheet' />
<style>
body {
margin: 0;
padding: 0;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
h1 {
font-size: 20px;
line-height: 30px;
}
h2 {
font-size: 14px;
line-height: 20px;
margin-bottom: 10px;
}
#console {
position: absolute;
margin: 10px;
width: 240px;
background-color: white;
padding: 10px 20px;
}
.legend-key {
display: inline-block;
border-radius: 20%;
width: 15px;
height: 15px;
margin-right: 5px;
}
.dot {
height: 12px;
width: 12px;
background-color: #d3a697;
outline-color: #993404;
outline-style: solid;
outline-width: 1;
border-radius: 50%;
margin-left: 1px;
margin-right: 3px;
display: inline-block;
}
.session {
margin-bottom: 20px;
}
.row {
height: 12px;
width: 100%;
}
.label {
width: 15%;
display: inline-block;
text-align: center;
}
</style>
</head>
<body>
<div id='map'></div>
<div id='console'>
<h1>Striped bass and spring run chinook salmon</h1>
<div class='session' id='sliderbar'>
<h2>Year: <label id="year"></label></h2>
<input id='slider' class='row' type='range' min='1873' range = '149' max='2021' value='1873' /><br><br>
<div><span class="legend-key" style="background-color: #c5e2dc;"></span><span>Historical chinook range</span></div><div><span class="legend-key" style="background-color: #86c19f;"></span><span>Current chinook range</span></div>
<span class="dot" ></span> Striped bass observations
</div>
<h2>Data:</h2>
<a href="https://nas.er.usgs.gov/queries/collectioninfo.aspx?SpeciesID=787" target="_blank"
>Striped bass</a
> observations outside their native range<br><br>
<a href="https://pisces.sf.ucdavis.edu/fish-data" target="_blank">Spring run chinook salmon</a> historical and current ranges
</div>
<script>
// Add the chinook salmon range layer
mapboxgl.accessToken = 'pk.eyJ1IjoiZ3JheWNlbiIsImEiOiJja3o2bmFyc2MxMjd2MnBvMm43Zm93N241In0.QlhrXwJi8TAXA6tCVcHwKg';
const map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/graycen/ckzht86x3002515rofs9ji37h',
center: [-121.478851, 38.575764],
zoom: 6.0
});
// Add the striped bass observations
map.on('load', () => {
map.addLayer({
'id': 'bass',
'type': 'circle',
'source': {
type: 'geojson',
data: 'https://graycenw.github.io/mapboxData/striped_bass_cumulative.geojson'
},
'paint': {
'circle-radius': 6,
'circle-color': '#993404',
'circle-opacity': 0.4,
'circle-stroke-width': 0.2
},
'filter': ['==', ['number', ['get', 'year']], 1873]
});
});
// animate striped bass data over years
// filter data based on slider input and set the label to the year
document.getElementById('slider').addEventListener('input', (event) => {
const year = event.target.value;
// update the map
map.setFilter('bass', ['==', 'year', year]);
// update text in the UI
document.getElementById('year').innerText = year
});
// Add zoom and rotation controls to the map.
map.addControl(new mapboxgl.NavigationControl());
// Disable scroll zooming
map.scrollZoom.disable();
</script>
</body>
</html>