GLOBALGRID2050 / EXPLORE CODE

Part of: Explore Code / Maps, GIS and field navigation / gridatlas / atlas/testcode/202609111007

Satellite and 3 more files

A JavaScript file in the testcode folder of GridAtlas that maps survey footprint line, survey boundary case and survey boundary line. Served with the page at https://gridatlas.globalgrid2050.com/atlas/testcode/202609111007/.

681 lines of JavaScript and HTML from gridatlas, in 4 files. Topic: Maps, GIS and field navigation. Section 611 of 2044.

Cut 2026-12-06T03:07:51+00:00. A copy for reading; the repository at the stated commit is the source.

In the State lines below, domain stage, users and canonical status are rule-based first approximations from code and path evidence (rules explore-agent-rules-v1), not observed facts: the rules.

In this section

  1. Satellite render · gridatlas / atlas/testcode/202609111007/satellite.js lines 1–313
  2. Survey UI render · gridatlas / atlas/testcode/202609111007/survey-ui.js lines 1–232
  3. Atlas — V Page render · gridatlas / atlas/v/202609012141/index.html lines 1–103
  4. SatNav Offline Plan Worker ingest · gridatlas / atlas/v/satnav-offline-plan-202611281315-worker.js lines 1–33

Satellite

A JavaScript file in the testcode folder of GridAtlas that maps survey footprint line, survey boundary case and survey boundary line. Served with the page at https://gridatlas.globalgrid2050.com/atlas/testcode/202609111007/.

rendergridatlas / atlas/testcode/202609111007/satellite.js · lines 1–313 of 313 · version 2026-09-11 10:07 · Not reached from any entry point (candidate for review) · pattern validateBoundary (shared by 2 files)

