From 3542d95c4bb474c80d4879ee0373c3bef84bc267 Mon Sep 17 00:00:00 2001 From: luen Date: Tue, 3 Nov 2026 09:57:15 +1000 Subject: [PATCH] Map: interactive Leaflet map with satellite and street tiles (#29) - InteractiveMap component: lazy-loads Leaflet, satellite (Esri) and OpenStreetMap base layers, toggleable point layers, popups linking to nursery profiles; the SSR SVG MooreaMap stays as the pre-hydration fallback. - Nurseries page: full-width map with CPUE-sized nursery circles and an optional layer of adult blacktip capture spots. - Nursery profile: map zoomed on the site, other nurseries as context. - CSP img-src allows the two tile hosts; e2e stubs tile requests. - MooreaMap registers its points as CSV; attribution in README/About/AGENTS. Closes #29 Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 5 +- README.md | 2 +- e2e/pages.spec.ts | 11 ++ package.json | 2 + pnpm-lock.yaml | 23 +++ src/lib/components/InteractiveMap.svelte | 213 +++++++++++++++++++++++ src/lib/components/MooreaMap.svelte | 11 +- src/routes/about/+page.svelte | 4 + src/routes/nurseries/+page.server.ts | 19 +- src/routes/nurseries/+page.svelte | 42 +++-- src/routes/nurseries/[site]/+page.svelte | 25 ++- vite.config.ts | 10 +- 12 files changed, 345 insertions(+), 22 deletions(-) create mode 100644 src/lib/components/InteractiveMap.svelte diff --git a/AGENTS.md b/AGENTS.md index abeccb3..2e7aaa1 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -44,7 +44,8 @@ src/lib/server/analytics common.ts (CPUE, Fulton's K, recapture pairs…) · env src/lib/server/astro.ts sunset/twilight/moon (local formulas) · tides.ts (extrema, interpolation) src/lib/server/holidays.ts French Polynesia public holidays (Easter-based too) + festive window src/lib/stats.ts regression, Spearman, Welch, Wilson, binomial, histograms, box stats -src/lib/components/ ChartCard, StatTile, DataTable, FindingCard, MooreaMap, charts/* +src/lib/components/ ChartCard, StatTile, DataTable, FindingCard, MooreaMap (SSR SVG), + InteractiveMap (Leaflet, lazy; MooreaMap is its fallback), charts/* src/routes/ one folder per page (+page.server.ts computes, +page.svelte renders) scripts/ fetch-external.mjs · make-fixture.mjs · server.mjs · nightlyRelease.mjs external/ public environmental snapshots (committed) @@ -117,7 +118,7 @@ REAL_DATA_DIR=data pnpm vitest run src/lib/server/import/realData.test.ts # op ## What not to do - Don't edit, rename, re-save or "clean" the spreadsheets. Don't commit them, fixtures derived from them, or SQLite caches. -- Don't add a chart library or third-party scripts/fonts/tiles without updating the CSP in `vite.config.ts` and this file. +- Don't add a chart library or third-party scripts/fonts without updating the CSP in `vite.config.ts` and this file. Map tiles (Esri World Imagery, OpenStreetMap) are the only allowed external images (`img-src`); a new tile host needs the CSP, the e2e tile stub in `e2e/pages.spec.ts` and the attribution. - Don't hard-code numbers in page copy; compute them in the load function. - Don't claim causation from the correlations; don't overstate the human-pressure results (the source paper found no significant effect). - Don't reintroduce dual-axis charts or per-point value labels. diff --git a/README.md b/README.md index b43ae07..8399b64 100644 --- a/README.md +++ b/README.md @@ -86,4 +86,4 @@ Read [AGENTS.md](AGENTS.md) before changing the importer, charts or release proc ## Credits -Survey data © the Physioshark project. Environmental data: Open-Meteo (CC BY 4.0, ERA5 © Copernicus/ECMWF), NOAA OISST v2.1, NOAA Coral Reef Watch (via PacIOOS), University of Hawaii Sea Level Center, NOAA Climate Prediction Center. Coastline © OpenStreetMap contributors (ODbL). +Survey data © the Physioshark project. Environmental data: Open-Meteo (CC BY 4.0, ERA5 © Copernicus/ECMWF), NOAA OISST v2.1, NOAA Coral Reef Watch (via PacIOOS), University of Hawaii Sea Level Center, NOAA Climate Prediction Center. Coastline and street map tiles © OpenStreetMap contributors (ODbL). Satellite imagery © Esri, Maxar, Earthstar Geographics. diff --git a/e2e/pages.spec.ts b/e2e/pages.spec.ts index 521dcd8..c4e70b4 100644 --- a/e2e/pages.spec.ts +++ b/e2e/pages.spec.ts @@ -8,6 +8,17 @@ const ROUTES = [ '/nurseries/haapiti' ]; +// Map tiles come from third-party hosts: serve a blank tile so tests don't depend on them. +const BLANK_PNG = Buffer.from( + 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=', + 'base64' +); +test.beforeEach(async ({ page }) => { + await page.route(/server\.arcgisonline\.com|tile\.openstreetmap\.org/, (route) => + route.fulfill({ contentType: 'image/png', body: BLANK_PNG }) + ); +}); + async function axe(page: Page) { const result = await new AxeBuilder({ page }).withTags(['wcag2a', 'wcag2aa']).analyze(); return result.violations.filter((v) => v.impact === 'serious' || v.impact === 'critical'); diff --git a/package.json b/package.json index 90171d6..c31c448 100644 --- a/package.json +++ b/package.json @@ -36,12 +36,14 @@ "@sveltejs/vite-plugin-svelte": "^7.3.1", "@tailwindcss/vite": "^4.3.3", "@types/better-sqlite3": "^9.6.0", + "@types/leaflet": "^1.9.22", "@types/node": "^26.6.6", "drizzle-kit": "^0.31.11", "eslint": "^10.14.0", "eslint-config-prettier": "^10.1.8", "eslint-plugin-svelte": "^3.23.1", "globals": "^17.13.0", + "leaflet": "^1.9.4", "prettier": "^3.9.10", "prettier-plugin-svelte": "^4.1.1", "svelte": "^5.57.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b3bd362..38716ea 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -203,6 +203,9 @@ importers: '@types/better-sqlite3': specifier: ^9.6.0 version: 9.6.0 + '@types/leaflet': + specifier: ^1.9.22 + version: 1.9.22 '@types/node': specifier: ^26.6.6 version: 26.6.6 @@ -221,6 +224,9 @@ importers: globals: specifier: ^17.13.0 version: 17.14.0 + leaflet: + specifier: ^1.9.4 + version: 1.9.4 prettier: specifier: ^3.9.10 version: 3.9.10 @@ -1064,9 +1070,15 @@ packages: '@types/estree@1.0.10': resolution: {integrity: sha512-lTyOMnOcmRBzdCv6/4zUZCrEhV0xrqQiUZBZtVcbmLHBXKLnN8q89v/wKRF/Q0HbwVsqbIG3o5HDoFl9sduM+g==} + '@types/geojson@7946.0.16': + resolution: {integrity: sha512-6C8nqWur3j98U6+lXDfTUWIfgvZU+EumvpHKcYjujKH7woYyLj2sUmff0tRhrqM7BohUw7Pz3ZB1jj2gW9Fvmg==} + '@types/json-schema@7.0.15': resolution: {integrity: sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==} + '@types/leaflet@1.9.22': + resolution: {integrity: sha512-h3lhECYEKDasG7LFHu+GiHqAvsgLuQvlJvVZzJDGONo3sEL+wUOqSFLnwkZlK0qVxnxbuGFW8iBlJNYs5wgndA==} + '@types/node@26.6.6': resolution: {integrity: sha512-MzQj+8Kx3XI40OmUAE6Qoh58ZMNstNNMwn2nfd3qWsfe7nDNSqJNzes4njhz6AHwrSHOffSLwXU6yb474Q4aog==} @@ -1560,6 +1572,9 @@ packages: known-css-properties@0.37.0: resolution: {integrity: sha512-JCDrsP4Z1Sb9JwG0aJ8Eo2r7k4Ou5MwmThS/6lcIe1ICyb7UBJKGRIUUdqc2ASdE/42lgz6zFUnzAIhtXnBVrQ==} + leaflet@1.9.4: + resolution: {integrity: sha512-nxS1ynzJOmOlHp+iL3FyWqK89GtNL8U8rvlMOsQdTTssxZwCXh8N2NB3GDQOL+YR3XnWyZAxwQixURb+FA74PA==} + levn@0.4.1: resolution: {integrity: sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==} engines: {node: '>= 0.8.0'} @@ -2608,8 +2623,14 @@ snapshots: '@types/estree@1.0.10': {} + '@types/geojson@7946.0.16': {} + '@types/json-schema@7.0.15': {} + '@types/leaflet@1.9.22': + dependencies: + '@types/geojson': 7946.0.16 + '@types/node@26.6.6': dependencies: undici-types: 8.9.0 @@ -3090,6 +3111,8 @@ snapshots: known-css-properties@0.37.0: {} + leaflet@1.9.4: {} + levn@0.4.1: dependencies: prelude-ls: 1.2.1 diff --git a/src/lib/components/InteractiveMap.svelte b/src/lib/components/InteractiveMap.svelte new file mode 100644 index 0000000..df1c828 --- /dev/null +++ b/src/lib/components/InteractiveMap.svelte @@ -0,0 +1,213 @@ + + + + +{#if ready} +
+

Drag to pan, use + / − to zoom. Select a circle for details.

+{:else} + +{/if} + + diff --git a/src/lib/components/MooreaMap.svelte b/src/lib/components/MooreaMap.svelte index 18b369f..f8da3c6 100644 --- a/src/lib/components/MooreaMap.svelte +++ b/src/lib/components/MooreaMap.svelte @@ -14,21 +14,30 @@