garage44.eu/jeroen/cartopolis

logclone: git clone https://garage44.eu/jeroen/cartopolis.git

cartopolis-agent · 2026-11-30T18:30:07Z

feat(web): Admin ▸ Data layers

List the data layers atlas keeps, with their record counts, when the
source was last asked and changed, and its error if it failed; refresh
or delete one. A new layer is made in the mockup's three steps: paste a
dataset's address and pick one of its map queries, see what it draws
(its points, north up, coloured by the chosen column, with the key),
and say how it shows - name, group, title and colour columns, the
fields on the card, how often to ask again, credit and licence - then
publish it. bun run mock shows the page with every eighth of
Noorderzijlvest's weirs.
crates/atlas/web/mock.ts                           |  90 +++++
 .../web/src/components/elements/admin/admin.tsx    |   3 +
 .../atlas/web/src/components/pages/feeds/feeds.css | 130 +++++++
 .../atlas/web/src/components/pages/feeds/feeds.tsx | 418 +++++++++++++++++++++
 crates/atlas/web/src/css/app.css                   |   1 +
 crates/atlas/web/src/lib/feeds.test.ts             |  39 ++
 crates/atlas/web/src/lib/feeds.ts                  | 147 ++++++++
 crates/atlas/web/src/lib/roles.ts                  |   3 +-
 crates/atlas/web/src/types.ts                      |  55 +++
 9 files changed, 885 insertions(+), 1 deletion(-)

diff --git a/crates/atlas/web/mock.ts b/crates/atlas/web/mock.ts
index cefacf75..44bf1b4f 100644
--- a/crates/atlas/web/mock.ts
+++ b/crates/atlas/web/mock.ts
@@ -34,6 +34,8 @@ import type {
     SigninTicket,
     BuildingAddress,
     BuildingOverride,
+    FeedDataset,
+    FeedListed,
     LibraryEntry,
     OwnedBuilding,
     PermissionInfo,
@@ -857,6 +859,54 @@ function liveLog(job: PipelineJob): PipelineLogLine[] {
     ]
 }
 