What it does
It maps survey footprint line, survey boundary case and survey boundary line. Defines 36 functions or classes, including finite, visible, say, containsRing, covers. Side effects: changes the web page (DOM); makes network requests.
Why it exists in the grid workflow
Domain stage experimental (path word 'testcode'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow.
Inputs & outputs
In: user-supplied file (file picker); form fields (user input). Coordinate systems named: WGS84 / EPSG:4326.
What it achieves
It updates buttons (`updateButtons`), removes slot (`removeSlot`) and gets catalogue (`getCatalogue`). Satellite-only test cartridge. No project, grid, substation or branding edits. It responds to abort, click and change events.
Why it matters
No other file in the estate was found to import it.
Application
gridatlas · atlas/testcode/202609111007 · script
Uses
none found
Used by
none found
Produces
finite, visible, say, containsRing, covers, sceneText, allowed, json, orderImagery, updateButtons, cancel, basic
Defines here
finite, visible, say, containsRing, covers, sceneText, allowed, json, orderImagery, updateButtons, cancel, basic, removeSlot, awaitTiles, done, abort, data, errorEvent, empty, byId, dateISO, schedulePosition, currentScope, sceneOptions, getCatalogue, paintFootprint, explainScene, showResult, task, sentinel
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 atlas/testcode/202609111007/satellite.js:1-313 · blob 57b9b5a08e312d1db7f9efff17a89f4037b91cd8 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: output · effects: dom, network · domain stage: experimental · users: none · canonical: unreached_review
/* Satellite-only test cartridge. No project, grid, substation or branding edits. */
(() => {
  'use strict';
  const VERSION = '202609111007';
  let catalogue = [], selectionPolicy = 'latest';
  const ROOT = 'https://planetarycomputer.microsoft.com';
  const SOURCE = ['sat-test-s2-0', 'sat-test-s2-1'];
  const LAYER = SOURCE.map(id => id + '-layer');
  const cache = new Map();
  const owners = [null, null];
  let map, panel, status, active = null, mode = 'dark', request = 0, controller;
  const metrics = { searches: 0, tilejson: 0, reused: 0, sourceAdds: 0, tileErrors: 0, loadedTileEvents: 0 };
  const finite = n => typeof n === 'number' && Number.isFinite(n);
  const visible = (id, on) => { if (map.getLayer(id)) map.setLayoutProperty(id, 'visibility', on ? 'visible' : 'none'); };
  const say = text => { if (status.textContent !== text) status.textContent = text; panel.title = text; schedulePosition(); };
  function containsRing(p, ring) {
    let inside = false;
    for (let i = 0, j = ring.length - 1; i < ring.length; j = i++) {
      const a = ring[i], b = ring[j];
      if ((a[1] > p[1]) !== (b[1] > p[1]) && p[0] < (b[0] - a[0]) * (p[1] - a[1]) / (b[1] - a[1]) + a[0]) inside = !inside;
    }
    return inside;
  }
  function covers(item, p) {
    const g = item.geometry;
    const polys = g?.type === 'Polygon' ? [g.coordinates] : g?.type === 'MultiPolygon' ? g.coordinates : [];
    return polys.some(poly => containsRing(p, poly[0]) && !poly.slice(1).some(r => containsRing(p, r)));
  }
  function sceneText(item) {
    const cloud = item.properties['eo:cloud_cover'];
    return 'S2 ' + item.properties.datetime.slice(0, 10) + ' · 10 m · scene cloud ' + (finite(cloud) ? cloud.toFixed(1) + '%' : 'unknown');
  }
  function allowed(url) { const u = new URL(url); if (u.origin !== ROOT) throw Error('Unexpected imagery service'); return u.href; }
  async function json(url, signal) {
    const r = await fetch(allowed(url), { signal });
    if (!r.ok) throw Error('Imagery service HTTP ' + r.status);
    return r.json();
  }
  function orderImagery() {
    // Move only the imagery. Some original engineering overlays arrive before l-sat.
    const style = map.getStyle();
    const anchor = style.layers.find(l => style.sources[l.source]?.type === 'geojson');
    if (!anchor) return;
    for (const id of ['l-sat', ...LAYER]) if (map.getLayer(id)) map.moveLayer(id, anchor.id);
  }
  function updateButtons() {
    for (const [id, value] of [['dark', 'dark'], ['esri', 'esri'], ['s2', 's2']]) {
      document.getElementById('sat-test-' + id).setAttribute('aria-pressed', String(mode === value));
    }
    // Keep the original Dark/Satellite choices truthful; never dispatch their handlers.
    document.querySelectorAll('input[name="bm"],input[name="bm-fs"]').forEach(e => { e.checked = mode !== 's2' && e.value === (mode === 'esri' ? 'sat' : 'dark'); });
  }
  function cancel() { request++; if (controller) controller.abort(); controller = null; }
  function basic(next) {
    cancel(); mode = next;
    LAYER.forEach(id => visible(id, false));
    visible('l-sat', next === 'esri');
    orderImagery(); updateButtons();
    say(next === 'esri' ? 'Esri World Imagery · capture date varies' : 'Dark map | Satellite survey ' + VERSION);
  }
  function removeSlot(slot, owner) {
    if (owner !== undefined && owners[slot] !== owner) return;
    if (map.getLayer(LAYER[slot])) map.removeLayer(LAYER[slot]);
    if (map.getSource(SOURCE[slot])) map.removeSource(SOURCE[slot]);
  }
  function awaitTiles(sourceId, signal) {
    return new Promise((resolve, reject) => {
      let sawTile = false;
      const done = error => { clearTimeout(timer); map.off('sourcedata', data); map.off('error', errorEvent); signal.removeEventListener('abort', abort); error ? reject(error) : resolve(); };
      const abort = () => done(new DOMException('Cancelled', 'AbortError'));
      const data = e => {
        if (e.sourceId !== sourceId) return;
        // MapLibre 3.6 tile-completion events do not set sourceDataType.
        if (e.tile?.state === 'loaded') { sawTile = true; metrics.loadedTileEvents++; }
        if (sawTile && map.isSourceLoaded(sourceId)) done();
      };
      const errorEvent = e => { if (e.sourceId === sourceId) metrics.tileErrors++; };
      const timer = setTimeout(() => done(Error('Tiles took too long; previous map retained. Retry S2.')), 25000);
      map.on('sourcedata', data); map.on('error', errorEvent); signal.addEventListener('abort', abort, { once: true });
    });
  }
  // Survey UI and boundary/date selection. Original GRID/SUBS nodes are not moved.
  let boundary = null, boundaryRevision = 0, catalogueKey = '', catalogueTime = 0;
  const slots = [null, null], comparisons = { A: null, B: null };
  let nativeNodes = [], gridTitle;
  const empty = () => ({ type: 'FeatureCollection', features: [] });
  const byId = id => panel.querySelector('#' + id);
  const dateISO = d => d.toISOString().slice(0, 10);
  function schedulePosition() { if (panel) panel.removeAttribute('title'); }
  function currentScope() {
    const c = map.getCenter();
    const start = byId('survey-start').value, end = byId('survey-end').value;
    if (!/^\d{4}-\d{2}-\d{2}$/.test(start) || !/^\d{4}-\d{2}-\d{2}$/.test(end) || start > end) throw Error('Choose a valid start and end date.');
    if ((Date.parse(end) - Date.parse(start)) / 86400000 > 366) throw Error('Choose a date range of at most one year.');
    return { geometry: boundary?.geometry || { type: 'Point', coordinates: [c.lng, c.lat] },
      key: (boundary ? 'boundary:' + boundaryRevision : c.lng.toFixed(3) + ',' + c.lat.toFixed(3)) + '|' + start + '|' + end,
      start, end };
  }
  function sceneOptions(selected) {
    const select = byId('sat-scene'); select.replaceChildren();
    if (!catalogue.length) { const o = new Option('Load S2 to list capture dates', ''); select.append(o); }
    for (const item of catalogue) {
      const cloud = item.properties['eo:cloud_cover'];
      const text = item.properties.datetime.slice(0, 16).replace('T', ' ') + ' UTC | ' + (finite(cloud) ? cloud.toFixed(1) + '%' : '?') + ' scene cloud';
      select.append(new Option(text, item.id, false, item.id === selected));
    }
    select.disabled = !catalogue.length;
    byId('survey-count').textContent = catalogue.length ? catalogue.length + ' scenes returned. Maximum 100 newest in the selected range; narrow dates to inspect older captures.' : '';
  }
  async function getCatalogue(scope, signal, force) {
    if (!force && scope.key === catalogueKey && Date.now() - catalogueTime < 300000 && catalogue.length) { metrics.reused++; return catalogue; }
    const body = { collections: ['sentinel-2-l2a'], intersects: scope.geometry,
      datetime: scope.start + 'T00:00:00Z/' + scope.end + 'T23:59:59Z',
      sortby: [{ field: 'datetime', direction: 'desc' }], limit: 100 };
    metrics.searches++;
    const r = await fetch(ROOT + '/api/stac/v1/search', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body), signal });
    if (!r.ok) throw Error('Scene catalogue HTTP ' + r.status);
    const found = await r.json(); if (signal.aborted) throw new DOMException('Cancelled', 'AbortError');
    const rows = (found.features || []).filter(f => Number.isFinite(Date.parse(f.properties?.datetime)) && f.assets?.tilejson?.href);
    rows.sort((a, b) => Date.parse(b.properties.datetime) - Date.parse(a.properties.datetime));
    catalogue = rows; catalogueKey = scope.key; catalogueTime = Date.now(); sceneOptions(null);
    return rows;
  }
  function paintFootprint(item) {
    const data = item ? { type: 'FeatureCollection', features: [{ type: 'Feature', properties: {}, geometry: item.geometry }] } : empty();
    if (map.getSource('survey-footprint')) map.getSource('survey-footprint').setData(data);
    else {
      map.addSource('survey-footprint', { type: 'geojson', data });
      map.addLayer({ id: 'survey-footprint-line', type: 'line', source: 'survey-footprint', paint: { 'line-color': '#e6bf64', 'line-width': 1, 'line-dasharray': [4, 3] } });
    }
  }
  function explainScene() {
    if (!active) return;
    say(sceneText(active.item) + ' | Esri outside the scene or in no-data gaps.');
    byId('survey-item').textContent = active.item.id;
    byId('survey-view-date').textContent = active.item.properties.datetime.replace('T', ' ').replace('Z', ' UTC');
  }
  async function showResult(result, token, signal) {
    let stage = slots.findIndex(s => s?.item.id === result.item.id && map.getSource(SOURCE[s.slot]));
    if (stage >= 0) {
      metrics.reused++; active = slots[stage]; mode = 's2';
      visible('l-sat', true); LAYER.forEach((id, i) => visible(id, i === stage));
      map.setPaintProperty(LAYER[stage], 'raster-opacity', 1); orderImagery();
      paintFootprint(active.item); updateButtons(); sceneOptions(active.item.id); explainScene(); return;
    }
    stage = active ? 1 - active.slot : 0; removeSlot(stage); slots[stage] = null; owners[stage] = token;
    try {
      const tj = result.tj;
      map.addSource(SOURCE[stage], { type: 'raster', tiles: tj.tiles, bounds: result.bounds, tileSize: 256,
        minzoom: 6, maxzoom: Math.min(14, finite(tj.maxzoom) ? tj.maxzoom : 14),
        attribution: 'Contains modified Copernicus Sentinel data; Microsoft Planetary Computer' });
      metrics.sourceAdds++;
      const ready = awaitTiles(SOURCE[stage], signal);
      map.addLayer({ id: LAYER[stage], type: 'raster', source: SOURCE[stage], paint: { 'raster-opacity': 0.001, 'raster-opacity-transition': { duration: 180 }, 'raster-fade-duration': 180 } });
      orderImagery(); say('Loading ' + sceneText(result.item) + '; previous map retained.');
      await ready;
      if (signal.aborted || token !== request) { removeSlot(stage, token); return; }
      active = { ...result, slot: stage }; slots[stage] = active; mode = 's2';
      visible('l-sat', true); LAYER.forEach((id, i) => visible(id, i === stage));
      map.setPaintProperty(LAYER[stage], 'raster-opacity', 1); paintFootprint(active.item);
      updateButtons(); sceneOptions(active.item.id); explainScene();
    } catch (error) { if (active?.slot !== stage) removeSlot(stage, token); throw error; }
  }
  async function task(work) {
    cancel(); const token = request, own = new AbortController(); controller = own;
    const timeout = setTimeout(() => own.abort(), 55000);
    panel.setAttribute('aria-busy', 'true');
    try { await work(token, own.signal); }
    catch (e) { if (token === request) say(e.name === 'AbortError' ? 'Image request timed out; previous map retained.' : 'Satellite survey: ' + e.message); }
    finally { clearTimeout(timeout); if (controller === own) { controller = null; panel.setAttribute('aria-busy', 'false'); } }
  }
  async function sentinel(preferredId = null, force = false) {
    if (map.getZoom() < 6) { say('Zoom to a project, or load and fit a boundary, before loading S2.'); return; }
    return task(async (token, signal) => {
      const scope = currentScope(); say('Finding dated scenes intersecting ' + (boundary ? 'the survey boundary' : 'the map centre') + '; previous map retained.');
      const rows = await getCatalogue(scope, signal, force);
      const item = preferredId ? rows.find(f => f.id === preferredId) : selectionPolicy === 'latest' ? rows[0] : (rows.find(f => finite(f.properties['eo:cloud_cover']) && f.properties['eo:cloud_cover'] <= 35) || rows[0]);
      if (!item) throw Error('No available scene in this area and date range.');
      let result = cache.get(item.id);
      if (!result) {
        metrics.tilejson++; const tj = await json(item.assets.tilejson.href, signal);
        if (!Array.isArray(tj.tiles) || !tj.tiles.length) throw Error('Scene has no image tiles.');
        tj.tiles.forEach(allowed); const bounds = tj.bounds || item.bbox;
        if (!Array.isArray(bounds) || bounds.length !== 4 || !bounds.every(finite) || bounds[0] >= bounds[2] || bounds[1] >= bounds[3]) throw Error('Invalid scene footprint.');
        result = { item, tj, bounds, fetched: Date.now() }; cache.set(item.id, result);
        while (cache.size > 8) cache.delete(cache.keys().next().value);
      }
      if (token === request && !signal.aborted) await showResult(result, token, signal);
    });
  }
  function validateBoundary(input) {
    if (input.crs && !/4326|CRS84/.test(JSON.stringify(input.crs))) throw Error('Use WGS84 longitude/latitude GeoJSON.');
    const features = input.type === 'FeatureCollection' ? input.features : [input.type === 'Feature' ? input : { geometry: input }];
    if (!Array.isArray(features) || !features.length || features.length > 100) throw Error('Expected 1–100 polygon features.');
    const polygons = [], points = [];
    for (const f of features) {
      const g = f.geometry; if (!g || !['Polygon', 'MultiPolygon'].includes(g.type)) throw Error('Only Polygon or MultiPolygon boundaries are supported.');
      const ps = g.type === 'Polygon' ? [g.coordinates] : g.coordinates;
      if (!Array.isArray(ps) || !ps.length) throw Error('Empty boundary.');
      for (const poly of ps) {
        if (!Array.isArray(poly) || !poly.length) throw Error('Empty polygon.');
        for (const ring of poly) {
          if (!Array.isArray(ring) || ring.length < 4) throw Error('Polygon rings need at least four coordinates.');
          for (const p of ring) {
            if (!Array.isArray(p) || !finite(p[0]) || !finite(p[1]) || Math.abs(p[0]) > 180 || Math.abs(p[1]) > 85.051) throw Error('Invalid longitude/latitude coordinate.');
            points.push(p); if (points.length > 20000) throw Error('Boundary exceeds 20,000 coordinates.');
          }
          if (ring[0][0] !== ring.at(-1)[0] || ring[0][1] !== ring.at(-1)[1]) throw Error('Close every polygon ring.');
        }
        polygons.push(poly.map(r => r.map(p => p.slice(0, 2))));
      }
    }
    const xs = points.map(p => p[0]), ys = points.map(p => p[1]);
    const bbox = [Math.min(...xs), Math.min(...ys), Math.max(...xs), Math.max(...ys)];
    if (bbox[0] === bbox[2] || bbox[1] === bbox[3] || bbox[2] - bbox[0] > 10 || bbox[3] - bbox[1] > 10) throw Error('Use a non-degenerate local project boundary, at most 10 degrees across.');
    return { geometry: { type: 'MultiPolygon', coordinates: polygons }, bbox, vertices: points.length };
  }
  function setBoundary(input, name) {
    const clean = validateBoundary(input); cancel(); basic('dark');
    boundary = { ...clean, name: String(name).slice(0, 120) }; boundaryRevision++; catalogue = []; catalogueKey = ''; comparisons.A = comparisons.B = null;
    const data = { type: 'FeatureCollection', features: [{ type: 'Feature', properties: {}, geometry: clean.geometry }] };
    if (map.getSource('survey-boundary')) map.getSource('survey-boundary').setData(data);
    else {
      map.addSource('survey-boundary', { type: 'geojson', data });
      map.addLayer({ id: 'survey-boundary-case', type: 'line', source: 'survey-boundary', paint: { 'line-color': '#000000', 'line-width': 4 } });
      map.addLayer({ id: 'survey-boundary-line', type: 'line', source: 'survey-boundary', paint: { 'line-color': '#ffffff', 'line-width': 2 } });
    }
    byId('survey-boundary-name').textContent = boundary.name + ' | ' + clean.vertices + ' coordinates';
    byId('survey-fit').disabled = byId('survey-clear').disabled = false;
    paintFootprint(null); sceneOptions(null); compareLabels(); say('Boundary loaded. Fit boundary, then load dated imagery.');
  }
  function closeGrid() { if (gridTitle.closest('.gm-menu')?.classList.contains('gm-open')) gridTitle.click(); }
  function fitBoundary() {
    if (!boundary) return; closeGrid();
    const b = boundary.bbox; map.fitBounds([[b[0], b[1]], [b[2], b[3]]], { padding: { top: 170, bottom: 100, left: 35, right: 35 }, maxZoom: 15, duration: 0 });
  }
  function compareLabels() {
    for (const key of ['A', 'B']) {
      byId('survey-show-' + key).disabled = !comparisons[key];
      byId('survey-date-' + key).textContent = comparisons[key] ? comparisons[key].item.properties.datetime.slice(0, 10) : 'Not set';
    }
  }
  function install(m) {
    if (panel || !m.getLayer('l-sat')) return false;
    gridTitle = [...document.querySelectorAll('#gridatlas-menu-bar .gm-title')].find(e => e.textContent.trim().toLowerCase() === 'grid');
    const gridPanel = gridTitle?.closest('.gm-menu')?.querySelector('.gm-panel');
    if (!gridPanel) return false;
    map = m; window.__GRIDATLAS_SATELLITE_TEST_MAP__ = map;
    nativeNodes = [...document.querySelectorAll('button')].filter(e => !e.closest('#gridatlas-menu-bar') && /⚡\s*grid|[◉◎]\s*subs/i.test(e.textContent));
    const css = document.createElement('style'); css.id = 'satellite-survey-css'; css.textContent = `
#satellite-survey{display:block;grid-column:1 / -1;margin:8px 4px;padding:6px;border:1px solid #426d73;border-radius:4px;color:#cfe6e8;font:11px/1.4 ui-monospace,monospace;box-sizing:border-box}
#satellite-survey>summary{min-height:44px;display:flex;align-items:center;cursor:pointer;font-weight:bold;color:#7fe3d0;list-style:none}
#satellite-survey>summary::before{content:'▸';margin-right:8px}#satellite-survey[open]>summary::before{content:'▾'}
#satellite-survey .survey-row{display:flex;gap:5px;flex-wrap:wrap;margin:6px 0}
#gridatlas-menu-bar #satellite-survey button{display:flex;width:auto;flex:1 1 65px;min-height:44px;align-items:center;justify-content:center;margin:0;padding:7px;border:1px solid #426d73;border-radius:4px;background:#0d171c;font:600 11px ui-monospace,monospace;color:#bde6e8;box-sizing:border-box;touch-action:manipulation}
#gridatlas-menu-bar #satellite-survey button[aria-pressed=true]{background:#183940;border-color:#00ffff;color:#00ffff}
#satellite-survey button:disabled{opacity:.45;cursor:default}
#satellite-survey label{display:block;margin:7px 0;font:11px/1.5 ui-monospace,monospace;color:#cfe6e8}
#satellite-survey input,#satellite-survey select{position:static;width:100%;min-width:0;min-height:44px;box-sizing:border-box;background:#0d171c;border:1px solid #426d73;border-radius:3px;color:#cfe6e8;font:11px ui-monospace,monospace;padding:5px;opacity:1;margin:4px 0 0}
#satellite-survey input[type=file]{font-size:10px}#satellite-survey .survey-row label{flex:1 1 100px;min-width:0}
#satellite-survey p{font:10px/1.45 ui-monospace,monospace;overflow-wrap:anywhere;margin:6px 0;color:#a6c0c6}
#satellite-survey #sat-test-status{color:#cfe6e8;white-space:normal}
#satellite-survey :focus-visible{outline:2px solid #7fe3d0;outline-offset:1px}
`;
    document.head.append(css); panel = document.createElement('details'); panel.id = 'satellite-survey';
    panel.innerHTML = `<summary>Satellite survey</summary><p>Dated imagery for domestic and public-interest study of renewable projects. No project status is inferred.</p>
<div class="survey-row"><button id="sat-test-dark" type="button">DARK</button><button id="sat-test-esri" type="button">ESRI</button><button id="sat-test-s2" type="button">SENTINEL-2</button></div>
<p id="sat-test-status" role="status" aria-live="polite"></p><p id="survey-view-date"></p><p id="survey-item"></p>
<details><summary>Project boundary</summary><p>WGS84 polygon GeoJSON, up to 1 MB. Files are read in this browser; only geometry is sent to the imagery catalogue when loading S2.</p><label>Boundary file<input id="survey-file" type="file" accept=".geojson,.json,application/geo+json,application/json"></label><p id="survey-boundary-name">No boundary: survey uses map centre.</p><div class="survey-row">  … [line shortened here: 547 characters; full line on GitHub]
<div class="survey-row"><label>From (UTC)<input id="survey-start" type="date"></label><label>To (UTC)<input id="survey-end" type="date"></label></div>
<label>Selection<select id="sat-policy"><option value="latest">Newest acquisition (may be cloudy)</option><option value="clear">Newest with ≤35% scene cloud</option></select></label>
<label>Capture date<select id="sat-scene" disabled><option>Load S2 to list capture dates</option></select></label><p id="survey-count"></p>
<div class="survey-row"><button id="survey-refresh" type="button">REFRESH DATES</button><button id="survey-view" type="button">VIEW MAP</button></div>
<details><summary>Compare two dates</summary><p>Load a capture and set A, then load another and set B. Show A/B switches actual imagery at the same map position; it does not classify changes.</p><div class="survey-row"><button id="survey-set-A" type="button">SET A</button><button id="survey-show-A" type="button" disabled>SHOW A</button></div><p id="survey-date-A">Not set</p><div class="survey-row"  … [line shortened here: 569 characters; full line on GitHub]
<p>Sentinel-2 RGB: 10 m. Cloud percentage describes the whole scene, not this site. White outline: supplied boundary. Gold dashed outline: scene footprint. Esri remains outside the scene and in no-data gaps; its capture date varies. A lack of visible change is not proof of no activity.</p>`;
    // Insert one section inside Grid; no floating controls or native-node reparenting.
    gridPanel.insertBefore(panel, gridPanel.firstChild); status = byId('sat-test-status');
    const now = new Date(); byId('survey-end').value = dateISO(now); byId('survey-start').value = dateISO(new Date(now.getTime() - 60 * 86400000));
    panel.addEventListener('click', e => {
      e.stopPropagation(); const id = e.target.closest('button')?.id;
      if (id === 'sat-test-s2') sentinel(); else if (id === 'sat-test-esri') { basic('esri'); paintFootprint(null); } else if (id === 'sat-test-dark') { basic('dark'); paintFootprint(null); }
      else if (id === 'survey-refresh') sentinel(null, true); else if (id === 'survey-view') closeGrid(); else if (id === 'survey-fit') fitBoundary();
      else if (id === 'survey-clear') {
        cancel(); boundary = null; boundaryRevision++; catalogue = []; catalogueKey = ''; comparisons.A = comparisons.B = null; basic('dark');
        map.getSource('survey-boundary')?.setData(empty()); paintFootprint(null); byId('survey-boundary-name').textContent = 'No boundary: survey uses map centre.';
        byId('survey-fit').disabled = byId('survey-clear').disabled = true; sceneOptions(null); compareLabels();
      } else if (id?.startsWith('survey-set-')) {
        if (mode !== 's2' || !active) { say('Load a Sentinel-2 capture before setting a comparison.'); return; }
        comparisons[id.at(-1)] = { ...active }; compareLabels();
      } else if (id?.startsWith('survey-show-')) {
        const saved = comparisons[id.at(-1)]; if (saved) task((token, signal) => showResult(saved, token, signal));
      }
    });
    panel.addEventListener('change', async e => {
      e.stopPropagation();
      if (e.target.id === 'survey-file') {
        const f = e.target.files?.[0]; if (!f) return;
        try { if (f.size > 1048576) throw Error('Boundary file exceeds 1 MB.'); setBoundary(JSON.parse(await f.text()), f.name); }
        catch (err) { say('Boundary: ' + err.message); } finally { e.target.value = ''; }
      } else if (e.target.id === 'sat-policy') { selectionPolicy = e.target.value; sentinel(null, false); }
      else if (e.target.id === 'sat-scene' && e.target.value) sentinel(e.target.value);
      else if (e.target.id === 'survey-start' || e.target.id === 'survey-end') { cancel(); catalogueKey = ''; catalogue = []; sceneOptions(null); say('Date range changed. Refresh dates to load this range.'); }
    });
    for (const event of ['pointerdown', 'touchstart', 'dblclick', 'wheel']) panel.addEventListener(event, e => e.stopPropagation(), { passive: true });
    document.addEventListener('change', e => { if (e.target.name === 'bm' || e.target.name === 'bm-fs') { basic(e.target.value === 'sat' ? 'esri' : 'dark'); paintFootprint(null); } });
    map.on('moveend', () => { if (mode === 's2' && active) { const c = map.getCenter(); if (!covers(active.item, [c.lng, c.lat])) say('Outside selected scene at map centre: Esri shown. Open Grid > Satellite survey to choose imagery here.'); else explainScene(); } });
    window.__GRIDATLAS_SATELLITE_TEST__ = { snapshot: () => ({ version: VERSION, mode, scene: active?.item.id || null, date: active?.item.properties.datetime || null,
      scenes: catalogue.length, boundary: boundary ? { name: boundary.name, bbox: boundary.bbox, vertices: boundary.vertices } : null,
      menuOnly: panel.closest('.gm-panel') !== null, nativeNodesUnmoved: nativeNodes.every(n => n.isConnected && !panel.contains(n)), comparisonA: comparisons.A?.item.id || null, comparisonB: comparisons.B?.item.id || null, ...metrics }) };
    updateButtons(); say('Open Grid > Satellite survey to inspect dated imagery.'); return true;
  }
  let attempts = 0; const timer = setInterval(() => { const m = window.__GRIDATLAS_V9_MAP__; if (m?.getLayer('l-sat') && install(m)) clearInterval(timer); else if (++attempts >= 240) clearInterval(timer); }, 250);
})();

