Skip to content

Commit f6ac088

Browse files
Merge pull request #47 from TheLinuxGuy-ssh/personal
UI Enhancement towards scientific functionality
2 parents e2a626d + 9a7d2d2 commit f6ac088

4 files changed

Lines changed: 321 additions & 200 deletions

File tree

src/lib/components/MapView.svelte

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
<script lang="ts">
22
import { onMount, onDestroy, tick } from "svelte";
33
import { allSites, selectedSiteId } from "$lib/stores/sites";
4+
import { theme } from "$lib/stores/theme";
45
import "leaflet/dist/leaflet.css";
56
import type { SiteSummary } from "$lib/stores/sites";
67
let container: HTMLDivElement;
78
let map: any = null;
89
let markers: Map<string, any> = new Map();
10+
let currentTileLayer: any = null;
11+
let themeUnsub: (() => void) | null = null;
912
1013
const c: Record<string,string> = { stable: "#34d399", watch: "#fbbf24", critical: "#f87171" };
1114
@@ -45,6 +48,19 @@
4548
maxZoom: 19,
4649
}).addTo(map);
4750
51+
themeUnsub = theme.subscribe((t) => {
52+
if (!map) return;
53+
map.eachLayer((l: any) => { if (l._url) map.removeLayer(l); });
54+
const url = t === "light"
55+
? "https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png"
56+
: "https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png";
57+
L.tileLayer(url, {
58+
attribution: '&copy; <a href="https://carto.com/">CARTO</a> &copy; <a href="https://openstreetmap.org">OSM</a>',
59+
subdomains: "abcd",
60+
maxZoom: 19,
61+
}).addTo(map);
62+
});
63+
4864
function renderMarkers(sites: SiteSummary[]) {
4965
markers.forEach(m => map.removeLayer(m));
5066
markers.clear();
@@ -75,7 +91,11 @@
7591
sitesUnsub = allSites.subscribe(renderMarkers);
7692
7793
selectedUnsub = selectedSiteId.subscribe((id) => {
78-
const m = id ? markers.get(id) : null;
94+
if (!id) {
95+
if (map) map.flyTo([20, 20], 2, { duration: 0.6 });
96+
return;
97+
}
98+
const m = markers.get(id);
7999
if (m && map) {
80100
const latlng = m.getLatLng();
81101
map.flyTo(latlng, 8, { duration: 0.8 });
@@ -87,12 +107,16 @@
87107
onDestroy(() => {
88108
sitesUnsub?.();
89109
selectedUnsub?.();
110+
themeUnsub?.();
90111
map?.remove();
91112
});
92113
</script>
93114

94115
<div class="relative z-0 w-full h-full">
95116
<div class="absolute inset-0 overflow-hidden"><div bind:this={container} class="w-full h-full"></div></div>
117+
{#if $theme === "night-vision"}
118+
<div class="absolute inset-0 pointer-events-none z-10" style="background: rgba(80,0,0,0.25); mix-blend-mode: multiply;"></div>
119+
{/if}
96120
</div>
97121

98122
<style>

0 commit comments

Comments
 (0)