+// Data layers (`lib/feeds.ts`): one published layer, and what a pasted TripleXL
+// address answers. The preview's points are every eighth of Noorderzijlvest's
+// 1,578 weirs as TripleXL answered on 2026-11-30.
+const feedValues: string[] = ["overlaat", "schotbalkstuw", "stuw met klep", "stuw met schuif", "tuimel- of kantelstuw", "onbekend", "overig"]
+const feedPoints: [number, number, number][] = [[53.1533, 6.2754, 1], [53.3034, 6.7684, 2], [53.3319, 6.9207, 0], [52.9813, 6.4358, 3], [53.2289, 6.3241, 0], [53.1294, 6.3039, 3], [53.4350, 6.7858, 2], [53.2361, 6.4267, 1], [53.2208, 6.3053, 0], [53.3995, 6.7075, 2], [52.9597, 6.4363, 2], [53.0668, 6.4015, 0], [53.2445, 6.3572, 4], [53.2644, 6.5058, 1], [53.1736, 6.3797, 1], [53.1497, 6.3693, 3], [53.2551, 6.5910, 0], [53.4132, 6.8136, 2], [53.2544, 6.5982, 0], [53.2287, 6.3239, 4], [53.1584, 6.2725, 0], [53.1313, 6.2555, 1], [53.2494, 6.3677, 4], [53.0954, 6.3306, 4], [53.2562, 6.5819, 2], [53.0574, 6.5520, 0], [53.3017, 6.6127, 0], [52.9533, 6.4114, 2], [53.0938, 6.5679, 2], [53.1435, 6.2350, 1], [53.3947, 6.5214, 2], [53.0655, 6.3825, 4], [53.0991, 6.5639, 4], [53.3046, 6.6131, 1], [53.2418, 6.3318, 0], [53.2374, 6.3367, 0], [53.2491, 6.3736, 0], [53.2277, 6.3191, 0], [53.2098, 6.3224, 0], [53.1673, 6.4032, 4], [53.0068, 6.4145, 3], [53.1682, 6.4220, 1], [53.2386, 6.2807, 1], [53.1376, 6.2949, 1], [53.1260, 6.2298, 1], [53.1450, 6.2827, 1], [53.1432, 6.2011, 2], [53.1366, 6.3680, 1], [53.1193, 6.3077, 2], [53.0091, 6.4115, 2], [53.1580, 6.3061, 1], [53.3151, 6.8310, 1], [53.2271, 6.5036, 3], [53.2679, 6.4301, 3], [53.1247, 6.4602, 0], [53.1600, 6.4414, 2], [53.3173, 6.6769, 2], [53.4449, 6.7324, 2], [53.4019, 6.6835, 1], [53.1436, 6.1853, 0], [53.2542, 6.5914, 0], [53.4543, 6.7916, 3], [53.2448, 6.3974, 0], [53.2044, 6.4491, 3], [53.3225, 6.8356, 0], [53.0273, 6.3907, 4], [53.0507, 6.3826, 4], [53.1899, 6.3897, 3], [53.0893, 6.3574, 0], [53.1078, 6.4776, 4], [53.0285, 6.4356, 0], [53.1033, 6.4738, 0], [53.2877, 6.7482, 0], [53.3079, 6.7623, 0], [53.3064, 6.8117, 0], [53.1686, 6.5414, 2], [53.2500, 6.5914, 0], [53.2638, 6.5373, 1], [53.2386, 6.5578, 0], [53.2210, 6.5220, 0], [53.1446, 6.3661, 0], [53.1676, 6.3127, 0], [53.1392, 6.3013, 1], [53.1542, 6.1948, 0], [53.1442, 6.3626, 1], [53.4161, 6.4644, 3], [53.3364, 6.6508, 0], [53.3272, 6.5894, 0], [53.3071, 6.5759, 0], [53.1325, 6.2643, 1], [53.3495, 6.6019, 0], [53.1592, 6.3481, 0], [53.1938, 6.3542, 0], [53.3471, 6.5951, 3], [53.1645, 6.4415, 3], [53.1831, 6.4493, 0], [53.2774, 6.6854, 0], [53.2836, 6.3223, 1], [53.3141, 6.8777, 0], [53.1617, 6.3929, 0], [53.2623, 6.5480, 3], [53.2770, 6.4737, 0], [53.2927, 6.5721, 6], [53.1955, 6.4415, 3], [53.0879, 6.4868, 4], [53.1630, 6.4334, 1], [53.4064, 6.2652, 1], [53.0024, 6.4443, 3], [53.0117, 6.4012, 1], [53.1601, 6.4154, 1], [53.2440, 6.4135, 0], [53.2237, 6.2739, 1], [53.3059, 6.8494, 0], [53.0913, 6.4266, 5], [53.0729, 6.4098, 0], [53.2521, 6.5271, 0], [53.0975, 6.4214, 1], [53.0792, 6.4142, 0], [53.1118, 6.4449, 0], [53.1135, 6.4431, 0], [53.2284, 6.5044, 0], [53.1577, 6.2611, 0], [53.0965, 6.3238, 6], [53.3016, 6.5080, 5], [53.3313, 6.5073, 6], [53.3220, 6.8669, 0], [53.2458, 6.6245, 2], [53.2154, 6.3057, 1], [53.1450, 6.3649, 0], [53.3332, 6.9099, 0], [53.1442, 6.2643, 0], [53.2471, 6.4061, 0], [53.2350, 6.3514, 0], [53.1186, 6.5208, 0], [53.1762, 6.4028, 5], [53.2593, 6.3119, 0], [53.1429, 6.2758, 0], [53.2986, 6.6036, 3], [53.1544, 6.4863, 0], [53.1722, 6.3023, 5], [53.1158, 6.4548, 0], [53.1935, 6.4293, 3], [53.3261, 6.5077, 0], [53.1253, 6.4079, 0], [53.1401, 6.4121, 1], [52.9874, 6.4300, 3], [53.0680, 6.4579, 0], [53.0442, 6.5277, 0], [53.0474, 6.5253, 0], [53.3721, 6.1629, 4], [53.3464, 6.5909, 0], [53.1999, 6.3351, 0], [53.1058, 6.4733, 4], [53.1970, 6.4127, 3], [53.1289, 6.4548, 0], [53.1292, 6.4548, 0], [53.0563, 6.5202, 0], [53.1608, 6.5544, 1], [53.2050, 6.4974, 0], [52.9759, 6.4593, 2], [53.3213, 6.1878, 0], [53.0333, 6.4408, 1], [53.3315, 6.4498, 4], [53.2581, 6.6459, 2], [53.0054, 6.3984, 1], [53.2706, 6.5524, 0], [53.0944, 6.5940, 0], [53.2515, 6.6724, 1], [53.1915, 6.5440, 3], [53.4083, 6.6854, 0], [53.2733, 6.5287, 4], [53.2998, 6.6986, 4], [53.2922, 6.7332, 0], [53.3997, 6.4499, 0], [53.0470, 6.5499, 0], [53.1869, 6.3567, 3], [53.0231, 6.3995, 3], [52.9976, 6.4250, 3], [53.4094, 6.6787, 1], [53.2185, 6.4646, 3], [53.3150, 6.8351, 0], [53.1726, 6.3909, 0], [53.2307, 6.6067, 0], [53.2234, 6.3404, 7], [53.3914, 6.4295, 7], [53.2622, 6.5093, 7], [53.3116, 6.6398, 0], [53.3338, 6.5105, 0], [53.3132, 6.8708, 0], [53.3014, 6.5191, 7], [52.9821, 6.4503, 0], [53.2717, 6.3365, 0], [53.2631, 6.4172, 0], [53.3141, 6.4226, 7], [53.2666, 6.5123, 0], [53.2673, 6.4212, 5], [53.3193, 6.6850, 1], [53.1767, 6.5632, 0]]
+const feeds: FeedListed[] = [
+    {
+        def: {
+            colour_by: 'soort',
+            credit: 'Waterschap Noorderzijlvest open data',
+            fields: ['code', 'soort'],
+            geometry: 'wkt',
+            group: 'Waterschap Noorderzijlvest',
+            id: 'noorderzijlvest-stuwen',
+            licence: 'CC BY 4.0',
+            link: '',
+            name: 'Stuwen',
+            refresh_hours: 6,
+            source: {dataset: 'https://www.triplexl.nl/datasets/archixl/noorderzijlvest', kind: 'triplexl', query: 'stuwen-kaart'},
+            title: 'naam',
+        },
+        state: {
+            cells: 61,
+            changed_ms: 1_764_350_000_000,
+            error: null,
+            ok_ms: 1_764_520_000_000,
+            placed: 1578,
+            rows: 1578,
+            tried_ms: 1_764_520_000_000,
+            values: feedValues,
+        },
+    },
+]
+const feedDataset: FeedDataset = {
+    dataset: 'https://www.triplexl.nl/datasets/archixl/noorderzijlvest',
+    licence: 'CC BY 4.0',
+    name: 'Waterschap Noorderzijlvest open data',
+    publisher: 'Waterschap Noorderzijlvest',
+    queries: [
+        {colour: 'functie', description: 'De gemalen op de kaart, met een kleur per functie', map: true, name: 'gemalen-kaart', parameters: 0},
+        {colour: 'soort', description: 'De sluizen op de kaart, met een kleur per soort', map: true, name: 'sluizen-kaart', parameters: 0},
+        {colour: '', description: 'De stuwen op de kaart', map: true, name: 'stuwen-kaart', parameters: 0},
+        {colour: 'soort', description: 'Stuwen zoeken', map: true, name: 'stuwen-zoeken', parameters: 1},
+        {colour: '', description: 'Het aantal bruggen', map: false, name: 'bruggen-aantal', parameters: 0},
+    ],
+    statements: 4_144_625,
+}
+
 const overrides: BuildingOverride[] = [
     {
         author: 'viberfox',
@@ -1718,6 +1768,46 @@ export async function mockApi(req: Request, url: URL): Promise<Response | null>
             return json({job, lines: all.slice(since), total: all.length})
         }
     }