Survey UI

A JavaScript file in the testcode folder of GridAtlas that maps survey footprint line, survey boundary case and survey boundary line. Served with the page at https://gridatlas.globalgrid2050.com/atlas/testcode/202609111007/.

rendergridatlas / atlas/testcode/202609111007/survey-ui.js · lines 1–232 of 232 · version 2026-09-11 10:07 · Not reached from any entry point (candidate for review) · pattern validateBoundary (shared by 2 files)

What it does
It maps survey footprint line, survey boundary case and survey boundary line. Defines 18 functions or classes, including empty, byId, dateISO, schedulePosition, currentScope. Side effects: changes the web page (DOM); makes network requests.
Why it exists in the grid workflow
Domain stage experimental (path word 'testcode'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow.
Inputs & outputs
In: user-supplied file (file picker); form fields (user input). Coordinate systems named: WGS84 / EPSG:4326.
What it achieves
It gets catalogue (`getCatalogue`), paints footprint (`paintFootprint`) and explains scene (`explainScene`). Survey UI and boundary/date selection. Original GRID/SUBS nodes are not moved. It responds to click and change events.
Why it matters
No other file in the estate was found to import it.
Application
gridatlas · atlas/testcode/202609111007 · script
Uses
none found
Used by
none found
Produces
empty, byId, dateISO, schedulePosition, currentScope, sceneOptions, getCatalogue, paintFootprint, explainScene, showResult, task, sentinel
Defines here
empty, byId, dateISO, schedulePosition, currentScope, sceneOptions, getCatalogue, paintFootprint, explainScene, showResult, task, sentinel, validateBoundary, setBoundary, closeGrid, fitBoundary, compareLabels, install
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 atlas/testcode/202609111007/survey-ui.js:1-232 · blob a62432f830284999ecaaa2650ffc2f6f0a6eaae0 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: output · effects: dom, network · domain stage: experimental · users: none · canonical: unreached_review
  // Survey UI and boundary/date selection. Original GRID/SUBS nodes are not moved.
  let boundary = null, boundaryRevision = 0, catalogueKey = '', catalogueTime = 0;
  const slots = [null, null], comparisons = { A: null, B: null };
  let nativeNodes = [], gridTitle;
  const empty = () => ({ type: 'FeatureCollection', features: [] });
  const byId = id => panel.querySelector('#' + id);
  const dateISO = d => d.toISOString().slice(0, 10);
  function schedulePosition() { if (panel) panel.removeAttribute('title'); }
  function currentScope() {
    const c = map.getCenter();
    const start = byId('survey-start').value, end = byId('survey-end').value;
    if (!/^\d{4}-\d{2}-\d{2}$/.test(start) || !/^\d{4}-\d{2}-\d{2}$/.test(end) || start > end) throw Error('Choose a valid start and end date.');
    if ((Date.parse(end) - Date.parse(start)) / 86400000 > 366) throw Error('Choose a date range of at most one year.');
    return { geometry: boundary?.geometry || { type: 'Point', coordinates: [c.lng, c.lat] },
      key: (boundary ? 'boundary:' + boundaryRevision : c.lng.toFixed(3) + ',' + c.lat.toFixed(3)) + '|' + start + '|' + end,
      start, end };
  }
  function sceneOptions(selected) {
    const select = byId('sat-scene'); select.replaceChildren();
    if (!catalogue.length) { const o = new Option('Load S2 to list capture dates', ''); select.append(o); }
    for (const item of catalogue) {
      const cloud = item.properties['eo:cloud_cover'];
      const text = item.properties.datetime.slice(0, 16).replace('T', ' ') + ' UTC | ' + (finite(cloud) ? cloud.toFixed(1) + '%' : '?') + ' scene cloud';
      select.append(new Option(text, item.id, false, item.id === selected));
    }
    select.disabled = !catalogue.length;
    byId('survey-count').textContent = catalogue.length ? catalogue.length + ' scenes returned. Maximum 100 newest in the selected range; narrow dates to inspect older captures.' : '';
  }
  async function getCatalogue(scope, signal, force) {
    if (!force && scope.key === catalogueKey && Date.now() - catalogueTime < 300000 && catalogue.length) { metrics.reused++; return catalogue; }
    const body = { collections: ['sentinel-2-l2a'], intersects: scope.geometry,
      datetime: scope.start + 'T00:00:00Z/' + scope.end + 'T23:59:59Z',
      sortby: [{ field: 'datetime', direction: 'desc' }], limit: 100 };
    metrics.searches++;
    const r = await fetch(ROOT + '/api/stac/v1/search', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body), signal });
    if (!r.ok) throw Error('Scene catalogue HTTP ' + r.status);
    const found = await r.json(); if (signal.aborted) throw new DOMException('Cancelled', 'AbortError');
    const rows = (found.features || []).filter(f => Number.isFinite(Date.parse(f.properties?.datetime)) && f.assets?.tilejson?.href);
    rows.sort((a, b) => Date.parse(b.properties.datetime) - Date.parse(a.properties.datetime));
    catalogue = rows; catalogueKey = scope.key; catalogueTime = Date.now(); sceneOptions(null);
    return rows;
  }
  function paintFootprint(item) {
    const data = item ? { type: 'FeatureCollection', features: [{ type: 'Feature', properties: {}, geometry: item.geometry }] } : empty();
    if (map.getSource('survey-footprint')) map.getSource('survey-footprint').setData(data);
    else {
      map.addSource('survey-footprint', { type: 'geojson', data });
      map.addLayer({ id: 'survey-footprint-line', type: 'line', source: 'survey-footprint', paint: { 'line-color': '#e6bf64', 'line-width': 1, 'line-dasharray': [4, 3] } });
    }
  }
  function explainScene() {
    if (!active) return;
    say(sceneText(active.item) + ' | Esri outside the scene or in no-data gaps.');
    byId('survey-item').textContent = active.item.id;
    byId('survey-view-date').textContent = active.item.properties.datetime.replace('T', ' ').replace('Z', ' UTC');
  }
  async function showResult(result, token, signal) {
    let stage = slots.findIndex(s => s?.item.id === result.item.id && map.getSource(SOURCE[s.slot]));
    if (stage >= 0) {
      metrics.reused++; active = slots[stage]; mode = 's2';
      visible('l-sat', true); LAYER.forEach((id, i) => visible(id, i === stage));
      map.setPaintProperty(LAYER[stage], 'raster-opacity', 1); orderImagery();
      paintFootprint(active.item); updateButtons(); sceneOptions(active.item.id); explainScene(); return;
    }
    stage = active ? 1 - active.slot : 0; removeSlot(stage); slots[stage] = null; owners[stage] = token;
    try {
      const tj = result.tj;
      map.addSource(SOURCE[stage], { type: 'raster', tiles: tj.tiles, bounds: result.bounds, tileSize: 256,
        minzoom: 6, maxzoom: Math.min(14, finite(tj.maxzoom) ? tj.maxzoom : 14),
        attribution: 'Contains modified Copernicus Sentinel data; Microsoft Planetary Computer' });
      metrics.sourceAdds++;
      const ready = awaitTiles(SOURCE[stage], signal);
      map.addLayer({ id: LAYER[stage], type: 'raster', source: SOURCE[stage], paint: { 'raster-opacity': 0.001, 'raster-opacity-transition': { duration: 180 }, 'raster-fade-duration': 180 } });
      orderImagery(); say('Loading ' + sceneText(result.item) + '; previous map retained.');
      await ready;
      if (signal.aborted || token !== request) { removeSlot(stage, token); return; }
      active = { ...result, slot: stage }; slots[stage] = active; mode = 's2';
      visible('l-sat', true); LAYER.forEach((id, i) => visible(id, i === stage));
      map.setPaintProperty(LAYER[stage], 'raster-opacity', 1); paintFootprint(active.item);
      updateButtons(); sceneOptions(active.item.id); explainScene();
    } catch (error) { if (active?.slot !== stage) removeSlot(stage, token); throw error; }
  }
  async function task(work) {
    cancel(); const token = request, own = new AbortController(); controller = own;
    const timeout = setTimeout(() => own.abort(), 55000);
    panel.setAttribute('aria-busy', 'true');
    try { await work(token, own.signal); }
    catch (e) { if (token === request) say(e.name === 'AbortError' ? 'Image request timed out; previous map retained.' : 'Satellite survey: ' + e.message); }
    finally { clearTimeout(timeout); if (controller === own) { controller = null; panel.setAttribute('aria-busy', 'false'); } }
  }
  async function sentinel(preferredId = null, force = false) {
    if (map.getZoom() < 6) { say('Zoom to a project, or load and fit a boundary, before loading S2.'); return; }
    return task(async (token, signal) => {
      const scope = currentScope(); say('Finding dated scenes intersecting ' + (boundary ? 'the survey boundary' : 'the map centre') + '; previous map retained.');
      const rows = await getCatalogue(scope, signal, force);
      const item = preferredId ? rows.find(f => f.id === preferredId) : selectionPolicy === 'latest' ? rows[0] : (rows.find(f => finite(f.properties['eo:cloud_cover']) && f.properties['eo:cloud_cover'] <= 35) || rows[0]);
      if (!item) throw Error('No available scene in this area and date range.');
      let result = cache.get(item.id);
      if (!result) {
        metrics.tilejson++; const tj = await json(item.assets.tilejson.href, signal);
        if (!Array.isArray(tj.tiles) || !tj.tiles.length) throw Error('Scene has no image tiles.');
        tj.tiles.forEach(allowed); const bounds = tj.bounds || item.bbox;
        if (!Array.isArray(bounds) || bounds.length !== 4 || !bounds.every(finite) || bounds[0] >= bounds[2] || bounds[1] >= bounds[3]) throw Error('Invalid scene footprint.');
        result = { item, tj, bounds, fetched: Date.now() }; cache.set(item.id, result);
        while (cache.size > 8) cache.delete(cache.keys().next().value);
      }
      if (token === request && !signal.aborted) await showResult(result, token, signal);
    });
  }
  function validateBoundary(input) {
    if (input.crs && !/4326|CRS84/.test(JSON.stringify(input.crs))) throw Error('Use WGS84 longitude/latitude GeoJSON.');
    const features = input.type === 'FeatureCollection' ? input.features : [input.type === 'Feature' ? input : { geometry: input }];
    if (!Array.isArray(features) || !features.length || features.length > 100) throw Error('Expected 1–100 polygon features.');
    const polygons = [], points = [];
    for (const f of features) {
      const g = f.geometry; if (!g || !['Polygon', 'MultiPolygon'].includes(g.type)) throw Error('Only Polygon or MultiPolygon boundaries are supported.');
      const ps = g.type === 'Polygon' ? [g.coordinates] : g.coordinates;
      if (!Array.isArray(ps) || !ps.length) throw Error('Empty boundary.');
      for (const poly of ps) {
        if (!Array.isArray(poly) || !poly.length) throw Error('Empty polygon.');
        for (const ring of poly) {
          if (!Array.isArray(ring) || ring.length < 4) throw Error('Polygon rings need at least four coordinates.');
          for (const p of ring) {
            if (!Array.isArray(p) || !finite(p[0]) || !finite(p[1]) || Math.abs(p[0]) > 180 || Math.abs(p[1]) > 85.051) throw Error('Invalid longitude/latitude coordinate.');
            points.push(p); if (points.length > 20000) throw Error('Boundary exceeds 20,000 coordinates.');
          }
          if (ring[0][0] !== ring.at(-1)[0] || ring[0][1] !== ring.at(-1)[1]) throw Error('Close every polygon ring.');
        }
        polygons.push(poly.map(r => r.map(p => p.slice(0, 2))));
      }
    }
    const xs = points.map(p => p[0]), ys = points.map(p => p[1]);
    const bbox = [Math.min(...xs), Math.min(...ys), Math.max(...xs), Math.max(...ys)];
    if (bbox[0] === bbox[2] || bbox[1] === bbox[3] || bbox[2] - bbox[0] > 10 || bbox[3] - bbox[1] > 10) throw Error('Use a non-degenerate local project boundary, at most 10 degrees across.');
    return { geometry: { type: 'MultiPolygon', coordinates: polygons }, bbox, vertices: points.length };
  }
  function setBoundary(input, name) {
    const clean = validateBoundary(input); cancel(); basic('dark');
    boundary = { ...clean, name: String(name).slice(0, 120) }; boundaryRevision++; catalogue = []; catalogueKey = ''; comparisons.A = comparisons.B = null;
    const data = { type: 'FeatureCollection', features: [{ type: 'Feature', properties: {}, geometry: clean.geometry }] };
    if (map.getSource('survey-boundary')) map.getSource('survey-boundary').setData(data);
    else {
      map.addSource('survey-boundary', { type: 'geojson', data });
      map.addLayer({ id: 'survey-boundary-case', type: 'line', source: 'survey-boundary', paint: { 'line-color': '#000000', 'line-width': 4 } });
      map.addLayer({ id: 'survey-boundary-line', type: 'line', source: 'survey-boundary', paint: { 'line-color': '#ffffff', 'line-width': 2 } });
    }
    byId('survey-boundary-name').textContent = boundary.name + ' | ' + clean.vertices + ' coordinates';
    byId('survey-fit').disabled = byId('survey-clear').disabled = false;
    paintFootprint(null); sceneOptions(null); compareLabels(); say('Boundary loaded. Fit boundary, then load dated imagery.');
  }
  function closeGrid() { if (gridTitle.closest('.gm-menu')?.classList.contains('gm-open')) gridTitle.click(); }
  function fitBoundary() {
    if (!boundary) return; closeGrid();
    const b = boundary.bbox; map.fitBounds([[b[0], b[1]], [b[2], b[3]]], { padding: { top: 170, bottom: 100, left: 35, right: 35 }, maxZoom: 15, duration: 0 });
  }
  function compareLabels() {
    for (const key of ['A', 'B']) {
      byId('survey-show-' + key).disabled = !comparisons[key];
      byId('survey-date-' + key).textContent = comparisons[key] ? comparisons[key].item.properties.datetime.slice(0, 10) : 'Not set';
    }
  }
  function install(m) {
    if (panel || !m.getLayer('l-sat')) return false;
    gridTitle = [...document.querySelectorAll('#gridatlas-menu-bar .gm-title')].find(e => e.textContent.trim().toLowerCase() === 'grid');
    const gridPanel = gridTitle?.closest('.gm-menu')?.querySelector('.gm-panel');
    if (!gridPanel) return false;
    map = m; window.__GRIDATLAS_SATELLITE_TEST_MAP__ = map;
    nativeNodes = [...document.querySelectorAll('button')].filter(e => !e.closest('#gridatlas-menu-bar') && /⚡\s*grid|[◉◎]\s*subs/i.test(e.textContent));
    const css = document.createElement('style'); css.id = 'satellite-survey-css'; css.textContent = `
#satellite-survey{display:block;grid-column:1 / -1;margin:8px 4px;padding:6px;border:1px solid #426d73;border-radius:4px;color:#cfe6e8;font:11px/1.4 ui-monospace,monospace;box-sizing:border-box}
#satellite-survey>summary{min-height:44px;display:flex;align-items:center;cursor:pointer;font-weight:bold;color:#7fe3d0;list-style:none}
#satellite-survey>summary::before{content:'▸';margin-right:8px}#satellite-survey[open]>summary::before{content:'▾'}
#satellite-survey .survey-row{display:flex;gap:5px;flex-wrap:wrap;margin:6px 0}
#gridatlas-menu-bar #satellite-survey button{display:flex;width:auto;flex:1 1 65px;min-height:44px;align-items:center;justify-content:center;margin:0;padding:7px;border:1px solid #426d73;border-radius:4px;background:#0d171c;font:600 11px ui-monospace,monospace;color:#bde6e8;box-sizing:border-box;touch-action:manipulation}
#gridatlas-menu-bar #satellite-survey button[aria-pressed=true]{background:#183940;border-color:#00ffff;color:#00ffff}
#satellite-survey button:disabled{opacity:.45;cursor:default}
#satellite-survey label{display:block;margin:7px 0;font:11px/1.5 ui-monospace,monospace;color:#cfe6e8}
#satellite-survey input,#satellite-survey select{position:static;width:100%;min-width:0;min-height:44px;box-sizing:border-box;background:#0d171c;border:1px solid #426d73;border-radius:3px;color:#cfe6e8;font:11px ui-monospace,monospace;padding:5px;opacity:1;margin:4px 0 0}
#satellite-survey input[type=file]{font-size:10px}#satellite-survey .survey-row label{flex:1 1 100px;min-width:0}
#satellite-survey p{font:10px/1.45 ui-monospace,monospace;overflow-wrap:anywhere;margin:6px 0;color:#a6c0c6}
#satellite-survey #sat-test-status{color:#cfe6e8;white-space:normal}
#satellite-survey :focus-visible{outline:2px solid #7fe3d0;outline-offset:1px}
`;
    document.head.append(css); panel = document.createElement('details'); panel.id = 'satellite-survey';
    panel.innerHTML = `<summary>Satellite survey</summary><p>Dated imagery for domestic and public-interest study of renewable projects. No project status is inferred.</p>
<div class="survey-row"><button id="sat-test-dark" type="button">DARK</button><button id="sat-test-esri" type="button">ESRI</button><button id="sat-test-s2" type="button">SENTINEL-2</button></div>
<p id="sat-test-status" role="status" aria-live="polite"></p><p id="survey-view-date"></p><p id="survey-item"></p>
<details><summary>Project boundary</summary><p>WGS84 polygon GeoJSON, up to 1 MB. Files are read in this browser; only geometry is sent to the imagery catalogue when loading S2.</p><label>Boundary file<input id="survey-file" type="file" accept=".geojson,.json,application/geo+json,application/json"></label><p id="survey-boundary-name">No boundary: survey uses map centre.</p><div class="survey-row">  … [line shortened here: 547 characters; full line on GitHub]
<div class="survey-row"><label>From (UTC)<input id="survey-start" type="date"></label><label>To (UTC)<input id="survey-end" type="date"></label></div>
<label>Selection<select id="sat-policy"><option value="latest">Newest acquisition (may be cloudy)</option><option value="clear">Newest with ≤35% scene cloud</option></select></label>
<label>Capture date<select id="sat-scene" disabled><option>Load S2 to list capture dates</option></select></label><p id="survey-count"></p>
<div class="survey-row"><button id="survey-refresh" type="button">REFRESH DATES</button><button id="survey-view" type="button">VIEW MAP</button></div>
<details><summary>Compare two dates</summary><p>Load a capture and set A, then load another and set B. Show A/B switches actual imagery at the same map position; it does not classify changes.</p><div class="survey-row"><button id="survey-set-A" type="button">SET A</button><button id="survey-show-A" type="button" disabled>SHOW A</button></div><p id="survey-date-A">Not set</p><div class="survey-row"  … [line shortened here: 569 characters; full line on GitHub]
<p>Sentinel-2 RGB: 10 m. Cloud percentage describes the whole scene, not this site. White outline: supplied boundary. Gold dashed outline: scene footprint. Esri remains outside the scene and in no-data gaps; its capture date varies. A lack of visible change is not proof of no activity.</p>`;
    // Insert one section inside Grid; no floating controls or native-node reparenting.
    gridPanel.insertBefore(panel, gridPanel.firstChild); status = byId('sat-test-status');
    const now = new Date(); byId('survey-end').value = dateISO(now); byId('survey-start').value = dateISO(new Date(now.getTime() - 60 * 86400000));
    panel.addEventListener('click', e => {
      e.stopPropagation(); const id = e.target.closest('button')?.id;
      if (id === 'sat-test-s2') sentinel(); else if (id === 'sat-test-esri') { basic('esri'); paintFootprint(null); } else if (id === 'sat-test-dark') { basic('dark'); paintFootprint(null); }
      else if (id === 'survey-refresh') sentinel(null, true); else if (id === 'survey-view') closeGrid(); else if (id === 'survey-fit') fitBoundary();
      else if (id === 'survey-clear') {
        cancel(); boundary = null; boundaryRevision++; catalogue = []; catalogueKey = ''; comparisons.A = comparisons.B = null; basic('dark');
        map.getSource('survey-boundary')?.setData(empty()); paintFootprint(null); byId('survey-boundary-name').textContent = 'No boundary: survey uses map centre.';
        byId('survey-fit').disabled = byId('survey-clear').disabled = true; sceneOptions(null); compareLabels();
      } else if (id?.startsWith('survey-set-')) {
        if (mode !== 's2' || !active) { say('Load a Sentinel-2 capture before setting a comparison.'); return; }
        comparisons[id.at(-1)] = { ...active }; compareLabels();
      } else if (id?.startsWith('survey-show-')) {
        const saved = comparisons[id.at(-1)]; if (saved) task((token, signal) => showResult(saved, token, signal));
      }
    });
    panel.addEventListener('change', async e => {
      e.stopPropagation();
      if (e.target.id === 'survey-file') {
        const f = e.target.files?.[0]; if (!f) return;
        try { if (f.size > 1048576) throw Error('Boundary file exceeds 1 MB.'); setBoundary(JSON.parse(await f.text()), f.name); }
        catch (err) { say('Boundary: ' + err.message); } finally { e.target.value = ''; }
      } else if (e.target.id === 'sat-policy') { selectionPolicy = e.target.value; sentinel(null, false); }
      else if (e.target.id === 'sat-scene' && e.target.value) sentinel(e.target.value);
      else if (e.target.id === 'survey-start' || e.target.id === 'survey-end') { cancel(); catalogueKey = ''; catalogue = []; sceneOptions(null); say('Date range changed. Refresh dates to load this range.'); }
    });
    for (const event of ['pointerdown', 'touchstart', 'dblclick', 'wheel']) panel.addEventListener(event, e => e.stopPropagation(), { passive: true });
    document.addEventListener('change', e => { if (e.target.name === 'bm' || e.target.name === 'bm-fs') { basic(e.target.value === 'sat' ? 'esri' : 'dark'); paintFootprint(null); } });
    map.on('moveend', () => { if (mode === 's2' && active) { const c = map.getCenter(); if (!covers(active.item, [c.lng, c.lat])) say('Outside selected scene at map centre: Esri shown. Open Grid > Satellite survey to choose imagery here.'); else explainScene(); } });
    window.__GRIDATLAS_SATELLITE_TEST__ = { snapshot: () => ({ version: VERSION, mode, scene: active?.item.id || null, date: active?.item.properties.datetime || null,
      scenes: catalogue.length, boundary: boundary ? { name: boundary.name, bbox: boundary.bbox, vertices: boundary.vertices } : null,
      menuOnly: panel.closest('.gm-panel') !== null, nativeNodesUnmoved: nativeNodes.every(n => n.isConnected && !panel.contains(n)), comparisonA: comparisons.A?.item.id || null, comparisonB: comparisons.B?.item.id || null, ...metrics }) };
    updateButtons(); say('Open Grid > Satellite survey to inspect dated imagery.'); return true;
  }
  let attempts = 0; const timer = setInterval(() => { const m = window.__GRIDATLAS_V9_MAP__; if (m?.getLayer('l-sat') && install(m)) clearInterval(timer); else if (++attempts >= 240) clearInterval(timer); }, 250);
})();

