Skip to content

Commit f6f30f1

Browse files
author
Vincent van der Wal
committed
darkmode
1 parent 2783bde commit f6f30f1

File tree

3 files changed

+67
-2
lines changed

3 files changed

+67
-2
lines changed

src/main.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ import type { Variable, Domain, DomainGroups } from './types';
1515
let url = new URL(document.location.href);
1616
let params = new URLSearchParams(url.search);
1717

18+
let darkMode = false;
19+
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
20+
darkMode = true;
21+
}
22+
if (params.get('dark')) {
23+
darkMode = params.get('dark') === 'true';
24+
}
25+
if (darkMode) {
26+
document.body.classList.add('dark');
27+
}
28+
1829
let domain: Domain;
1930
if (params.get('domain')) {
2031
domain = domains.find((dm) => dm.value === params.get('domain')) ?? domains[0];
@@ -143,9 +154,11 @@ let showPopup = false;
143154
if (mapContainer) {
144155
maplibregl.addProtocol('om', omProtocol);
145156

157+
console.log(darkMode);
158+
146159
map = new maplibregl.Map({
147160
container: mapContainer,
148-
style: `https://maptiler.servert.nl/styles/basic-world-maps/style.json`,
161+
style: `https://maptiler.servert.nl/styles/basic-world-maps${darkMode ? '-dark' : ''}/style.json`,
149162
center: typeof domain.grid.center == 'object' ? domain.grid.center : [0, 0],
150163
zoom: domain?.grid.zoom,
151164
attributionControl: false,
@@ -267,6 +280,7 @@ if (mapContainer) {
267280
<br>
268281
Selected time:
269282
<div id="time_slider_container"></div>
283+
<div id="darkmode_toggle">${darkMode ? 'Light mode' : 'Dark mode'}</div>
270284
</div>
271285
`;
272286

@@ -320,6 +334,16 @@ if (mapContainer) {
320334
changeOMfileURL();
321335
}
322336
});
337+
338+
const darkmodeToggle = document.getElementById(
339+
'darkmode_toggle'
340+
) as HTMLElement;
341+
darkmodeToggle?.addEventListener('click', (e) => {
342+
darkMode = !darkMode;
343+
url.searchParams.set('dark', darkMode);
344+
history.pushState({}, '', url);
345+
window.location.reload();
346+
});
323347
}
324348
});
325349
}

src/style.css

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ body {
6363
}
6464

6565
#info_box {
66+
<<<<<<< HEAD
67+
=======
68+
position: relative;
69+
display: flex;
70+
justify-content: center;
71+
align-items: center;
72+
>>>>>>> 3e343dd (darkmode)
6673
background: rgba(255, 255, 255, 0.8);
6774
border-radius: 15px;
6875
padding: 15px 20px;
@@ -108,3 +115,37 @@ body {
108115
margin-top: 0.5rem;
109116
border-width: 1px;
110117
}
118+
119+
#darkmode_toggle {
120+
position: absolute;
121+
right: 15px;
122+
bottom: 15px;
123+
padding: 6px 10px;
124+
background-color: white;
125+
color: black;
126+
border-radius: 5px;
127+
border: 1px solid black;
128+
cursor: pointer;
129+
}
130+
131+
.dark #info_box {
132+
color: white;
133+
background: rgba(50, 50, 50, 0.85);
134+
}
135+
136+
.dark .domain-selection,
137+
.dark .variable-selection,
138+
.dark .date-time-selection {
139+
background: rgba(100, 100, 100, 0.8);
140+
color: white;
141+
}
142+
143+
.dark #time_slider_container button {
144+
background: rgba(100, 100, 100, 0.8);
145+
color: white;
146+
}
147+
148+
.dark #darkmode_toggle {
149+
background: rgba(100, 100, 100, 0.8);
150+
color: white;
151+
}

src/worker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ self.onmessage = async (message) => {
186186
if (variable.value == 'cloud_cover') {
187187
colors = colorScale({
188188
colorScheme: '',
189-
customColors: ['#999', '#444'],
189+
customColors: ['#FFF', '#c3c2c2'],
190190
min: 0,
191191
max: 100
192192
});

0 commit comments

Comments
 (0)