+    if (p === '/api/pipeline/feeds' && method === 'GET') {
+        return json({feeds})
+    }
+    if (p === '/api/pipeline/feeds/inspect' && method === 'POST') {
+        return json({dataset: feedDataset})
+    }
+    if (p === '/api/pipeline/feeds/preview' && method === 'POST') {
+        const asked = await body<{colour_by: string}>(req)
+        const coloured = asked.colour_by === 'soort'
+        return json({
+            preview: {
+                columns: ['code', 'naam', 'soort', 'stuw', 'wkt'],
+                geometry: 'wkt',
+                placed: 1578,
+                points: feedPoints.map(([lat, lng, v]) => [lat, lng, coloured ? v : -1]),
+                rows: 1578,
+                sample: [{code: 'KST6211', naam: 'Hoge Noorderplantsoenstuw', soort: 'overlaat', stuw: 'https://www.triplexl.nl/id/noorderzijlvest/stuw/KST6211'}],
+                values: coloured ? feedValues : [],
+            },
+        })
+    }
+    if (parts[1] === 'pipeline' && parts[2] === 'feeds' && parts.length >= 4) {
+        const id = parts[3]
+        if (method === 'PUT') {
+            const def = await body<FeedListed['def']>(req)
+            const listed: FeedListed = {def: {...feeds[0].def, ...def, id}, state: {...feeds[0].state, tried_ms: Date.now(), ok_ms: Date.now()}}
+            const at = feeds.findIndex((f) => f.def.id === id)
+            if (at >= 0) feeds[at] = listed
+            else feeds.push(listed)
+            return json({error: null, feed: listed})
+        }
+        if (method === 'DELETE') {
+            const at = feeds.findIndex((f) => f.def.id === id)
+            if (at >= 0) feeds.splice(at, 1)
+            return new Response(null, {status: 204})
+        }
+        if (parts[4] === 'refresh' && method === 'POST') {
+            return json({state: feeds.find((f) => f.def.id === id)?.state})
+        }
+    }
     if (p === '/api/pipeline/overrides' && method === 'GET') {
         return json({overrides})
     }
diff --git a/crates/atlas/web/src/components/elements/admin/admin.tsx b/crates/atlas/web/src/components/elements/admin/admin.tsx
index 0d32e2eb..7ab8d9d7 100644
--- a/crates/atlas/web/src/components/elements/admin/admin.tsx
+++ b/crates/atlas/web/src/components/elements/admin/admin.tsx
@@ -7,6 +7,7 @@ import {$s} from '@/app'
 import {Accounts} from '@/components/pages/accounts/accounts'
 import {Claims} from '@/components/pages/claims/claims'
 import {ContentPages} from '@/components/pages/content-pages/content-pages'
+import {Feeds} from '@/components/pages/feeds/feeds'
 import {Library} from '@/components/pages/library/library'
 import {Overrides} from '@/components/pages/overrides/overrides'
 import {Pipeline} from '@/components/pages/pipeline/pipeline'