Atlas — V Page

A web page in GridAtlas that works with escape attribute (`escapeAttribute`) and sha256 hex (`sha256Hex`), using SHA-256. Published at https://gridatlas.globalgrid2050.com/atlas/v/202609012141/.

Set aside from the main view: 91% of its lines are the same as sandbox/202609060459/atlas/index.html (testcode), which stays. (near-copy-of, proposed by families.py). 91% of lines shared with Sandbox — Atlas Page; read that one first. All set-aside files, with reasons. Nothing was deleted.

Evidence
  • line-jaccard 0.9111 to testcode@a8a215982b13d6e2f6019b40bf0bef5755719773 sandbox/202609060459/atlas/index.html:1-108 4877bbedc7da9f84cb4fad8f72e5499ccf8ea55a
  • sha256 e1e403f6defe984e6a12c30bb882dfeb65166b5414e3088c3b04f957064232b3
  • target sha256 0a6e82d1a72225649c59cec2821b45dc4297f897ca1b2652b5c3ff2bae4d9d2e
  • group of 2 (identity.json near-copy edges >= 0.9)
  • canonical rule: reachable, newest stamp, core repo, most lines

rendergridatlas / atlas/v/202609012141/index.html · lines 1–103 of 103 · version 2026-09-01 21:41 · Entry point · pattern escapeAttribute (shared by 6 files)

