GLOBALGRID2050 / EXPLORE CODE

Part of: Explore Code / Solar and storage design / globalgrid2050 / solar-bess-topology-v7/docs

GIS Single-Line Diagram (SLD) V5 Drawing and 4 more files

A JavaScript file in the GIS SLD financial sandbox folder of GlobalGrid2050 that works with battery storage (BESS) and substations. Served with the page at https://globalgrid2050.com/solar-bess-topology-v7/gis-sld-financial-sandbox/.

534 lines of JavaScript and HTML and YAML from globalgrid2050, in 5 files. Topic: Solar and storage design. Section 98 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. Demonstration Videos render · globalgrid2050 / solar-bess-topology-v7/docs/demonstration-videos.html lines 1–119
  2. 05 V6 Module Relevance docs-config · globalgrid2050 / solar-bess-topology-v7/docs/training/05_v6_module_relevance.yml lines 1–80
  3. GIS Single-Line Diagram (SLD) V5 Config electrical · globalgrid2050 / solar-bess-topology-v7/gis-sld-financial-sandbox/gis-sld-v5-config.js lines 1–24
  4. GIS Single-Line Diagram (SLD) V5 Drawing geodesy · globalgrid2050 / solar-bess-topology-v7/gis-sld-financial-sandbox/gis-sld-v5-drawing.js lines 1–236
  5. GIS Single-Line Diagram (SLD) V5 Helpers geodesy · globalgrid2050 / solar-bess-topology-v7/gis-sld-financial-sandbox/gis-sld-v5-helpers.js lines 1–75

Demonstration Videos

A web page in GlobalGrid2050 covering solar and battery storage (BESS). Published at https://globalgrid2050.com/solar-bess-topology-v7/docs/demonstration-videos.html.

renderglobalgrid2050 / solar-bess-topology-v7/docs/demonstration-videos.html · lines 1–119 of 119 · Entry point

