Skip to content

Commit 1d73e5c

Browse files
author
Vincent van der Wal
committed
add position toggle and try something with pressure lines
1 parent 3652669 commit 1d73e5c

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

src/main.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const TILE_SIZE = Number(import.meta.env.VITE_TILE_SIZE);
2727
let map: maplibregl.Map;
2828
const infoBox: HTMLElement | null = document.getElementById('info_box');
2929
const mapContainer: HTMLElement | null = document.getElementById('map_container');
30+
let popup: maplibregl.Popup | undefined;
3031

3132
let omUrl: string;
3233
let timeSelected = new Date();
@@ -95,6 +96,10 @@ const changeOMfileURL = () => {
9596
variableSelector.replaceChildren('');
9697
variableSelector.innerHTML = `${getVariableOptions()}`;
9798

99+
if (popup) {
100+
popup.remove();
101+
}
102+
98103
if (!domain.variables.includes(variable.value)) {
99104
variable = variables.find((v) => v.value === domain.variables[0]) as Variable;
100105
}
@@ -155,6 +160,19 @@ if (mapContainer) {
155160

156161
map.touchZoomRotate.disableRotation();
157162

163+
// Add geolocate control to the map.
164+
map.addControl(
165+
new maplibregl.GeolocateControl({
166+
fitBoundsOptions: {
167+
maxZoom: 9.5
168+
},
169+
positionOptions: {
170+
enableHighAccuracy: true
171+
},
172+
trackUserLocation: true
173+
})
174+
);
175+
158176
map.on('load', async () => {
159177
omUrl = getOMUrl();
160178
source = map.addSource('omFileSource', {
@@ -173,7 +191,6 @@ if (mapContainer) {
173191
'road_area_pier'
174192
);
175193

176-
let popup: maplibregl.Popup | undefined;
177194
map.on('mousemove', function (e) {
178195
if (showPopup) {
179196
const coordinates = e.lngLat;
@@ -192,7 +209,11 @@ if (mapContainer) {
192209
coordinates.lng
193210
);
194211
if (index) {
195-
if (hideZero.includes(variable.value) && value <= 0.25) {
212+
if (
213+
(hideZero.includes(variable.value) &&
214+
value <= 0.25) ||
215+
!value
216+
) {
196217
popup.remove();
197218
} else {
198219
let string = '';

src/worker.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,14 @@ self.onmessage = async (message) => {
320320
if (variable.value == 'cloud_cover') {
321321
rgba[4 * ind + 3] = 255 * (px / 100);
322322
} else if (variable.value == 'precipitation') {
323-
rgba[4 * ind + 3] = 50 + 205 * (px / 10);
323+
rgba[4 * ind + 3] =
324+
50 + 180 * Math.min(px / 12, 10);
325+
} else if (variable.value == 'pressure_msl') {
326+
if (px % 1 > 0.05 || px % 1 > 0.95) {
327+
rgba[4 * ind + 3] = 0;
328+
} else {
329+
rgba[4 * ind + 3] = 255;
330+
}
324331
} else {
325332
rgba[4 * ind + 3] = 255 * (OPACITY / 100);
326333
}

0 commit comments

Comments
 (0)