What it does
It draws its content. Defines invariant, escapeAttribute, sha256Hex, fail. Uses libraries ${escapeAttribute(blobUrl)}. Side effects: changes the web page (DOM); makes network requests.
Why it exists in the grid workflow
Domain stage upstream_foresight (path word 'atlas'): upstream engineering foresight over GB transmission and distribution topology (TSO/DNO, 132kV and above, the REPD pipeline, data centres), which Ventus Ltd states it models for foresight. README: "`atlas/index.html` is the stable composer."
Inputs & outputs
In: JSON file current.json. Out: web page.
Downstream impact
It is itself an entry point, published at https://gridatlas.globalgrid2050.com/atlas/v/202609012141/.
What it achieves
It is built from the invariant step (`invariant`), the escape attribute helper (`escapeAttribute`) and the sha256 hex helper (`sha256Hex`). The README says: `atlas/index.html` is the stable composer. It reads `./current.json`.
Why it matters
No other file in the estate was found to import it; it is an entry point.
Application
gridatlas · atlas/v/202609012141 · page
Uses
${escapeAttribute(blobUrl)}
Used by
none found
Produces
invariant, escapeAttribute, sha256Hex, fail
Defines here
invariant, escapeAttribute, sha256Hex, fail
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 atlas/v/202609012141/index.html:1-103 · blob 3677697d929ad2bec94da9f3c4bd6ef618f3c8e8 · GitHub at these lines
State
achieves: readme · context: readme_derived · stage: output · effects: dom, network · domain stage: upstream_foresight · users: IPP_developer, ICP_grid_engineer · canonical: production_core
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width,initial-scale=1">
  <title>Grid Atlas</title>
  <style>
    html,body{height:100%;margin:0;background:#000;color:#00ffff;font:13px monospace}
    #gridatlas-loader{display:grid;place-items:center;height:100%;padding:24px;text-align:center}
    #gridatlas-loader strong{color:#ffae00}
  </style>
</head>
<body data-gridatlas-router="loading">
  <main id="gridatlas-loader"><div><strong>GRIDATLAS</strong><br>verifying immutable shell and cartridges…</div></main>
  <script type="module">
    const SCRIPT_CLOSE = '</scr' + 'ipt>';
    const loader = document.getElementById('gridatlas-loader');

    function invariant(condition, message) {
      if (!condition) throw new Error(message);
    }

    function escapeAttribute(value) {
      return String(value).replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/</g, '&lt;');
    }

    async function sha256Hex(bytes) {
      const digest = await crypto.subtle.digest('SHA-256', bytes);
      return [...new Uint8Array(digest)].map(value => value.toString(16).padStart(2, '0')).join('');
    }

    function fail(error) {
      console.error('[GRIDATLAS COMPOSER]', error);
      document.body.dataset.gridatlasRouter = 'failed';
      loader.innerHTML = `<div><strong>GRIDATLAS COMPOSITION FAILED</strong><br>${String(error?.message || error).replace(/[<>&]/g, '')}<br><small>The immutable shell was not changed.</small></div>`;
    }

    try {
      const currentResponse = await fetch('./current.json', { cache: 'no-store' });
      invariant(currentResponse.ok, `current.json HTTP ${currentResponse.status}`);
      const current = await currentResponse.json();
      invariant(current?.schema === 'gridatlas.current.v2', 'unsupported current.json schema');
      invariant(current?.architecture === 'IMMUTABLE_SHELL_PLUS_HASHED_CARTRIDGES', 'architecture contract mismatch');
      invariant(Array.isArray(current.cartridge_order) && Array.isArray(current.cartridges), 'cartridge registry malformed');

      const shellUrl = new URL(current.shell.index, window.location.href);
      const shellBase = new URL(current.shell.base, window.location.href).href;
      const shellResponse = await fetch(shellUrl, { cache: 'no-store' });
      invariant(shellResponse.ok, `immutable shell HTTP ${shellResponse.status}`);
      let html = await shellResponse.text();
      invariant(/<head\b/i.test(html) && /<body\b/i.test(html), 'immutable shell is not HTML');
      html = html.replace(/<head([^>]*)>/i, match => `${match}\n<base href="${escapeAttribute(shellBase)}">`);

      const byId = new Map(current.cartridges.map(item => [item.id, item]));
      const loaded = [];
      const scriptTagPattern = new RegExp('<script\\b[^>]*\\bsrc=(["\\\'])([^"\\\']+)\\1[^>]*>\\s*<\\/script>', 'gi');

      for (const id of current.cartridge_order) {
        const cartridge = byId.get(id);
        invariant(cartridge, `missing cartridge ${id}`);
        invariant(cartridge.type === 'script', `${id}: unsupported cartridge type`);
        invariant(cartridge.slot === 'replace-script', `${id}: unsupported cartridge slot`);
        invariant(typeof cartridge.replace_script === 'string' && cartridge.replace_script, `${id}: replace_script missing`);
        invariant(/^[a-f0-9]{64}$/.test(cartridge.sha256 || ''), `${id}: invalid SHA-256`);

        const cartridgeUrl = new URL(cartridge.path, window.location.href);
        const response = await fetch(cartridgeUrl, { cache: 'no-store' });
        invariant(response.ok, `${id}: HTTP ${response.status}`);
        const bytes = await response.arrayBuffer();
        invariant(await sha256Hex(bytes) === cartridge.sha256, `${id}: SHA-256 mismatch`);
        const blobUrl = URL.createObjectURL(new Blob([bytes], { type: 'text/javascript' }));

        let replaced = false;
        html = html.replace(scriptTagPattern, (full, quote, src) => {
          if (replaced || String(src).split('/').pop() !== cartridge.replace_script) return full;
          replaced = true;
          return `<script data-gridatlas-cartridge="${escapeAttribute(id)}" src="${escapeAttribute(blobUrl)}">${SCRIPT_CLOSE}`;
        });
        invariant(replaced, `${id}: shell slot ${cartridge.replace_script} not found`);
        loaded.push({ id, sha256: cartridge.sha256, blob_url: blobUrl });
      }

      const publicState = JSON.stringify({
        schema: current.schema,
        generation: current.generation,
        release_id: current.release_id,
        architecture: current.architecture,
        shell: current.shell,
        cartridge_order: current.cartridge_order,
        loaded_cartridges: loaded.map(item => ({ id: item.id, sha256: item.sha256 }))
      }).replace(/</g, '\\u003c');
      const stateScript = `<script>window.__GRIDATLAS_ATLAS__=${publicState};document.documentElement.dataset.gridatlasGeneration=${JSON.stringify(current.generation)};${SCRIPT_CLOSE}`;
      html = html.replace(/<body([^>]*)>/i, match => `${match}\n${stateScript}`);

      document.open();
      document.write(html);
      document.close();
    } catch (error) {
      fail(error);
    }
  </script>