What it does
It draws solar and battery storage (BESS). Side effects: changes the web page (DOM).
Why it exists in the grid workflow
Domain stage sub33kv_design (path word 'bess'): inside-the-fence electrical and civil design below 33kV, which Ventus Ltd states is within its commercial execution boundary. Domain terms in the code: solar, battery storage (BESS).
Inputs & outputs
Out: web page.
Downstream impact
Used directly by 2 files: GlobalGrid2050 — Solar Battery Energy Storage System (BESS) Topology V7 Page (globalgrid2050, https://globalgrid2050.com/solar-bess-topology-v7/); Spider Maya — V1 Page (spiders, https://ventusltd.github.io/spiders/spider_maya/v1/). Reached from 135 other entry points, including Iterations — 43 Registry Growth Page (galaxies-wafers, https://ventusltd.github.io/galaxies-wafers/iterations/43-registry-growth/); Iterations — 47 Federation Honesty Page (galaxies-wafers, https://ventusltd.github.io/galaxies-wafers/iterations/47-federation-honesty/); GlobalGrid2050 Historical Builds (globalgrid2050, https://globalgrid2050.com/historical_builds.html). It is itself an entry point, published at https://globalgrid2050.com/solar-bess-topology-v7/docs/demonstration-videos.html.
What it achieves
No statement of purpose was found in the file, a README line naming it, or its name.
Why it matters
Loaded by the Solar Battery Energy Storage System (BESS) Topology V7 page at https://globalgrid2050.com/solar-bess-topology-v7/ and 1 other page.
Application
globalgrid2050 · solar-bess-topology-v7/docs · page
Uses
GlobalGrid2050 — Solar Battery Energy Storage System (BESS) Topology V7 Page (link)
Used by
linked from GlobalGrid2050 — Solar Battery Energy Storage System (BESS) Topology V7 Page (link), named by URL in Spider Maya — V1 Page (estate URL)
Produces
none declared
Defines here
none
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 solar-bess-topology-v7/docs/demonstration-videos.html:1-119 · blob b2cdcd885ad0e39f0692bbd508eac3504dfddc8a · GitHub at these lines
State
achieves: name · context: readme_derived · stage: output · effects: dom · domain stage: sub33kv_design · users: EPC_contractor, ICP_grid_engineer · canonical: production_core
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>V7 Demonstration Videos | GlobalGrid2050</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
  body {
    background: black;
    color: white;
    font-family: Courier, monospace;
    padding: 40px;
    max-width: 900px;
    margin: 0 auto;
    font-size: 20px;
    line-height: 1.6;
  }

  h1, h2, h3 {
    margin-top: 0;
  }

  a {
    color: #66ccff;
    text-decoration: none;
  }

  a:hover {
    text-decoration: underline;
  }

  .kicker {
    color: #66ccff;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 14px;
    margin-bottom: 10px;
  }

  .panel {
    border: 1px solid #333;
    background: #080808;
    padding: 24px;
    margin-top: 24px;
    border-radius: 10px;
  }

  .video-card {
    border-top: 1px solid #333;
    padding-top: 22px;
    margin-top: 22px;
  }

  .button-link {
    display: inline-block;
    margin-top: 12px;
    padding: 10px 14px;
    border: 1px solid #66ccff;
    border-radius: 6px;
    color: #66ccff;
    font-weight: bold;
  }

  .meta {
    color: #aaaaaa;
    font-size: 16px;
  }

  .footer {
    margin-top: 60px;
    font-size: 16px;
    color: #aaaaaa;
    line-height: 1.5;
  }

  @media (max-width: 600px) {
    body {
      padding: 25px;
      font-size: 18px;
    }

    .footer,
    .meta {
      font-size: 14px;
    }
  }
</style>
</head>
<body>
  <div class="kicker">GlobalGrid2050 V7</div>
  <h1>V7 Demonstration Videos</h1>

  <p>This page records public demonstration videos for the GlobalGrid2050 V7 workspace.</p>

  <p>These videos support review of the V7 GIS SLD Financial Sandbox, solar PV and BESS screening workflows, grid context and early commercial engineering logic.</p>

  <div class="panel">
    <h2>Demonstration videos</h2>

    <div class="video-card">
      <h3>GIS SLD Financial Sandbox V7 Demo</h3>
      <p class="meta">Public demonstration video</p>
      <p>This video demonstrates the V7 GIS SLD Financial Sandbox workflow, including map based grid and asset screening logic for early solar PV and BESS project review.</p>
      <h3>Summary</h3>
      <p>The demonstration presents GlobalGrid2050 V7 as a geospatial, electrical and financial sandbox for early stage solar PV and BESS development. It shows how users can view existing grid infrastructure, including high voltage lines and substations, then overlay renewable asset status to assess potential project locations.</p>
      <p>The workflow combines satellite mapping, real world site inspection, scalable project sizing, SLD thinking, cable route assumptions and financial screening. The tool is designed to move beyond generic CAD by connecting map based reality capture with electrical topology, inverter and transformer assumptions, route geometry, losses, CAPEX, revenue, profit and project feasibility.</p>
      <p>In practical terms, V7 helps developers, consultants, funders and engineering teams test whether a site is worth deeper investigation before formal design, procurement or investment decisions are locked in.</p>
      <a class="button-link" href="https://youtu.be/nXpmdZchTw0?si=lfuQlc89FMAcWgjf" target="_blank" rel="noopener noreferrer">Open video</a>
    </div>
  </div>

  <p><a href="../index.html">Back to V7 workspace</a></p>
  <p><a href="../../index.html">Back to GlobalGrid2050 home</a></p>

  <div class="footer">
    <p><strong>Disclaimer:</strong> Content provided for general technical documentation and research purposes only.</p>
  </div>
</body>
</html>

05 V6 Module Relevance

A configuration file in the training folder of GlobalGrid2050 covering battery storage (BESS), solar and cables.

docs-configglobalgrid2050 / solar-bess-topology-v7/docs/training/05_v6_module_relevance.yml · lines 1–80 of 80 · Not reached from any entry point (candidate for review)

Why it exists in the grid workflow
Domain stage sub33kv_design (path word 'bess'): inside-the-fence electrical and civil design below 33kV, which Ventus Ltd states is within its commercial execution boundary. Domain terms in the code: battery storage (BESS), solar, cables.
What it achieves
No statement of purpose was found in the file, a README line naming it, or its name.
Why it matters
No other file in the estate was found to import it.
Application
globalgrid2050 · solar-bess-topology-v7/docs/training · configuration
Uses
none found
Used by
none found
Produces
none declared
Defines here
none
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 solar-bess-topology-v7/docs/training/05_v6_module_relevance.yml:1-80 · blob 534267e0d7be7e4740303dbba3aa9f72387ecce5 · GitHub at these lines
State
achieves: name · context: readme_derived · stage: unknown · effects: none found · domain stage: sub33kv_design · users: EPC_contractor, ICP_grid_engineer · canonical: unreached_review
training_folder: solar-bess-topology-v7/docs/training
public_homepage_link: false
confidentiality_rule: >
  Do not include project names, client names, site names, contractor names,
  supplier names, consultant names or confidential source document titles.
  Convert source material into generic engineering lessons only.

governing_rule:
  - Geometry first
  - Assumptions second
  - Screening third
  - Formal design only when verified

v6_modules:
  cable_geometry_visualiser:
    path: solar-bess-topology-v7/cable-geometry-visualiser
    relevant_training:
      - 01_cable_route_assumptions.md
      - 02_sld_topology_validation.md
      - 04_electrical_risk_controls.md
    future_feature_priority:
      - V7 cable route assumption schema phase 1
      - Export missing assumption flags
      - Add thermal and protection placeholder status
    do_not:
      - claim cable rating
      - claim compliance
      - add IEC thermal calculation before assumptions are stable

  gis_sld_financial_sandbox:
    path: solar-bess-topology-v7/gis-sld-financial-sandbox
    relevant_training:
      - 02_sld_topology_validation.md
      - 03_bess_grid_resilience.md
      - 04_electrical_risk_controls.md
    future_feature_priority:
      - Electrical topology validation phase 1
      - Feeder load aggregation
      - Transformer and inverter count cross checks
      - BESS availability and redundancy visibility
    do_not:
      - allow manual totals to override child object totals
      - treat SLD symbols as electrical validity
      - hide temperature rating basis

  dc_ac_lv_topology_review:
    path: solar-bess-topology-v7/dc-ac-lv-topology-review
    relevant_training:
      - 02_sld_topology_validation.md
      - 04_electrical_risk_controls.md
    future_feature_priority:
      - DC string voltage check placeholders
      - LV AC insulation coordination placeholders
      - Inverter feeder and protection status fields
      - Harmonic and reactive power assumption fields
    do_not:
      - assume unity power factor without explicit basis
      - assume cable voltage rating is valid without earthing basis
      - draw protection without protection data

  module_layout:
    path: solar-bess-topology-v7/module-layout
    relevant_training:
      - 02_sld_topology_validation.md
    future_feature_priority:
      - Link module count to SLD hierarchy later
      - Track module rating and mixed module flag later
      - Preserve physical layout as visual assumption level
    do_not:
      - treat physical module layout as verified electrical design
      - mix module geometry with full SLD logic too early

future_training_expansion:
  - employer_requirements_delivery_logic
  - commissioning_and_acceptance_logic
  - formal_testing_status_logic

current_recommendation: >
  Work on the tool first. Keep training modules short and generic.
  Do not encode contractual delivery logic until the V7 electrical layers are ready.

GIS Single-Line Diagram (SLD) V5 Config

A JavaScript file in the GIS SLD financial sandbox folder of GlobalGrid2050 covering grid substations. Served with the page at https://globalgrid2050.com/solar-bess-topology-v7/gis-sld-financial-sandbox/.

electricalglobalgrid2050 / solar-bess-topology-v7/gis-sld-financial-sandbox/gis-sld-v5-config.js · lines 1–24 of 24 · Entry point

Why it exists in the grid workflow
Domain stage experimental (path word 'sandbox'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow.
Downstream impact
Used directly by 3 files: Solar Battery Energy Storage System (BESS) Topology V7 — GIS Single-Line Diagram (SLD) Financial Sandbox Page (globalgrid2050, https://globalgrid2050.com/solar-bess-topology-v7/gis-sld-financial-sandbox/); Solar Battery Energy Storage System (BESS) Topology V7 — GIS Single-Line Diagram (SLD) Financial Sandbox Page (globalgrid2050, https://globalgrid2050.com/testcode/202609052011/layer-apps/solar-bess-topology-v7/gis-sld-financial-sandbox/); Solar Battery Energy Storage System (BESS) Topology V7 — GIS Single-Line Diagram (SLD) Financial Sandbox Page (testcode). Reached from 145 other entry points, including Iterations — 43 Registry Growth Page (galaxies-wafers, https://ventusltd.github.io/galaxies-wafers/iterations/43-registry-growth/); Iterations — 47 Federation Honesty Page (galaxies-wafers, https://ventusltd.github.io/galaxies-wafers/iterations/47-federation-honesty/); Demonstration Videos (globalgrid2050, https://globalgrid2050.com/solar-bess-topology-v7/docs/demonstration-videos.html). It is itself an entry point, published at https://globalgrid2050.com/solar-bess-topology-v7/gis-sld-financial-sandbox/.
What it achieves
GIS SLD Financial Sandbox V7. Config extracted by GridBot feature 002.
Why it matters
Loaded by the GIS Single-Line Diagram (SLD) Financial Sandbox page at https://globalgrid2050.com/solar-bess-topology-v7/gis-sld-financial-sandbox/ and 2 other pages.
Application
globalgrid2050 · solar-bess-topology-v7/gis-sld-financial-sandbox · script
Uses
none found
Used by
loaded by Solar Battery Energy Storage System (BESS) Topology V7 — GIS Single-Line Diagram (SLD) Financial Sandbox Page (script src), loaded by Solar Battery Energy Storage System (BESS) Topology V7 — GIS Single-Line Diagram (SLD) Financial Sandbox Page (script src), loaded by Solar Battery Energy Storage System (BESS) Topology V7 — GIS Single-Line Diagram (SLD) Financial Sandbox Page (script src)
Produces
none declared
Defines here
none
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 solar-bess-topology-v7/gis-sld-financial-sandbox/gis-sld-v5-config.js:1-24 · blob d0fcfbc13c72efee87b4268d8d632b62282eee4b · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: unknown · effects: none found · domain stage: experimental · users: none · canonical: production_core
"use strict";

// GIS SLD Financial Sandbox V7
// Config extracted by GridBot feature 002.
// TODO: migrate config into the shared GISSLD namespace at feature 007.

const SUBSTATIONS_URL = "/grid_substations.geojson";

const CONSTANTS = {
    M2_PER_ACRE: 4046.86,
    BESS_M2_PER_MWH: 85,
    BESS_ASPECT: 2.5,
    BLOCK_SPACING_KM: 0.01,
    BOUNDARY_BUFFER_KM: 0.02,
    ARRAY_OFFSET_KM: 0.2,
    DEFAULT_CENTER: [-0.1276, 51.5072],
    DEFAULT_ZOOM: 13,
    RECALC_DEBOUNCE_MS: 80,
    BIFACIAL_BY_GCR: { "0.35": 8, "0.45": 5, "0.75": 2 },
    LOGISTICS_PRESETS: {
        high_density: { pallet: 33, container: 594 },
        legacy: { pallet: 31, container: 620 }
    }
};

GIS Single-Line Diagram (SLD) V5 Drawing

A JavaScript file in the GIS SLD financial sandbox folder of GlobalGrid2050 that works with battery storage (BESS) and substations. Served with the page at https://globalgrid2050.com/solar-bess-topology-v7/gis-sld-financial-sandbox/.

geodesyglobalgrid2050 / solar-bess-topology-v7/gis-sld-financial-sandbox/gis-sld-v5-drawing.js · lines 1–236 of 236 · Entry point · pattern addCableRoutePinMarkers (shared by 2 files)

What it does
It calculates battery storage (BESS) and substations. Defines 12 functions or classes, including normBearing, getArrayAxisDeg, getRectPolygon, atlasHaversineKm, routeLengthKm.
Why it exists in the grid workflow
Domain stage experimental (path word 'sandbox'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow. Domain terms in the code: battery storage (BESS), substations, 33kV.
Inputs & outputs
Voltage levels named: 33kV.
Downstream impact
Used directly by 3 files: Solar Battery Energy Storage System (BESS) Topology V7 — GIS Single-Line Diagram (SLD) Financial Sandbox Page (globalgrid2050, https://globalgrid2050.com/solar-bess-topology-v7/gis-sld-financial-sandbox/); Solar Battery Energy Storage System (BESS) Topology V7 — GIS Single-Line Diagram (SLD) Financial Sandbox Page (globalgrid2050, https://globalgrid2050.com/testcode/202609052011/layer-apps/solar-bess-topology-v7/gis-sld-financial-sandbox/); Solar Battery Energy Storage System (BESS) Topology V7 — GIS Single-Line Diagram (SLD) Financial Sandbox Page (testcode). Reached from 145 other entry points, including Iterations — 43 Registry Growth Page (galaxies-wafers, https://ventusltd.github.io/galaxies-wafers/iterations/43-registry-growth/); Iterations — 47 Federation Honesty Page (galaxies-wafers, https://ventusltd.github.io/galaxies-wafers/iterations/47-federation-honesty/); Demonstration Videos (globalgrid2050, https://globalgrid2050.com/solar-bess-topology-v7/docs/demonstration-videos.html). It is itself an entry point, published at https://globalgrid2050.com/solar-bess-topology-v7/gis-sld-financial-sandbox/.
What it achieves
It gets array axis deg (`getArrayAxisDeg`), gets rect polygon (`getRectPolygon`) and routes length km (`routeLengthKm`). Defines `normBearing`, `getArrayAxisDeg`, `getRectPolygon` and 9 more. Its code works with 33 kV.
Why it matters
Loaded by the GIS Single-Line Diagram (SLD) Financial Sandbox page at https://globalgrid2050.com/solar-bess-topology-v7/gis-sld-financial-sandbox/ and 2 other pages.
Application
globalgrid2050 · solar-bess-topology-v7/gis-sld-financial-sandbox · script
Uses
none found
Used by
loaded by Solar Battery Energy Storage System (BESS) Topology V7 — GIS Single-Line Diagram (SLD) Financial Sandbox Page (script src), loaded by Solar Battery Energy Storage System (BESS) Topology V7 — GIS Single-Line Diagram (SLD) Financial Sandbox Page (script src), loaded by Solar Battery Energy Storage System (BESS) Topology V7 — GIS Single-Line Diagram (SLD) Financial Sandbox Page (script src), mentioned in Standalone (comment link)
Produces
normBearing, getArrayAxisDeg, getRectPolygon, atlasHaversineKm, routeLengthKm, getBlockAspect, getExportCableExtraKm, getCommittedCablePins, shouldShowExportCable, buildExportCableLine, addCableRoutePinMarkers, computeAndDraw
Defines here
normBearing, getArrayAxisDeg, getRectPolygon, atlasHaversineKm, routeLengthKm, getBlockAspect, getExportCableExtraKm, getCommittedCablePins, shouldShowExportCable, buildExportCableLine, addCableRoutePinMarkers, computeAndDraw
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 solar-bess-topology-v7/gis-sld-financial-sandbox/gis-sld-v5-drawing.js:1-236 · blob fd8e16fafe1e151fc86d425c0b2df0b5871cb98b · GitHub at these lines
State
achieves: name · context: readme_derived · stage: transform · effects: none found · domain stage: experimental · users: none · canonical: production_core
"use strict";

// DRAWING
// ============================================================
function normBearing(deg) {
    return ((deg % 360) + 360) % 360;
}

function getArrayAxisDeg() {
    return normBearing(Number.isFinite(state.arrayRotationDeg) ? state.arrayRotationDeg : 0);
}

function getRectPolygon(centerCoord, width_km, length_km, propType, rotationDeg = 0) {
    const axis = normBearing(rotationDeg);
    const pt = turf.point(centerCoord);
    const ptN = turf.destination(pt, length_km / 2, axis, { units: "kilometers" }).geometry.coordinates;
    const ptS = turf.destination(pt, length_km / 2, axis + 180, { units: "kilometers" }).geometry.coordinates;
    const nw = turf.destination(turf.point(ptN), width_km / 2, axis - 90, { units: "kilometers" }).geometry.coordinates;
    const ne = turf.destination(turf.point(ptN), width_km / 2, axis + 90, { units: "kilometers" }).geometry.coordinates;
    const se = turf.destination(turf.point(ptS), width_km / 2, axis + 90, { units: "kilometers" }).geometry.coordinates;
    const sw = turf.destination(turf.point(ptS), width_km / 2, axis - 90, { units: "kilometers" }).geometry.coordinates;
    return turf.polygon([[nw, ne, se, sw, nw]], { type: propType });
}

function atlasHaversineKm(a, b) {
    const R = 6378.137;
    const r = Math.PI / 180;
    const lon1 = a[0], lat1 = a[1], lon2 = b[0], lat2 = b[1];
    const dLat = (lat2 - lat1) * r;
    const dLon = (lon2 - lon1) * r;
    const x = Math.sin(dLat / 2) ** 2 + Math.cos(lat1 * r) * Math.cos(lat2 * r) * Math.sin(dLon / 2) ** 2;
    return R * 2 * Math.atan2(Math.sqrt(x), Math.sqrt(1 - x));
}

function routeLengthKm(coords) {
    if (!Array.isArray(coords) || coords.length < 2) return 0;
    let total = 0;
    for (let i = 1; i < coords.length; i++) total += atlasHaversineKm(coords[i - 1], coords[i]);
    return total;
}

function getBlockAspect() {
    const mountingVal = state.activeTab === "string" ? $("mounting_type").value : $("mounting_type_c").value;
    if (mountingVal === "0.45") return 1 / 1.4;
    if (mountingVal === "0.75") return 1.0;
    return 1.4;
}

function getExportCableExtraKm() {
    const el = $("layout_export_extra_km");
    if (!el) return 0;
    const value = parseFloat(el.value);
    return Number.isFinite(value) ? value : 0;
}

function getCommittedCablePins() {
    return state.cableRouteCommitted && Array.isArray(state.cableRoutePins) ? state.cableRoutePins : [];
}

function shouldShowExportCable() {
    if (state.cableRoutePinMode) return false;
    if (Array.isArray(state.cableRoutePins) && state.cableRoutePins.length > 0 && !state.cableRouteCommitted) return false;
    return true;
}

function buildExportCableLine(privateSubCoord, publicSubCoord, safeExtraOffsetKm) {
    const routePoints = getCommittedCablePins();
    const coords = [privateSubCoord, ...routePoints, publicSubCoord];
    return turf.lineString(coords, {
        type: "export_cable",
        export_cable_extra_km: safeExtraOffsetKm,
        export_cable_length_km: 0,
        array_moved_manually: Boolean(state.arrayOverrideCenter),
        array_rotation_deg: getArrayAxisDeg(),
        routed_by_pins: routePoints.length > 0,
        route_pin_count: routePoints.length,
        measurement_method: "atlas_haversine_6378_137_km"
    });
}

function addCableRoutePinMarkers(features) {
    if (!Array.isArray(state.cableRoutePins)) return;
    state.cableRoutePins.forEach((coord, idx) => {
        features.push(turf.point(coord, {
            type: "export_cable_pin",
            pin_index: idx + 1,
            committed_to_route: Boolean(state.cableRouteCommitted)
        }));
    });
}

function computeAndDraw() {
    if (!state.activeDrawCenter || !map) return;
    const stats = computeStats();
    state.lastStats = stats;

    if (stats.total_blocks === 0) {
        recalcAll();
        return;
    }

    const axis = getArrayAxisDeg();
    const N = stats.total_blocks;
    const cols = Math.ceil(Math.sqrt(N));
    const rows = Math.ceil(N / cols);
    const block_area_km2 = stats.block_ground_area_m2 / 1_000_000;

    const aspect = getBlockAspect();
    const block_w = Math.sqrt(block_area_km2 / aspect);
    const block_l = block_w * aspect;
    const spacing = CONSTANTS.BLOCK_SPACING_KM;

    const grid_w = cols * block_w + (cols - 1) * spacing;
    const grid_l = rows * block_l + (rows - 1) * spacing;

    const features = [];
    const publicSubCoord = state.activeDrawCenter;
    const safeExtraOffsetKm = Math.max(-CONSTANTS.ARRAY_OFFSET_KM, getExportCableExtraKm());
    const arrayOffsetKm = grid_l / 2 + CONSTANTS.ARRAY_OFFSET_KM + safeExtraOffsetKm;
    const defaultGridCenter = turf.destination(turf.point(publicSubCoord), arrayOffsetKm, axis, { units: "kilometers" }).geometry.coordinates;
    const gridCenter = state.arrayOverrideCenter || defaultGridCenter;
    const privateSubCoord = turf.destination(turf.point(gridCenter), grid_l / 2, axis + 180, { units: "kilometers" }).geometry.coordinates;
    const exportCableLine = buildExportCableLine(privateSubCoord, publicSubCoord, safeExtraOffsetKm);
    state.exportCableLengthKm = routeLengthKm(exportCableLine.geometry.coordinates);
    exportCableLine.properties.export_cable_length_km = state.exportCableLengthKm;

    features.push(turf.point(publicSubCoord, {
        type: "poi",
        selected_substation_name: state.selectedSubstation?.name || "Local Grid Node",
        selected_substation_voltage: state.selectedSubstation?.voltage || "Unknown"
    }));
    features.push(turf.point(privateSubCoord, {
        type: "private_sub",
        selected_substation_name: "Customer Substation",
        selected_substation_voltage: "Local Voltage",
        export_cable_extra_km: safeExtraOffsetKm,
        export_cable_length_km: state.exportCableLengthKm,
        array_moved_manually: Boolean(state.arrayOverrideCenter),
        array_rotation_deg: axis,
        export_cable_pin_count: state.cableRoutePins.length,
        export_cable_route_committed: Boolean(state.cableRouteCommitted)
    }));
    if (shouldShowExportCable()) features.push(exportCableLine);
    addCableRoutePinMarkers(features);
    features.push(getRectPolygon(gridCenter, grid_w + CONSTANTS.BOUNDARY_BUFFER_KM, grid_l + CONSTANTS.BOUNDARY_BUFFER_KM, "array_boundary", axis));

    const ptN = turf.destination(turf.point(gridCenter), grid_l / 2, axis, { units: "kilometers" }).geometry.coordinates;
    const ptNW = turf.destination(turf.point(ptN), grid_w / 2, axis - 90, { units: "kilometers" }).geometry.coordinates;

    const inverters = [];
    let count = 0;
    for (let r = 0; r < rows; r++) {
        for (let c = 0; c < cols; c++) {
            if (count >= N) break;
            const posAcross = turf.destination(turf.point(ptNW), c * block_w + c * spacing + block_w / 2, axis + 90, { units: "kilometers" }).geometry.coordinates;
            const finalPos = turf.destination(turf.point(posAcross), r * block_l + r * spacing + block_l / 2, axis + 180, { units: "kilometers" }).geometry.coordinates;
            const nodeType = state.activeTab === "string" ? "string_substation" : "central_inverter";
            const footType = state.activeTab === "string" ? "skid_footprint" : "central_footprint";
            features.push(getRectPolygon(finalPos, block_w, block_l, footType, axis));
            inverters.push({ coords: finalPos, type: nodeType });
            features.push(turf.point(finalPos, { type: nodeType }));
            count++;
        }
    }

    // BESS
    const prefix = state.activeTab === "string" ? "fin_string" : "fin_central";
    const bess_mwh = num(prefix + "_bess_mwh");
    if (bess_mwh > 0) {
        const bess_area_km2 = (bess_mwh * CONSTANTS.BESS_M2_PER_MWH) / 1_000_000;
        const bess_w = Math.sqrt(bess_area_km2 * CONSTANTS.BESS_ASPECT);
        const bess_l = bess_area_km2 / bess_w;
        const bessCenter = turf.destination(turf.point(privateSubCoord), bess_w / 2 + 0.05, axis - 90, { units: "kilometers" }).geometry.coordinates;
        features.push(getRectPolygon(bessCenter, bess_w, bess_l, "bess_footprint", axis));
        features.push(turf.point(bessCenter, { type: "bess_compound", mwh: bess_mwh }));
        features.push(turf.lineString([bessCenter, privateSubCoord], { type: "33kv_radial" }));
    }

    // Internal 33kV radial links with a clipped visible trunk back to the customer substation.
    if (inverters.length > 0) {
        const projectionLine = turf.lineString([
            privateSubCoord,
            turf.destination(turf.point(privateSubCoord), grid_l, axis, { units: "kilometers" }).geometry.coordinates
        ], { type: "33kv_projection_only" });

        let maxTrunkDistanceKm = 0;
        const projectedBranches = [];
        inverters.forEach(inv => {
            const projected = turf.nearestPointOnLine(projectionLine, turf.point(inv.coords), { units: "kilometers" }).geometry.coordinates;
            const distanceFromCustomerSub = routeLengthKm([privateSubCoord, projected]);
            if (distanceFromCustomerSub > maxTrunkDistanceKm) maxTrunkDistanceKm = distanceFromCustomerSub;
            projectedBranches.push({ inverter: inv.coords, projected });
        });

        if (maxTrunkDistanceKm > 0) {
            const clippedTrunkEnd = turf.destination(turf.point(privateSubCoord), maxTrunkDistanceKm, axis, { units: "kilometers" }).geometry.coordinates;
            features.push(turf.lineString([privateSubCoord, clippedTrunkEnd], {
                type: "33kv_radial",
                role: "collector_trunk",
                clipped_to_inverter_extent: true
            }));
        }

        projectedBranches.forEach(branch => {
            features.push(turf.lineString([branch.inverter, branch.projected], {
                type: "33kv_radial",
                role: "block_branch"
            }));
        });
    }

    state.currentGeoJSON = turf.featureCollection(features);
    const src = map.getSource("topology");
    if (src) src.setData(state.currentGeoJSON);
    setTopologyLayerVisibility?.(state.arrayVisible !== false);
    updateArrayToggleButton?.();

    if (features.length > 0 && !state.suppressNextMapFit) {
        const bbox = turf.bbox(state.currentGeoJSON);
        map.fitBounds(bbox, { padding: 60, duration: 800 });
    }
    state.suppressNextMapFit = false;

    updateExportCableLengthDisplay();
    updateCableRouteStatus();
    updateArrayRotationDisplay();

    // Refresh side-panel values
    renderTechSummary(stats);
    const fin = computeFinance(prefix, stats);
    state.lastFinance[prefix] = fin;
    renderFinance(prefix, fin);
    renderFinanceWarnings(prefix, fin, stats);
}

// ============================================================

GIS Single-Line Diagram (SLD) V5 Helpers

A JavaScript file in the GIS SLD financial sandbox folder of GlobalGrid2050 that sets class (`setClass`), picks prop (`pickProp`) and sets fetch status (`setFetchStatus`). Served with the page at https://globalgrid2050.com/solar-bess-topology-v7/gis-sld-financial-sandbox/.

geodesyglobalgrid2050 / solar-bess-topology-v7/gis-sld-financial-sandbox/gis-sld-v5-helpers.js · lines 1–75 of 75 · Entry point · pattern setFetchStatus (shared by 7 files)

What it does
Defines 11 functions or classes, including $, num, intVal, checked, setText. Side effects: changes the web page (DOM).
Why it exists in the grid workflow
Domain stage experimental (path word 'sandbox'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow.
Downstream impact
Used directly by 5 files: Solar Battery Energy Storage System (BESS) Topology V7 — GIS Single-Line Diagram (SLD) Financial Sandbox Page (globalgrid2050, https://globalgrid2050.com/solar-bess-topology-v7/gis-sld-financial-sandbox/); Solar Battery Energy Storage System (BESS) Topology V7 — Module Layout Page (globalgrid2050, https://globalgrid2050.com/solar-bess-topology-v7/module-layout/); Solar Battery Energy Storage System (BESS) Topology V7 — Module Layout Page (globalgrid2050, https://globalgrid2050.com/testcode/202609051958/layer-apps/solar-bess-topology-v7/module-layout/); Solar Battery Energy Storage System (BESS) Topology V7 — GIS Single-Line Diagram (SLD) Financial Sandbox Page (globalgrid2050, https://globalgrid2050.com/testcode/202609052011/layer-apps/solar-bess-topology-v7/gis-sld-financial-sandbox/); and 1 more. Reached from 143 other entry points, including Iterations — 43 Registry Growth Page (galaxies-wafers, https://ventusltd.github.io/galaxies-wafers/iterations/43-registry-growth/); Iterations — 47 Federation Honesty Page (galaxies-wafers, https://ventusltd.github.io/galaxies-wafers/iterations/47-federation-honesty/); Demonstration Videos (globalgrid2050, https://globalgrid2050.com/solar-bess-topology-v7/docs/demonstration-videos.html). It is itself an entry point, published at https://globalgrid2050.com/solar-bess-topology-v7/gis-sld-financial-sandbox/.
What it achieves
It sets text (`setText`), sets class (`setClass`) and picks prop (`pickProp`). GIS SLD Financial Sandbox V7. Helpers extracted by GridBot feature 003.
Why it matters
Loaded by the GIS Single-Line Diagram (SLD) Financial Sandbox page at https://globalgrid2050.com/solar-bess-topology-v7/gis-sld-financial-sandbox/ and 4 other pages.
Application
globalgrid2050 · solar-bess-topology-v7/gis-sld-financial-sandbox · script
Uses
none found
Used by
loaded by Solar Battery Energy Storage System (BESS) Topology V7 — GIS Single-Line Diagram (SLD) Financial Sandbox Page (script src), loaded by Solar Battery Energy Storage System (BESS) Topology V7 — Module Layout Page (script src), loaded by Solar Battery Energy Storage System (BESS) Topology V7 — Module Layout Page (script src), loaded by Solar Battery Energy Storage System (BESS) Topology V7 — GIS Single-Line Diagram (SLD) Financial Sandbox Page (script src), loaded by Solar Battery Energy Storage System (BESS) Topology V7 — GIS Single-Line Diagram (SLD) Financial Sandbox Page (script src), mentioned in Standalone (comment link)
Produces
$, num, intVal, checked, setText, setClass, money, debounce, isValidLngLat, pickProp, setFetchStatus
Defines here
$, num, intVal, checked, setText, setClass, money, debounce, isValidLngLat, pickProp, setFetchStatus
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 solar-bess-topology-v7/gis-sld-financial-sandbox/gis-sld-v5-helpers.js:1-75 · blob e2c75947310f79482a976b058c119bff0b194d73 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: output · effects: dom · domain stage: experimental · users: none · canonical: production_core
"use strict";

// GIS SLD Financial Sandbox V7
// Helpers extracted by GridBot feature 003.
// Must load after gis-sld-v5-config.js and before the inline app script.

const $ = (id) => document.getElementById(id);

const num = (id) => {
    const el = $(id);
    return el ? (parseFloat(el.value) || 0) : 0;
};

const intVal = (id, fallback = 0) => {
    const el = $(id);
    return el ? (parseInt(el.value, 10) || fallback) : fallback;
};

const checked = (id) => {
    const el = $(id);
    return el ? !!el.checked : false;
};

const setText = (id, val) => {
    const el = $(id);
    if (el) el.textContent = val;
};

const setClass = (id, cls) => {
    const el = $(id);
    if (el) el.className = cls;
};

function money(v) {
    const rounded = Math.round(v);
    if (rounded < 0) return "-£" + Math.abs(rounded).toLocaleString();
    return "£" + rounded.toLocaleString();
}

function debounce(fn, ms) {
    let t = null;
    return function(...args) {
        clearTimeout(t);
        t = setTimeout(() => fn.apply(this, args), ms);
    };
}

function isValidLngLat(c) {
    return Array.isArray(c) && c.length >= 2
        && Number.isFinite(+c[0]) && Number.isFinite(+c[1])
        && +c[0] >= -180 && +c[0] <= 180 && +c[1] >= -90 && +c[1] <= 90;
}

function pickProp(obj, keys, fallback = null) {
    for (const k of keys) {
        if (obj && obj[k] !== undefined && obj[k] !== null && obj[k] !== "") return obj[k];
    }
    return fallback;
}

function setFetchStatus(msg, isError) {
    const el = $("fetch_status");
    if (!el) return;

    if (!msg) {
        el.style.display = "none";
        el.textContent = "";
        el.classList.remove("error");
        return;
    }

    el.textContent = msg;
    el.style.display = "block";
    el.classList.toggle("error", !!isError);
}