-
Notifications
You must be signed in to change notification settings - Fork 58
/
map5.html
276 lines (224 loc) · 8.91 KB
/
map5.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Earthquakes in Japan</title>
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<!-- include google web fonts -->
<link href="https://fonts.googleapis.com/css?family=Titillium+Web|Oswald" rel="stylesheet">
<link href="https://api.mapbox.com/mapbox-gl-js/v2.8.1/mapbox-gl.css" rel="stylesheet">
<!-- include icons -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.8.1/font/bootstrap-icons.css">
<link rel="stylesheet" href="css/c3.min.css">
<style>
body {
margin: 0;
padding: 0;
font-family: 'Titillium Web', serif;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
#info {
z-index: 1000;
position: absolute;
width: 500px;
top: 1%;
bottom: 1%;
left: .5%;
padding: 40px 15px 900px 15px;
background: #343a40;
color: white;
}
/* social media icons */
#info a {
color: lightgray;
}
#info a:hover {
color: white;
opacity: 0.3;
}
#title {
font-size: 25px;
font-family: 'Oswald', sans-serif;
}
/* social media icons */
#title span {
font-size: 14px;
float: right;
margin-right: 10px;
}
#desc {
text-align: center;
color: lightgray;
font-size: medium;
font-weight: bold;
margin-bottom: 0px;
}
#earthquake-count {
margin: 0;
text-align: center;
color: orange;
font-size: 50px;
}
#earthquake-chart {
top: 20px;
}
#footer {
position: absolute;
bottom: 0px;
margin-bottom: 20px;
margin-right: 10px;
font-size: 13px;
line-height: 150%;
color: lightgray;
}
/* the layout of the legend panel */
#legend {
position: absolute;
bottom: 0;
right: 0;
width: 110px;
background: #fff;
margin-right: 20px;
margin-bottom: 40px;
padding: 10px 20px 10px 10px;
border-radius: 3px;
text-align: center;
font-family: 'Open Sans', sans-serif;
}
/* each line for a break */
.break {
position: relative;
margin: 0px;
padding: 0px;
}
/* basic style for a dot/circle */
.dot {
display: inline-block;
margin-top: 5px;
border-radius: 50%;
opacity: 0.6;
}
/* the label for the dot */
.dot-label {
position: absolute;
top: 0;
right: 0;
font-style: italic;
}
</style>
<script src="https://api.mapbox.com/mapbox-gl-js/v2.8.1/mapbox-gl.js"></script>
<!-- include c3.js to make charts. c3.js is built upon d3.js -->
<script src="js/d3.js"></script>
<script src="js/c3.min.js"></script>
</head>
<body>
<div id="info">
<div id="title">
Earthquakes in Japan - September 2017
<span><a href="https://twitter.com/UW" target="_blank"><i class="bi bi-twitter"></i></a></span>
<span><a href="https://github.com/jakobzhao/geog458" target="_blank"><i class="bi bi-github"></i></a></span>
<span id="reset"><a href="#">reset</a></span>
</div>
<div id="count" class="card">
<h5 id="desc"> # Earthquakes in the displaying region</h5>
<p id="earthquake-count"></p>
</div>
<div id="earthquake-chart"></div>
<div id="footer">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et
dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex
ea commodo consequat. Duis aute
irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum
dolor sit amet,
consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute
irure dolor in reprehenderit
in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet,
consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit
in voluptate velit esse cillum
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
deserunt mollit anim id est laborum.
</div>
</div>
<div id="map"></div>
<div id="legend"></div>
<script>
// assign the access token
mapboxgl.accessToken =
'pk.eyJ1IjoiamFrb2J6aGFvIiwiYSI6ImNpcms2YWsyMzAwMmtmbG5icTFxZ3ZkdncifQ.P9MBej1xacybKcDN_jehvw';
// declare the map object
let map = new mapboxgl.Map({
container: 'map', // container ID
style: 'mapbox://styles/mapbox/dark-v10',
zoom: 5, // starting zoom
minZoom: 5,
center: [138, 38] // starting center
});
// declare the coordinated chart as well as other variables.
let earthquakeChart = null,
magnitude = {},
numEarthquakes = 0;
// create a few constant variables.
const grades = [4, 5, 6],
colors = ['rgb(208,209,230)', 'rgb(103,169,207)', 'rgb(1,108,89)'],
radii = [5, 15, 20];
// create the legend object and anchor it to the html element with id legend.
const legend = document.getElementById('legend');
//set up legend grades content and labels
let labels = ['<strong>Magnitude</strong>'],
vbreak;
//iterate through grades and create a scaled circle and label for each
for (var i = 0; i < grades.length; i++) {
vbreak = grades[i];
// you need to manually adjust the radius of each dot on the legend
// in order to make sure the legend can be properly referred to the dot on the map.
dot_radii = 2 * radii[i];
labels.push(
'<p class="break"><i class="dot" style="background:' + colors[i] + '; width: ' + dot_radii +
'px; height: ' +
dot_radii + 'px; "></i> <span class="dot-label" style="top: ' + dot_radii / 2 + 'px;">' + vbreak +
'</span></p>');
}
const source =
'<p style="text-align: right; font-size:10pt">Source: <a href="https://earthquake.usgs.gov/earthquakes/">USGS</a></p>';
// join all the labels and the source to create the legend content.
legend.innerHTML = labels.join('') + source;
// define the asynchronous function to load geojson data.
async function geojsonFetch() {
// Await operator is used to wait for a promise.
// An await can cause an async function to pause until a Promise is settled.
let response;
response = await fetch('assets/earthquakes.geojson');
earthquakes = await response.json();
map.on('load', () => { //simplifying the function statement: arrow with brackets to define a function
});
//load data to the map as new layers.
//map.on('load', function loadingData() {
map.on('idle', () => { //simplifying the function statement: arrow with brackets to define a function
});
}
// call the function
geojsonFetch();
// capture the element reset and add a click event to it.
const reset = document.getElementById('reset');
reset.addEventListener('click', event => {
// this event will trigger the map fly to its origin location and zoom level.
map.flyTo({
zoom: 5,
center: [138, 38]
});
// also remove all the applied filters
// map.setFilter('earthquakes-point', null)
});
</script>
</body>
</html>