</body>
</html>

SatNav Offline Plan Worker

A JavaScript file in the atlas folder of GridAtlas. It opens plan (`openPlan`).

ingestgridatlas / atlas/v/satnav-offline-plan-202611281315-worker.js · lines 1–33 of 33 · version 2026-11-28 13:15 · Not reached from any entry point (candidate for review)

What it does
It fetches data. Defines openPlan. Side effects: makes network requests.
Why it exists in the grid workflow
Domain stage field_execution (path word 'satnav'): on-road and off-road field navigation to the farm gate (access gates, terrain slope, ground-bearing limits, electrical hazards), as Ventus Ltd describes its SatNav work.
What it achieves
A version registers this worker for its own directory after an explicit save. It responds to install, activate and fetch events.
Why it matters
No other file in the estate was found to import it.
Application
gridatlas · atlas/v · script
Uses
none found
Used by
none found
Produces
openPlan
Defines here
openPlan
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
gridatlas@98b5004c5eda9f2ed915fb6fca4b9bbcaa426ca5 atlas/v/satnav-offline-plan-202611281315-worker.js:1-33 · blob 61914d7185126cc32ed001e9af41b68ac08d5f3f · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: ingest · effects: network · domain stage: field_execution · users: EPC_contractor, landowner_planner · canonical: unreached_review
// A version registers this worker for its own directory after an explicit save.
// Only the version entry can fall back to a saved plan. Map tiles and GPS are never cached.
const entry = new URL(self.registration.scope);
const savedPlanKey = new URL('__saved-field-plan__', entry).href;
const cacheName = 'ventus-satnav-offline-plans-v1';

self.addEventListener('install', event => event.waitUntil(self.skipWaiting()));
self.addEventListener('activate', event => event.waitUntil(self.clients.claim()));

async function openPlan(request) {
  let response;
  try {
    // The online entry is only a loader. A cached HTTP 200 for that loader
    // would conceal a disconnected origin and leave its dependencies unavailable.
    response = await fetch(request, {cache: 'no-store'});
    if (response.status < 500) return response;
  } catch {
    // Offline navigation can still open the user's last explicitly saved copy.
  }
  const saved = await caches.match(savedPlanKey, {cacheName});
  return saved || response || new Response('This version has no saved field plan on this device.', {
    status: 503,
    headers: {'Content-Type': 'text/plain; charset=utf-8'},
  });
}

self.addEventListener('fetch', event => {
  if (event.request.mode !== 'navigate' || event.request.method !== 'GET') return;
  const target = new URL(event.request.url);
  if (target.origin !== entry.origin) return;
  if (target.pathname !== entry.pathname && target.pathname !== entry.pathname + 'index.html') return;
  event.respondWith(openPlan(event.request));
});