-
Notifications
You must be signed in to change notification settings - Fork 0
/
open_data.html
210 lines (202 loc) · 7.44 KB
/
open_data.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Marine Heatwaves</title>
<script src="https://code.iconify.design/2/2.0.4/iconify.min.js"></script>
<style>
.switch {
position: relative;
display: inline-block;
width: 46px;
height: 24px;
}
.switch input {display:none;}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
}
.slider:before {
position: absolute;
content: "";
height: 21px;
width: 21px;
left: 2px;
bottom: 2px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}
input:checked + .slider {
background-color: #2196F3;
}
input:focus + .slider {
box-shadow: 0 0 1px #2196F3;
}
input:checked + .slider:before {
-webkit-transform: translateX(21px);
-ms-transform: translateX(21px);
transform: translateX(21px);
}
/* Rounded sliders */
.slider.round {
border-radius: 24px;
}
.slider.round:before {
border-radius: 50%;
}
.header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 20px;
}
h1 {
margin: 0;
}
.switch-wrapper {
display: flex;
align-items: center;
justify-content: space-between;
width: 100px;
}
.container {
display: flex;
flex-direction: column;
align-items: center;
gap: 10px;
padding: 20px;
}
.row {
display: flex;
justify-content: center;
gap: 10px;
width: 100%;
padding: 10px;
}
.dropdown {
width: 200px;
}
#download {
margin-left: 10px;
}
</style>
<style id="themeStyle">
body { background-color: white; color: black; }
/* Add more light-theme styles here */
</style>
</head>
<body>
<div class="header">
<h1>Marine Heatwaves</h1>
<div>
<div class="switch-wrapper">
<span class="iconify" data-icon="carbon:sun" data-inline="false"></span>
<label for="themeSwitch" class="switch">
<input type="checkbox" id="themeSwitch">
<span class="slider round"></span>
</label>
<span class="iconify" data-icon="carbon:moon" data-inline="false"></span>
</div>
<div class="switch-wrapper">
<img src="https://flagcdn.com/w20/gb.png" alt="English" width="20"/>
<label for="languageSwitch" class="switch">
<input type="checkbox" id="languageSwitch">
<span class="slider round"></span>
</label>
<img src="https://flagcdn.com/w20/tw.png" alt="Traditional Chinese" width="20"/>
</div>
</div>
</div>
<div class="container">
<div class="row">
<label for="startDate">Start date:</label>
<input type="date" id="startDate">
<label for="endDate">End date:</label>
<input type="date" id="endDate">
</div>
<div class="row">
<label for="lon0">Longitude 0:</label>
<input type="number" id="lon0" min="-180" max="180" step="any">
<label for="lon1">Longitude 1:</label>
<input type="number" id="lon1" min="-180" max="180" step="any">
</div>
<div class="row">
<label for="lat0">Latitude 0:</label>
<input type="number" id="lat0" min="-90" max="90" step="any">
<label for="lat1">Latitude 1:</label>
<input type="number" id="lat1" min="-90" max="90" step="any">
</div>
<div class="row">
<select id="dataVariables" class="dropdown" multiple>
<option value="sst_anomaly">Monthly SST Anomalies</option>
<option value="level">Monthly MHW level</option>
<option value="td">Themal Displacement</option>
</select>
<button id="downloadbtn">Download</button>
</div>
</div>
<script>
// Add your existing JavaScript here...
const themeSwitch = document.querySelector('#themeSwitch');
themeSwitch.addEventListener('change', function() {
let theme = this.checked ? 'dark' : 'light';
let themeStyle = document.querySelector('#themeStyle');
if (theme === 'dark') {
themeStyle.innerHTML = `
body { background-color: black; color: white; }
/* Add more dark-theme styles here */
`;
} else {
themeStyle.innerHTML = `
body { background-color: white; color: black; }
/* Add more light-theme styles here */
`;
}
});
const languageSwitch = document.querySelector('#languageSwitch');
languageSwitch.addEventListener('change', function() {
// TODO: Implement language switch functionality
});
// Set default date values
let startDate = document.querySelector('#startDate');
let endDate = document.querySelector('#endDate');
let now = new Date();
endDate.valueAsDate = now;
now.setMonth(now.getMonth() - 1);
now.setDate(1);
startDate.valueAsDate = now;
document.getElementById('downloadbtn').addEventListener('click', async function() {
const lon0 = document.querySelector('#lon0').value;
const lon1 = document.querySelector('#lon1').value;
const lat0 = document.querySelector('#lat0').value;
const lat1 = document.querySelector('#lat1').value;
const start = document.querySelector('#startDate').value;
const end = document.querySelector('#endDate').value;
const dataVariables = Array.from(document.querySelector('#dataVariables').selectedOptions).map(option => option.value);
const url = `https://eco.odb.ntu.edu.tw/api/mhw/csv?lon0=${lon0}&lat0=${lat0}${lon1 ? '&lon1=' + lon1 : ''}${lat1 ? '&lat1=' + lat1 : ''}${start ? '&start=' + start : ''}${end ? '&end=' + end : ''}${dataVariables.length > 0 ? '&append=' + dataVariables.join(',') : ''}`;
const response = await fetch(url);
if (response.ok) {
const blob = await response.blob();
const downloadUrl = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = downloadUrl;
a.download = 'data.csv';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
} else {
console.error('Download failed:', response.status, response.statusText);
}
});
</script>
</body>
</html>