@@ -62,6 +63,8 @@ function page(tab: AdminTab) {
     switch (tab) {
         case 'claims':
             return <Claims />
+        case 'feeds':
+            return <Feeds />
         case 'library':
             return <Library />
         case 'overrides':
diff --git a/crates/atlas/web/src/components/pages/feeds/feeds.css b/crates/atlas/web/src/components/pages/feeds/feeds.css
new file mode 100644
index 00000000..8494a30f
--- /dev/null
+++ b/crates/atlas/web/src/components/pages/feeds/feeds.css
@@ -0,0 +1,130 @@
+/* Admin ▸ Data ▸ Data layers (`docs/mockups/data-layers/`, sheet 2). */
+
+.feeds,
+.feeds-new {
+    display: flex;
+    flex-direction: column;
+    gap: var(--m-space-4);
+}
+
+.feeds-head,
+.feeds-row,
+.feeds-actions,
+.feeds-item__main {
+    align-items: center;
+    display: flex;
+    flex-wrap: wrap;
+    gap: var(--m-space-2) var(--m-space-3);
+}
+
+.feeds-row > :first-child {
+    flex: 1;
+    min-width: 16rem;
+}
+
+.feeds-spacer {
+    flex: 1;
+}
+
+.feeds-count,
+.feeds-note,
+.feeds-meta,
+.feeds-group,
+.feeds-label {
+    color: var(--m-text-dim);
+    font-size: var(--m-font-size-sm);
+    margin: 0;
+}
+
+.feeds-step {
+    color: var(--m-text-strong);
+    font-size: var(--m-font-size-md, 1rem);
+    margin: 0 0 var(--m-space-3);
+}
+
+.feeds-empty {
+    border: 1px dashed var(--m-border);
+    border-radius: var(--m-radius);
+    color: var(--m-text-dim);
+    margin: 0;
+    padding: var(--m-space-5) var(--m-space-4);
+    text-align: center;
+}
+
+.feeds-found {
+    background: var(--m-surface-raised);
+    border: 1px solid var(--m-border);
+    border-radius: var(--m-radius);
+    font-size: var(--m-font-size-sm);
+    margin: var(--m-space-3) 0;
+    padding: var(--m-space-3);
+}
+
+.feeds-map {
+    background: var(--m-surface-raised);
+    border-radius: var(--m-radius);
+    display: block;
+    height: auto;
+    max-width: 100%;
+}
+
+.feeds-map circle {
+    stroke: rgb(0 0 0 / 0.45);
+    stroke-width: 0.8;
+}
+
+.feeds-key {
+    display: flex;
+    flex-wrap: wrap;
+    font-size: var(--m-font-size-sm);
+    gap: var(--m-space-1) var(--m-space-3);
+    margin-top: var(--m-space-2);
+}
+
+.feeds-key span {
+    align-items: center;
+    display: inline-flex;
+    gap: var(--m-space-1);
+}
+
+.feeds-key i {
+    border-radius: 50%;
+    display: inline-block;
+    height: 9px;
+    width: 9px;
+}
+
+.feeds-fields {
+    display: flex;
+    flex-direction: column;
+    gap: var(--m-space-1);
+    margin: var(--m-space-3) 0;
+}
+
+.feeds-list {
+    list-style: none;
+    margin: 0;
+    padding: 0;
+}
+
+.feeds-item {
+    border-top: 1px solid var(--m-border);
+    display: flex;
+    flex-direction: column;
+    gap: var(--m-space-1);
+    padding: var(--m-space-3) var(--m-space-4);
+}
+
+.feeds-item:first-child {
+    border-top: none;
+}
+
+.feeds-name {
+    color: var(--m-text-strong);
+    font-weight: 600;
+}
+
+.feeds-error {
+    color: var(--m-danger, #e5483a);
+    font-size: var(--m-font-size-sm);
+}
diff --git a/crates/atlas/web/src/components/pages/feeds/feeds.tsx b/crates/atlas/web/src/components/pages/feeds/feeds.tsx
new file mode 100644
index 00000000..53485421
--- /dev/null
+++ b/crates/atlas/web/src/components/pages/feeds/feeds.tsx
@@ -0,0 +1,418 @@
+import m, {MithrilComponent} from '@garage44/mithril'
+import {Badge, Button, Card, FieldCheckbox, FieldNumber, FieldSelect, FieldText} from '@garage44/mithril/components'
+
+import type {FeedDataset, FeedDef, FeedListed, FeedPreview} from '@/types'
+
+import {
+    colour,
+    deleteFeed,
+    inspect,
+    loadFeeds,
+    preview,
+    project,
+    publisherSlug,
+    refreshFeed,
+    saveFeed,
+    slug,
+    when,
+} from '@/lib/feeds'
+import {bind, local} from '@/lib/reactive'
+
+const MAP_W = 560
+const MAP_H = 360
+
+/** A string field of a `local()` as a select's model: the select may write `null`. */
+function choice<T extends object>(s: T, key: {[K in keyof T]: T[K] extends string ? K : never}[keyof T]) {
+    return {
+        get value(): string | null {
+            return s[key] as string
+        },
+        set value(v: string | null) {
+            ;(s[key] as string) = v ?? ''
+        },
+    }
+}
+
+interface Draft {
+    url: string
+    dataset: FeedDataset | null
+    query: string
+    preview: FeedPreview | null
+    name: string
+    group: string
+    title: string
+    colour_by: string
+    fields: string[]
+    credit: string
+    licence: string
+    refresh_hours: number | null
+    busy: boolean
+}
+
+function fresh(): Draft {
+    return {
+        busy: false,
+        colour_by: '',
+        credit: '',
+        dataset: null,
+        fields: [],
+        group: '',
+        licence: '',
+        name: '',
+        preview: null,
+        query: '',
+        refresh_hours: 6,
+        title: '',
+        url: '',
+    }
+}
+
+/** The preview's dots on a plain ground, north up (`lib/feeds.project`). */
+function PreviewMap({p}: {p: FeedPreview}) {
+    const dots = project(p.points, MAP_W, MAP_H)
+    return (
+        <svg class="feeds-map" height={MAP_H} role="img" viewBox={`0 0 ${MAP_W} ${MAP_H}`} width={MAP_W}>
+            <title>{`${p.placed.toLocaleString()} records`}</title>
+            {dots.map(([x, y, v]) => (
+                <circle cx={x.toFixed(1)} cy={y.toFixed(1)} fill={colour(v)} r="3" />
+            ))}
+        </svg>
+    )
+}
+
+/** Adding a layer: the source, what it draws, how it shows (the mockup's sheet 2). */
+class NewFeed extends MithrilComponent<{onDone: (saved: boolean) => void}> {
+    d = local<Draft>(fresh())
+
+    async look() {
+        const d = this.d
+        d.busy = true
+        const found = await inspect(d.url)
+        d.busy = false
+        d.dataset = found
+        d.preview = null
+        if (found) {
+            const first = found.queries.find((q) => q.map && !q.parameters)
+            d.credit = found.name
+            d.licence = found.licence
+            d.group = found.publisher || found.name
+            if (first) {
+                d.query = first.name
+                void this.ask()
+            }
+        }
+    }
+
+    async ask() {
+        const d = this.d
+        if (!d.dataset || !d.query) {
+            return
+        }
+        const q = d.dataset.queries.find((x) => x.name === d.query)
+        d.busy = true
+        const p = await preview(d.dataset.dataset, d.query, d.colour_by || q?.colour || '')
+        d.busy = false
+        d.preview = p
+        if (p) {
+            const named = (c: string) => p.columns.includes(c)
+            d.colour_by = d.colour_by && named(d.colour_by) ? d.colour_by : q?.colour && named(q.colour) ? q.colour : ''
+            d.title = ['naam', 'name', 'titel', 'title', 'label'].find(named) ?? p.columns.find((c) => c !== p.geometry) ?? ''
+            d.fields = p.columns.filter((c) => c !== p.geometry && c !== d.title && !looksLikeIri(p, c)).slice(0, 4)
+            if (!d.name && q) {
+                d.name = q.description.replace(/ op de kaart.*$/i, '').replace(/^De /, '')
+            }
+        }
+    }
+
+    def(): FeedDef | null {
+        const d = this.d
+        if (!d.dataset || !d.preview) {
+            return null
+        }
+        return {
+            colour_by: d.colour_by,
+            credit: d.credit.trim(),
+            fields: d.fields,
+            geometry: d.preview.geometry,
+            group: d.group.trim(),
+            id: slug(`${publisherSlug(d.dataset.dataset)}-${d.name}`),
+            licence: d.licence.trim(),
+            link: '',
+            name: d.name.trim(),
+            refresh_hours: d.refresh_hours ?? 6,
+            source: {dataset: d.dataset.dataset, kind: 'triplexl', query: d.query},
+            title: d.title,
+        }
+    }
+
+    view(vnode: m.Vnode<{onDone: (saved: boolean) => void}>) {
+        const d = this.d
+        const p = d.preview
+        // A new query or colour column asks the source again.
+        const askAgain = () => this.ask()
+        const queries = d.dataset?.queries ?? []
+        const def = this.def()
+        const ready = !!def && !!def.name && !!def.title && !!def.credit && !!def.group && p!.placed > 0
+        const columns = p ? p.columns.filter((c) => c !== p.geometry) : []
+        return (
+            <div class="feeds-new">
+                <Card>
+                    <h3 class="feeds-step">1 · Source</h3>
+                    <div class="feeds-row">
+                        <FieldText
+                            disabled={d.busy}
+                            help="A TripleXL dataset's address, or one of its pages: https://www.triplexl.nl/datasets/{account}/{dataset}"
+                            label="Address"
+                            model={bind(d, 'url')}
+                        />
+                        <Button disabled={!d.url.trim() || d.busy} loading={d.busy && !d.dataset} onclick={() => void this.look()} variant="secondary">
+                            Look it up
+                        </Button>
+                    </div>
+                    {d.dataset && (
+                        <div class="feeds-found">
+                            <b>{d.dataset.name}</b> — {d.dataset.publisher}, {d.dataset.licence},{' '}
+                            {d.dataset.statements.toLocaleString()} statements
+                        </div>
+                    )}
+                    {d.dataset && (
+                        <FieldSelect
+                            disabled={d.busy}
+                            help="Queries TripleXL marks as maps come first. One that asks for a value cannot be a layer by itself."
+                            label="Query"
+                            model={{
+                                get value() {
+                                    return d.query
+                                },
+                                set value(v: string | null) {
+                                    d.query = v ?? ''
+                                    void askAgain()
+                                },
+                            }}
+                            options={queries.map((q) => ({
+                                disabled: q.parameters > 0,
+                                label: `${q.description || q.name}${q.map ? ' · map' : ''}${q.parameters ? ' · asks for a value' : ''}`,
+                                value: q.name,
+                            }))}
+                        />
+                    )}
+                </Card>
+                {p && (
+                    <Card>
+                        <h3 class="feeds-step">2 · What it draws</h3>
+                        <PreviewMap p={p} />
+                        <p class="feeds-note">
+                            {p.rows.toLocaleString()} records, {p.placed.toLocaleString()} with a place
+                            {p.geometry ? `, from the column “${p.geometry}”` : ' — no column holds points'}
+                        </p>
+                        {!!p.values.length && (
+                            <div class="feeds-key">
+                                {p.values.map((v, i) => (
+                                    <span>
+                                        <i style={`background: ${colour(i)}`} />
+                                        {v}
+                                    </span>
+                                ))}
+                                <span>
+                                    <i style={`background: ${colour(p.values.length)}`} />
+                                    other
+                                </span>
+                            </div>
+                        )}
+                    </Card>
+                )}
+                {p && (
+                    <Card>
+                        <h3 class="feeds-step">3 · How it shows</h3>
+                        <FieldText label="Name" model={bind(d, 'name')} />
+                        <FieldText help="Its heading in Layers ▸ Data" label="Group" model={bind(d, 'group')} />
+                        <FieldSelect label="Title on the card" model={choice(d, 'title')} options={columns.map((c) => ({label: c, value: c}))} />
+                        <FieldSelect
+                            label="Colour by"
+                            model={{
+                                get value() {
+                                    return d.colour_by
+                                },
+                                set value(v: string | null) {
+                                    d.colour_by = v ?? ''
+                                    void askAgain()
+                                },
+                            }}
+                            options={[{label: 'One colour', value: ''}, ...columns.map((c) => ({label: c, value: c}))]}
+                        />
+                        <div class="feeds-fields">
+                            <span class="feeds-label">On the card</span>
+                            {columns
+                                .filter((c) => c !== d.title)
+                                .map((c) => (
+                                    <FieldCheckbox
+                                        label={c}
+                                        model={{
+                                            get value() {
+                                                return d.fields.includes(c)
+                                            },
+                                            set value(on: boolean) {
+                                                d.fields = on ? [...d.fields, c] : d.fields.filter((f) => f !== c)
+                                            },
+                                        }}
+                                    />
+                                ))}
+                        </div>
+                        <FieldNumber label="Ask the source again every" model={bind(d, 'refresh_hours')} unit="hours" />
+                        <FieldText help="As the source asks to be credited" label="Credit" model={bind(d, 'credit')} />
+                        <FieldText label="Licence" model={bind(d, 'licence')} />
+                        <div class="feeds-actions">
+                            <Button
+                                disabled={!ready || d.busy}
+                                loading={d.busy}
+                                onclick={async () => {
+                                    const def = this.def()
+                                    if (!def) return
+                                    d.busy = true
+                                    const saved = await saveFeed(def)
+                                    d.busy = false
+                                    if (saved) vnode.attrs.onDone(true)
+                                }}
+                                variant="primary"
+                            >
+                                Publish layer
+                            </Button>
+                            <Button onclick={() => vnode.attrs.onDone(false)} variant="ghost">
+                                Cancel
+                            </Button>
+                        </div>
+                    </Card>
+                )}
+                {!p && (
+                    <div class="feeds-actions">
+                        <Button onclick={() => vnode.attrs.onDone(false)} variant="ghost">
+                            Cancel
+                        </Button>
+                    </div>
+                )}
+            </div>
+        )
+    }
+}
+
+/** A column whose sample values are all addresses: the record's own, not a field. */
+function looksLikeIri(p: FeedPreview, column: string): boolean {
+    const values = p.sample.map((r) => r[column]).filter(Boolean)
+    return values.length > 0 && values.every((v) => /^https?:\/\//.test(v))
+}
+
+/**
+ * Admin ▸ Data ▸ Data layers: the layers atlas reads from open data, and adding one
+ * from a pasted address.
+ */
+export class Feeds extends MithrilComponent {
+    s = local<{feeds: FeedListed[] | null; adding: boolean; busy: string; confirming: string}>({
+        adding: false,
+        busy: '',
+        confirming: '',
+        feeds: null,
+    })
+
+    async load() {
+        this.s.feeds = (await loadFeeds()) ?? []
+    }
+
+    oninit() {
+        void this.load()
+    }
+
+    view() {
+        const s = this.s
+        return (
+            <div class="feeds">
+                <div class="feeds-head">
+                    <span class="feeds-count">{s.feeds === null ? '' : `${s.feeds.length} layers`}</span>
+                    <span class="feeds-spacer" />
+                    {!s.adding && (
+                        <Button
+                            onclick={() => {
+                                s.adding = true
+                            }}
+                            variant="primary"
+                        >
+                            Add a data layer
+                        </Button>
+                    )}
+                </div>
+                <p class="feeds-note">
+                    Records from open data, placed on the map under Layers ▸ Data. Atlas asks the source on each layer's
+                    clock and sends viewers only the parts of the map that changed.
+                </p>
+                {s.adding && (
+                    <NewFeed
+                        onDone={(saved) => {
+                            s.adding = false
+                            if (saved) void this.load()
+                        }}
+                    />
+                )}
+                {s.feeds === null ? (
+                    <p class="feeds-empty">Loading…</p>
+                ) : !s.feeds.length ? (
+                    <p class="feeds-empty">No data layer yet.</p>
+                ) : (
+                    <Card flush>
+                        <ul class="feeds-list">
+                            {s.feeds.map(({def, state}) => (
+                                <li class="feeds-item" key={def.id}>
+                                    <div class="feeds-item__main">
+                                        <span class="feeds-name">{def.name}</span>
+                                        <span class="feeds-group">{def.group}</span>
+                                        {state.error ? <Badge tone="danger">source failed</Badge> : <Badge tone="success">{`${state.placed.toLocaleString()} records`}</Badge>}
+                                        <span class="feeds-spacer" />
+                                        <Button
+                                            disabled={!!s.busy}
+                                            loading={s.busy === def.id}
+                                            onclick={async () => {
+                                                s.busy = def.id
+                                                await refreshFeed(def.id)
+                                                s.busy = ''
+                                                void this.load()
+                                            }}
+                                            size="sm"
+                                            variant="ghost"
+                                        >
+                                            Refresh now
+                                        </Button>
+                                        {s.confirming === def.id ? (
+                                            <Button
+                                                onclick={async () => {
+                                                    s.confirming = ''
+                                                    if (await deleteFeed(def.id)) void this.load()
+                                                }}
+                                                size="sm"
+                                                variant="danger"
+                                            >
+                                                Really delete
+                                            </Button>
+                                        ) : (
+                                            <Button
+                                                onclick={() => {
+                                                    s.confirming = def.id
+                                                }}
+                                                size="sm"
+                                                variant="ghost"
+                                            >
+                                                Delete
+                                            </Button>
+                                        )}
+                                    </div>
+                                    <div class="feeds-meta">
+                                        {def.source.dataset.replace(/^https:\/\//, '')} · {def.source.query} · every{' '}
+                                        {def.refresh_hours} h · asked {when(state.tried_ms)} · changed {when(state.changed_ms)}
+                                    </div>
+                                    {state.error && <div class="feeds-error">{state.error}</div>}
+                                </li>
+                            ))}
+                        </ul>
+                    </Card>
+                )}
+            </div>
+        )
+    }
+}
diff --git a/crates/atlas/web/src/css/app.css b/crates/atlas/web/src/css/app.css
index fb5995a5..3b877be8 100644
--- a/crates/atlas/web/src/css/app.css
+++ b/crates/atlas/web/src/css/app.css
@@ -20,6 +20,7 @@
 @import '../components/pages/content-pages/content-pages.css';
 @import '../components/pages/library/library.css';
 @import '../components/pages/login/login.css';
+@import '../components/pages/feeds/feeds.css';
 @import '../components/pages/overrides/overrides.css';
 @import '../components/pages/pipeline/pipeline.css';
 @import '../components/pages/reports/reports.css';
diff --git a/crates/atlas/web/src/lib/feeds.test.ts b/crates/atlas/web/src/lib/feeds.test.ts
new file mode 100644
index 00000000..b9a63f80
--- /dev/null
+++ b/crates/atlas/web/src/lib/feeds.test.ts
@@ -0,0 +1,39 @@
+import {describe, expect, test} from 'bun:test'
+
+import {colour, PALETTE, project, publisherSlug, slug} from './feeds'
+
+describe('data layers', () => {
+    test('an id is made from a name the way atlas accepts it', () => {
+        expect(slug('Stuwen — Noorderzijlvest')).toBe('stuwen-noorderzijlvest')
+        expect(slug('Wetterskip Fryslân gemalen')).toBe('wetterskip-fryslan-gemalen')
+        expect(slug('x'.repeat(60)).length).toBe(40)
+        expect(publisherSlug('https://www.triplexl.nl/datasets/archixl/hunzeenaas/')).toBe('hunzeenaas')
+    })
+
+    test('a value past the key is other, no colour column is the first colour', () => {
+        expect(colour(-1)).toBe(PALETTE[0])
+        expect(colour(2)).toBe(PALETTE[2])
+        expect(colour(99)).toBe(PALETTE[7])
+    })
+
+    test('the preview keeps north up and fits the box', () => {
+        const pts = project(
+            [
+                [53.3, 6.5, 0],
+                [53.1, 6.7, 1],
+            ],
+            200,
+            100,
+            10,
+        )
+        // North is up: the first point (further north) is higher on the screen.
+        expect(pts[0][1]).toBeLessThan(pts[1][1])
+        for (const [x, y] of pts) {
+            expect(x).toBeGreaterThanOrEqual(10)
+            expect(x).toBeLessThanOrEqual(190)
+            expect(y).toBeGreaterThanOrEqual(10)
+            expect(y).toBeLessThanOrEqual(90)
+        }
+        expect(project([], 10, 10)).toEqual([])
+    })
+})
diff --git a/crates/atlas/web/src/lib/feeds.ts b/crates/atlas/web/src/lib/feeds.ts
new file mode 100644
index 00000000..0e5ddb49
--- /dev/null
+++ b/crates/atlas/web/src/lib/feeds.ts
@@ -0,0 +1,147 @@
+import type {FeedDataset, FeedDef, FeedListed, FeedPreview} from '@/types'
+
+import {api, notifier} from '@/app'
+import {ApiError} from '@/lib/api'
+
+/**
+ * Data layers (`docs/notes/data-layers.md`, `docs/mockups/data-layers/` sheet 2):
+ * records from a source outside Cartopolis that atlas places on the map and keeps
+ * current. TripleXL's saved queries first. A layer is a definition — a source, the
+ * columns that place, title and colour a record, and the ones its card shows —
+ * kept by atlas under `/api/pipeline/feeds`; saving one refreshes it at once.
+ */
+
+/** The colours the app gives a layer's values, in rank order, then "other"
+ *  (`systems::feeds::PALETTE` in the client: keep the two the same). */
+export const PALETTE = ['#5fb3e6', '#f2a33a', '#b48cf0', '#7fc9a0', '#e8893c', '#e5d36a', '#e57aa0', '#9aa7ab']
+
+export function colour(value: number): string {
+    return value < 0 ? PALETTE[0] : PALETTE[Math.min(value, PALETTE.length - 1)]
+}
+
+function report(e: unknown, fallback: string) {
+    if (e instanceof ApiError) {
+        if (!e.isUnauthorized) {
+            notifier.error(e.message)
+        }
+        return
+    }
+    notifier.error(fallback)
+}
+
+/** A layer id from its name and source: lower case, digits and dashes, 40 at most. */
+export function slug(text: string): string {
+    return text
+        .normalize('NFD')
+        .replace(/[̀-ͯ]/g, '')
+        .toLowerCase()
+        .replace(/[^a-z0-9]+/g, '-')
+        .replace(/^-+|-+$/g, '')
+        .slice(0, 40)
+        .replace(/-+$/, '')
+}
+
+/** A short publisher id for the layer id: "Waterschap Noorderzijlvest" → "noorderzijlvest". */
+export function publisherSlug(dataset: string): string {
+    const last = dataset.replace(/\/+$/, '').split('/').pop() ?? ''
+    return slug(last)
+}
+
+/**
+ * The preview's points in a box of `w` × `h`: longitude scaled by the cosine of the
+ * middle latitude, so a square on the ground is square on the screen, fitted with
+ * a margin. Returns `[x, y, value]`.
+ */
+export function project(points: [number, number, number][], w: number, h: number, margin = 12): [number, number, number][] {
+    if (!points.length) {
+        return []
+    }
+    const lats = points.map((p) => p[0])
+    const lngs = points.map((p) => p[1])
+    const [s, n] = [Math.min(...lats), Math.max(...lats)]
+    const [west, east] = [Math.min(...lngs), Math.max(...lngs)]
+    const k = Math.cos((((s + n) / 2) * Math.PI) / 180)
+    const spanX = Math.max((east - west) * k, 1e-6)
+    const spanY = Math.max(n - s, 1e-6)
+    const scale = Math.min((w - 2 * margin) / spanX, (h - 2 * margin) / spanY)
+    const ox = (w - spanX * scale) / 2
+    const oy = (h - spanY * scale) / 2
+    return points.map(([lat, lng, v]) => [ox + (lng - west) * k * scale, oy + (n - lat) * scale, v])
+}
+
+/** When something happened, in words: "28 Nov 2026, 17:42". */
+export function when(ms: number): string {
+    if (!ms) {
+        return 'never'
+    }
+    return new Date(ms).toLocaleString('en-GB', {day: 'numeric', hour: '2-digit', minute: '2-digit', month: 'short', year: 'numeric'})
+}
+
+export async function loadFeeds(): Promise<FeedListed[] | null> {
+    try {
+        const r = await api.get<{feeds: FeedListed[]}>('/api/pipeline/feeds')
+        return r.feeds
+    } catch (e) {
+        report(e, 'Could not load the data layers')
+        return null
+    }
+}
+
+export async function inspect(url: string): Promise<FeedDataset | null> {
+    try {
+        const r = await api.post<{dataset: FeedDataset}>('/api/pipeline/feeds/inspect', {url})
+        return r.dataset
+    } catch (e) {
+        report(e, 'Could not read that dataset')
+        return null
+    }
+}
+
+export async function preview(dataset: string, query: string, colourBy: string): Promise<FeedPreview | null> {
+    try {
+        const r = await api.post<{preview: FeedPreview}>('/api/pipeline/feeds/preview', {
+            colour_by: colourBy,
+            source: {dataset, kind: 'triplexl', query},
+        })
+        return r.preview
+    } catch (e) {
+        report(e, 'Could not ask that query')
+        return null
+    }
+}
+
+/** Save and refresh a layer. The answer says whether the source answered. */
+export async function saveFeed(def: FeedDef): Promise<FeedListed | null> {
+    try {
+        const r = await api.put<{feed: FeedListed | null; error: string | null}>(`/api/pipeline/feeds/${def.id}`, def)
+        if (r.error) {
+            notifier.error(`Saved ${def.name}, but the source did not answer: ${r.error}`)
+        } else if (r.feed) {
+            notifier.success(`Published ${def.name}: ${r.feed.state.placed.toLocaleString()} records on the map`)
+        }
+        return r.feed
+    } catch (e) {
+        report(e, 'Could not save that layer')
+        return null
+    }
+}
+
+export async function refreshFeed(id: string): Promise<boolean> {
+    try {
+        await api.post(`/api/pipeline/feeds/${id}/refresh`, {})
+        return true
+    } catch (e) {
+        report(e, 'Could not refresh that layer')
+        return false
+    }
+}
+
+export async function deleteFeed(id: string): Promise<boolean> {
+    try {
+        await api.delete(`/api/pipeline/feeds/${id}`)
+        return true
+    } catch (e) {
+        report(e, 'Could not delete that layer')
+        return false
+    }
+}
diff --git a/crates/atlas/web/src/lib/roles.ts b/crates/atlas/web/src/lib/roles.ts
index b5da6580..f34cfcca 100644
--- a/crates/atlas/web/src/lib/roles.ts
+++ b/crates/atlas/web/src/lib/roles.ts
@@ -35,6 +35,7 @@ export const TABS: {tab: AdminTab; label: string; needs: string[]}[] = [
     {label: 'Models', needs: ['library_manage'], tab: 'library'},
     {label: 'Pages', needs: ['pages_edit'], tab: 'pages'},
     {label: 'Data', needs: ['pipeline_run'], tab: 'pipeline'},
+    {label: 'Data layers', needs: ['pipeline_run'], tab: 'feeds'},
     {label: 'Overview', needs: ['stats_view'], tab: 'stats'},
     // Not "World" and "Web": the page's own switch already says World.
     {label: 'In the world', needs: ['stats_view'], tab: 'stats_world'},
@@ -57,7 +58,7 @@ export type AdminAreaId = 'people' | 'content' | 'data' | 'stats'
 export const AREAS: {id: AdminAreaId; label: string; hint: string; tabs: AdminTab[]}[] = [
     {hint: 'Accounts, what they may do, who holds which building, and how people sign in', id: 'people', label: 'People', tabs: ['accounts', 'roles', 'claims', 'reports', 'signin']},
     {hint: 'Buildings drawn from a model, the shared model library, and the site\'s pages', id: 'content', label: 'Content', tabs: ['overrides', 'library', 'pages']},
-    {hint: 'The pipelines that build the map', id: 'data', label: 'Data', tabs: ['pipeline']},
+    {hint: 'The pipelines that build the map, and the layers read from open data', id: 'data', label: 'Data', tabs: ['pipeline', 'feeds']},
     {hint: 'How the world is used, and who visits the sites', id: 'stats', label: 'Stats', tabs: ['stats', 'stats_world', 'stats_web', 'stats_places']},
 ]
 
diff --git a/crates/atlas/web/src/types.ts b/crates/atlas/web/src/types.ts
index f85300d0..c2d34b0b 100644
--- a/crates/atlas/web/src/types.ts
+++ b/crates/atlas/web/src/types.ts
@@ -490,6 +490,7 @@ export interface PageSummary {
 }
 
 export type AdminTab =
+    | 'feeds'
     | 'accounts'
     | 'roles'
     | 'claims'
@@ -693,6 +694,60 @@ export interface UserReport {
     subject_username: string
 }
 
+/** A data layer as atlas keeps it (`crates/atlas/src/feeds.rs`, `Def`). */
+export interface FeedDef {
+    id: string
+    name: string
+    group: string
+    source: {kind: 'triplexl'; dataset: string; query: string}
+    geometry: string
+    title: string
+    colour_by: string
+    fields: string[]
+    link: string
+    credit: string
+    licence: string
+    refresh_hours: number
+}
+
+/** What the last refresh of a layer found (`feeds::State`). */
+export interface FeedState {
+    tried_ms: number
+    ok_ms: number
+    changed_ms: number
+    error: string | null
+    rows: number
+    placed: number
+    cells: number
+    values: string[]
+}
+
+export interface FeedListed {
+    def: FeedDef
+    state: FeedState
+}
+
+/** A TripleXL dataset, as `/feeds/inspect` reads it (`feeds::Inspected`). */
+export interface FeedDataset {
+    dataset: string
+    name: string
+    publisher: string
+    licence: string
+    statements: number
+    queries: {name: string; description: string; map: boolean; colour: string; parameters: number}[]
+}
+
+/** What a layer would draw (`feeds::Preview`). */
+export interface FeedPreview {
+    columns: string[]
+    rows: number
+    placed: number
+    geometry: string
+    values: string[]
+    points: [number, number, number][]
+    sample: Record<string, string>[]
+}
+
 export interface AdminState extends Record<string, unknown> {
     accounts: Account[]
     /** The roles each account holds explicitly, by account id. */