GLOBALGRID2050 / EXPLORE CODE

Part of: Explore Code / Solar and storage design / globalgrid2050 / solar-bess-topology-v7/gis-sld-financial-sandbox

GIS Single-Line Diagram (SLD) V5 Map and 2 more files

A JavaScript file in the GIS SLD financial sandbox folder of GlobalGrid2050 that maps atlas grid 66kV line and atlas grid 132kV line. Served with the page at https://globalgrid2050.com/solar-bess-topology-v7/gis-sld-financial-sandbox/.

588 lines of JavaScript from globalgrid2050, in 3 files. Topic: Solar and storage design. Section 99 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. GIS Single-Line Diagram (SLD) V5 Map electrical · globalgrid2050 / solar-bess-topology-v7/gis-sld-financial-sandbox/gis-sld-v5-map.js lines 1–476
  2. GIS Single-Line Diagram (SLD) V5 State electrical · globalgrid2050 / solar-bess-topology-v7/gis-sld-financial-sandbox/gis-sld-v5-state.js lines 1–29
  3. GIS Single-Line Diagram (SLD) V5 Substations electrical · globalgrid2050 / solar-bess-topology-v7/gis-sld-financial-sandbox/gis-sld-v5-substations.js lines 1–83

GIS Single-Line Diagram (SLD) V5 Map

A JavaScript file in the GIS SLD financial sandbox folder of GlobalGrid2050 that maps atlas grid 66kV line and atlas grid 132kV line. 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-map.js · lines 1–476 of 476 · Entry point · pattern toggleAtlasV8OperatingAssetLayer (shared by 2 files)

What it does
It maps atlas grid 66kV line, atlas grid 132kV line, atlas grid 275kV line and atlas grid 400kV line. Defines 15 functions or classes, including atlasV8CapacityExpression, atlasV8AssetBaseFilter, atlasV8StatusExpression, atlasV8AssetFilter, applyAtlasV8AssetDropdownFilter. 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. Domain terms in the code: 400kV, 275kV, 132kV, 66kV, 33kV.
Inputs & outputs
In: JSON file style.json; GeoJSON file grid_66kv.geojson; GeoJSON file grid_132kv.geojson; GeoJSON file grid_275kv.geojson; GeoJSON file grid_400kv.geojson; JSON file repd_master.json. Out: interactive map. Voltage levels named: 400kV, 275kV, 132kV, 66kV, 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 toggles atlas v8 grid layer (`toggleAtlasV8GridLayer`) and shows popup (`showPopup`). Defines `atlasV8CapacityExpression`, `atlasV8AssetBaseFilter`, `atlasV8StatusExpression` and 12 more.
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
atlasV8CapacityExpression, atlasV8AssetBaseFilter, atlasV8StatusExpression, atlasV8AssetFilter, applyAtlasV8AssetDropdownFilter, toggleAtlasV8OperatingAssetLayer, toggleAtlasV8GridLayer, initMap, onMapLoad, showPopup, onSubstationClick, onInverterClick
Defines here
atlasV8CapacityExpression, atlasV8AssetBaseFilter, atlasV8StatusExpression, atlasV8AssetFilter, applyAtlasV8AssetDropdownFilter, toggleAtlasV8OperatingAssetLayer, toggleAtlasV8GridLayer, initMap, onMapLoad, showPopup, onSubstationClick, onInverterClick, onCableRoutePinClick, onOperatingAssetClick, onPoiClick
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-map.js:1-476 · blob e1826869d3186b2d187ce5c8a06b43c1e3ff8430 · GitHub at these lines
State
achieves: name · context: readme_derived · stage: output · effects: dom · domain stage: experimental · users: none · canonical: production_core
"use strict";

// MAP
// ============================================================
let map = null;
const atlasV8GridLayerVisibility = {
    "66kv": false,
    "132kv": false,
    "275kv": false,
    "400kv": false
};

const atlasV8GridLayerIds = {
    "66kv": "atlas-v8-grid-66kv-line",
    "132kv": "atlas-v8-grid-132kv-line",
    "275kv": "atlas-v8-grid-275kv-line",
    "400kv": "atlas-v8-grid-400kv-line"
};

const atlasV8OperatingAssetVisibility = {
    "solar_operational": false,
    "wind_onshore_operational": false,
    "wind_offshore_operational": false,
    "bess_operational": false
};

const atlasV8AssetFilterState = {
    selected: "off",
    status: "all",
    minMw: null,
    maxMw: null
};

const atlasV8OperatingAssetLayerIds = {
    "solar_operational": "atlas-v8-asset-solar-operational",
    "wind_onshore_operational": "atlas-v8-asset-wind-onshore-operational",
    "wind_offshore_operational": "atlas-v8-asset-wind-offshore-operational",
    "bess_operational": "atlas-v8-asset-bess-operational"
};

function atlasV8CapacityExpression() {
    return ["to-number", ["coalesce", ["get", "capacity"], ["get", "capacity_mw"], 0]];
}

function atlasV8AssetBaseFilter(assetKey) {
    if (assetKey === "solar_operational") return ["==", ["get", "tech"], "solar"];
    if (assetKey === "bess_operational") return ["==", ["get", "tech"], "bess"];
    if (assetKey === "wind_onshore_operational") return ["==", ["get", "raw_tech"], "Wind Onshore"];
    if (assetKey === "wind_offshore_operational") return ["==", ["get", "raw_tech"], "Wind Offshore"];
    return true;
}

function atlasV8StatusExpression() {
    return ["downcase", ["to-string", ["coalesce", ["get", "status"], ["get", "Status"], ""]]];
}

function atlasV8AssetFilter(assetKey) {
    const filters = ["all", atlasV8AssetBaseFilter(assetKey)];
    const capacityExpr = atlasV8CapacityExpression();
    if (atlasV8AssetFilterState.status && atlasV8AssetFilterState.status !== "all") {
        filters.push(["==", atlasV8StatusExpression(), atlasV8AssetFilterState.status]);
    }
    if (Number.isFinite(atlasV8AssetFilterState.minMw)) filters.push([">=", capacityExpr, atlasV8AssetFilterState.minMw]);
    if (Number.isFinite(atlasV8AssetFilterState.maxMw)) filters.push(["<=", capacityExpr, atlasV8AssetFilterState.maxMw]);
    return filters;
}

function applyAtlasV8AssetDropdownFilter(selected = atlasV8AssetFilterState.selected, status = atlasV8AssetFilterState.status, minMw = atlasV8AssetFilterState.minMw, maxMw = atlasV8AssetFilterState.maxMw) {
    atlasV8AssetFilterState.selected = selected || "off";
    atlasV8AssetFilterState.status = status || "all";
    atlasV8AssetFilterState.minMw = Number.isFinite(minMw) ? minMw : null;
    atlasV8AssetFilterState.maxMw = Number.isFinite(maxMw) ? maxMw : null;

    Object.keys(atlasV8OperatingAssetLayerIds).forEach(assetKey => {
        const layerId = atlasV8OperatingAssetLayerIds[assetKey];
        const visible = atlasV8AssetFilterState.selected === "all" || atlasV8AssetFilterState.selected === assetKey;
        atlasV8OperatingAssetVisibility[assetKey] = visible;
        if (map && map.getLayer(layerId)) {
            map.setFilter(layerId, atlasV8AssetFilter(assetKey));
            map.setLayoutProperty(layerId, "visibility", visible ? "visible" : "none");
        }
    });
    updateLegend?.();
}

function toggleAtlasV8OperatingAssetLayer(assetKey) {
    if (!atlasV8OperatingAssetLayerIds[assetKey]) return;
    const next = atlasV8AssetFilterState.selected === assetKey ? "off" : assetKey;
    applyAtlasV8AssetDropdownFilter(next, atlasV8AssetFilterState.status, atlasV8AssetFilterState.minMw, atlasV8AssetFilterState.maxMw);
}


function toggleAtlasV8GridLayer(voltageKey) {
    if (!atlasV8GridLayerIds[voltageKey]) return;
    atlasV8GridLayerVisibility[voltageKey] = !atlasV8GridLayerVisibility[voltageKey];
    const layerId = atlasV8GridLayerIds[voltageKey];
    if (map && map.getLayer(layerId)) {
        map.setLayoutProperty(layerId, "visibility", atlasV8GridLayerVisibility[voltageKey] ? "visible" : "none");
    }
    updateLegend();
}


function initMap() {
    if (typeof maplibregl === "undefined") {
        setFetchStatus("MapLibre failed to load. Check network.", true);
        console.error("maplibregl is undefined");
        return;
    }
    if (typeof turf === "undefined") {
        setFetchStatus("Turf failed to load. Check network.", true);
        console.error("turf is undefined");
        return;
    }

    map = new maplibregl.Map({
        container: "map",
        style: "https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json",
        center: CONSTANTS.DEFAULT_CENTER,
        zoom: CONSTANTS.DEFAULT_ZOOM
    });

    map.on("error", (e) => console.error("MapLibre error:", e && e.error ? e.error : e));
    map.on("load", onMapLoad);
}

function onMapLoad() {
    map.addSource("sat-s", {
        type: "raster",
        tiles: ["https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"],
        tileSize: 256
    });
    map.addLayer({ id: "l-sat", type: "raster", source: "sat-s", layout: { visibility: "none" } });
// Atlas V8 transmission visibility layers
// These layers are read from the existing Atlas V8 data folder.
// They are visual context only and do not imply confirmed grid headroom.
map.addSource("atlas-v8-grid-66kv", {
    type: "geojson",
    data: "../../repd_grid_atlasv8/data/grid_66kv.geojson"
});
map.addLayer({
    id: "atlas-v8-grid-66kv-line",
    type: "line",
    source: "atlas-v8-grid-66kv",
    layout: { visibility: atlasV8GridLayerVisibility["66kv"] ? "visible" : "none" },
    paint: {
        "line-color": "#66ff66",
        "line-width": ["interpolate", ["linear"], ["zoom"], 5, 0.8, 10, 1.4, 14, 2.4],
        "line-opacity": 0.62
    }
});

map.addSource("atlas-v8-grid-132kv", {
    type: "geojson",
    data: "../../repd_grid_atlasv8/data/grid_132kv.geojson"
});
map.addLayer({
    id: "atlas-v8-grid-132kv-line",
    type: "line",
    source: "atlas-v8-grid-132kv",
    layout: { visibility: atlasV8GridLayerVisibility["132kv"] ? "visible" : "none" },
    paint: {
        "line-color": "#ffcc00",
        "line-width": ["interpolate", ["linear"], ["zoom"], 5, 1.0, 10, 1.8, 14, 3.0],
        "line-opacity": 0.72
    }
});

map.addSource("atlas-v8-grid-275kv", {
    type: "geojson",
    data: "../../repd_grid_atlasv8/data/grid_275kv.geojson"
});
map.addLayer({
    id: "atlas-v8-grid-275kv-line",
    type: "line",
    source: "atlas-v8-grid-275kv",
    layout: { visibility: atlasV8GridLayerVisibility["275kv"] ? "visible" : "none" },
    paint: {
        "line-color": "#ff66ff",
        "line-width": ["interpolate", ["linear"], ["zoom"], 5, 1.3, 10, 2.4, 14, 3.7],
        "line-opacity": 0.76
    }
});

map.addSource("atlas-v8-grid-400kv", {
    type: "geojson",
    data: "../../repd_grid_atlasv8/data/grid_400kv.geojson"
});
map.addLayer({
    id: "atlas-v8-grid-400kv-line",
    type: "line",
    source: "atlas-v8-grid-400kv",
    layout: { visibility: atlasV8GridLayerVisibility["400kv"] ? "visible" : "none" },
    paint: {
        "line-color": "#ff3333",
        "line-width": ["interpolate", ["linear"], ["zoom"], 5, 1.6, 10, 2.8, 14, 4.2],
        "line-opacity": 0.82
    }
});



    map.addSource("src-subs", { type: "geojson", data: { type: "FeatureCollection", features: [] } });
    map.addLayer({
        id: "l-subs", type: "circle", source: "src-subs",
        paint: {
            "circle-color": "#ffffff",
            "circle-radius": ["interpolate", ["linear"], ["zoom"], 5, 3, 10, 5, 14, 10, 18, 22],
            "circle-stroke-width": 1, "circle-stroke-color": "#ff3333", "circle-opacity": 0.8
        }
    });



    // Atlas V8 operating asset visibility layers from REPD master data.
    // These are existing operating asset context layers only.
    // They help users inspect nearby operating solar, wind and battery assets before drawing a new array.
    map.addSource("atlas-v8-repd-operating-assets", {
        type: "geojson",
        data: "/dist/repd_master.json"
    });

    map.addLayer({
        id: "atlas-v8-asset-solar-operational",
        type: "circle",
        source: "atlas-v8-repd-operating-assets",
        filter: ["all", ["==", ["get", "tech"], "solar"]],
        layout: { visibility: atlasV8OperatingAssetVisibility["solar_operational"] ? "visible" : "none" },
        paint: {
            "circle-color": "#00ff88",
            "circle-radius": ["interpolate", ["linear"], ["coalesce", ["get", "capacity"], 0], 0, 5, 10, 7, 30, 9, 50, 10, 100, 12, 200, 15, 350, 18, 500, 21],
            "circle-stroke-color": "#111111",
            "circle-stroke-width": 1,
            "circle-opacity": 0.88
        }
    });

    map.addLayer({
        id: "atlas-v8-asset-wind-onshore-operational",
        type: "circle",
        source: "atlas-v8-repd-operating-assets",
        filter: ["all", ["==", ["get", "raw_tech"], "Wind Onshore"]],
        layout: { visibility: atlasV8OperatingAssetVisibility["wind_onshore_operational"] ? "visible" : "none" },
        paint: {
            "circle-color": "#00ffcc",
            "circle-radius": ["interpolate", ["linear"], ["coalesce", ["get", "capacity"], 0], 0, 5, 10, 7, 30, 9, 50, 10, 100, 12, 200, 15, 350, 18, 500, 21],
            "circle-stroke-color": "#111111",
            "circle-stroke-width": 1,
            "circle-opacity": 0.88
        }
    });

    map.addLayer({
        id: "atlas-v8-asset-wind-offshore-operational",
        type: "circle",
        source: "atlas-v8-repd-operating-assets",
        filter: ["all", ["==", ["get", "raw_tech"], "Wind Offshore"]],
        layout: { visibility: atlasV8OperatingAssetVisibility["wind_offshore_operational"] ? "visible" : "none" },
        paint: {
            "circle-color": "#0066ff",
            "circle-radius": ["interpolate", ["linear"], ["coalesce", ["get", "capacity"], 0], 0, 5, 10, 7, 30, 9, 50, 10, 100, 12, 200, 15, 350, 18, 500, 21],
            "circle-stroke-color": "#ffffff",
            "circle-stroke-width": 1,
            "circle-opacity": 0.88
        }
    });

    map.addLayer({
        id: "atlas-v8-asset-bess-operational",
        type: "circle",
        source: "atlas-v8-repd-operating-assets",
        filter: ["all", ["==", ["get", "tech"], "bess"]],
        layout: { visibility: atlasV8OperatingAssetVisibility["bess_operational"] ? "visible" : "none" },
        paint: {
            "circle-color": "#ff69b4",
            "circle-radius": ["interpolate", ["linear"], ["coalesce", ["get", "capacity"], 0], 0, 5, 10, 7, 30, 9, 50, 10, 100, 12, 200, 15, 350, 18, 500, 21],
            "circle-stroke-color": "#111111",
            "circle-stroke-width": 1,
            "circle-opacity": 0.9
        }
    });

    map.addSource("topology", { type: "geojson", data: state.currentGeoJSON });

    map.addLayer({
        id: "overall_boundary_fill", type: "fill", source: "topology",
        filter: ["==", "type", "array_boundary"],
        paint: { "fill-color": "#0066ff", "fill-opacity": 0.25 }
    });
    map.addLayer({
        id: "overall_boundary_line", type: "line", source: "topology",
        filter: ["==", "type", "array_boundary"],
        paint: { "line-color": "#0066ff", "line-width": 2, "line-dasharray": [4, 4] }
    });
    map.addLayer({
        id: "footprints", type: "fill", source: "topology",
        filter: ["in", ["get", "type"], ["literal", ["skid_footprint", "central_footprint", "bess_footprint"]]],
        paint: {
            "fill-color": ["match", ["get", "type"],
                "skid_footprint", "#00ffff", "central_footprint", "#ff9900", "bess_footprint", "#ff00aa", "#000"],
            "fill-opacity": 0.15
        }
    });
    map.addLayer({
        id: "footprints_outline", type: "line", source: "topology",
        filter: ["in", ["get", "type"], ["literal", ["skid_footprint", "central_footprint", "bess_footprint"]]],
        paint: {
            "line-color": ["match", ["get", "type"],
                "skid_footprint", "#00ffff", "central_footprint", "#ff9900", "bess_footprint", "#ff00aa", "#000"],
            "line-width": 1
        }
    });
    map.addLayer({
        id: "export_cable", type: "line", source: "topology",
        filter: ["==", "type", "export_cable"],
        paint: { "line-color": "#ff3333", "line-width": 2, "line-dasharray": [4, 4] }
    });
    map.addLayer({
        id: "radial_spine", type: "line", source: "topology",
        filter: ["==", "type", "33kv_radial"],
        paint: { "line-color": "#00ffff", "line-width": 2 }
    });
    map.addLayer({
        id: "export_cable_pins", type: "circle", source: "topology",
        filter: ["==", "type", "export_cable_pin"],
        paint: {
            "circle-color": ["case", ["==", ["get", "committed_to_route"], true], "#ff3333", "#ff9900"],
            "circle-radius": ["interpolate", ["linear"], ["zoom"], 8, 4, 14, 6, 18, 10],
            "circle-stroke-color": "#ffffff",
            "circle-stroke-width": 1.5,
            "circle-opacity": 0.95
        }
    });
    map.addLayer({
        id: "inverters", type: "circle", source: "topology",
        filter: ["in", ["get", "type"], ["literal", ["string_substation", "central_inverter", "mv_station", "bess_compound"]]],
        paint: {
            "circle-color": ["match", ["get", "type"],
                "string_substation", "#ffff00", "central_inverter", "#ff9900",
                "mv_station", "#6633ff", "bess_compound", "#ff00aa", "#fff"],
            "circle-radius": ["match", ["get", "type"],
                "string_substation", 4, "central_inverter", 6, "mv_station", 4, "bess_compound", 6, 3],
            "circle-stroke-color": "#000", "circle-stroke-width": 1
        }
    });
    map.addLayer({
        id: "substation", type: "circle", source: "topology",
        filter: ["in", ["get", "type"], ["literal", ["poi", "private_sub"]]],
        paint: {
            "circle-color": ["match", ["get", "type"], "poi", "#ff3333", "private_sub", "#00ff88", "#fff"],
            "circle-radius": 8, "circle-stroke-color": "#fff", "circle-stroke-width": 2
        }
    });

    // Map clicks
    map.on("click", "l-subs", onSubstationClick);
    map.on("mouseenter", "l-subs", () => map.getCanvas().style.cursor = "pointer");
    map.on("mouseleave", "l-subs", () => map.getCanvas().style.cursor = "");

    map.on("click", "inverters", onInverterClick);
    map.on("mouseenter", "inverters", () => map.getCanvas().style.cursor = "pointer");
    map.on("mouseleave", "inverters", () => map.getCanvas().style.cursor = "");

    map.on("click", "export_cable_pins", onCableRoutePinClick);
    map.on("mouseenter", "export_cable_pins", () => map.getCanvas().style.cursor = "pointer");
    map.on("mouseleave", "export_cable_pins", () => map.getCanvas().style.cursor = "");

    map.on("click", "substation", onPoiClick);
    map.on("mouseenter", "substation", () => map.getCanvas().style.cursor = "pointer");
    map.on("mouseleave", "substation", () => map.getCanvas().style.cursor = "");

    ["atlas-v8-asset-solar-operational", "atlas-v8-asset-wind-onshore-operational", "atlas-v8-asset-wind-offshore-operational", "atlas-v8-asset-bess-operational"].forEach(layerId => {
        map.on("click", layerId, onOperatingAssetClick);
        map.on("mouseenter", layerId, () => map.getCanvas().style.cursor = "pointer");
        map.on("mouseleave", layerId, () => map.getCanvas().style.cursor = "");
    });

    loadSubstations();
    updateLegend();
    recalcAll();
}

function showPopup(coords, html) {
    if (state.activePopup) state.activePopup.remove();
    state.activePopup = new maplibregl.Popup().setLngLat(coords).setHTML(html).addTo(map);
    state.activePopup.on("close", () => { state.activePopup = null; });
}

// ============================================================
// MAP CLICK HANDLERS
// ============================================================
function onSubstationClick(e) {
    const f = e.features && e.features[0];
    if (!f || !f.geometry) return;
    const coords = f.geometry.coordinates.slice();
    const p = f.properties || {};

    state.selectedSubstation = {
        name: p.name_clean || pickProp(p, ["name","Name","SiteName","Site Name","substation","Substation"], "Selected Substation"),
        voltage: p.voltage_clean || pickProp(p, ["voltage","Voltage","kv","kV","KV"], "Unknown"),
        properties: p,
        coordinates: coords
    };
    state.activeDrawCenter = coords;
    updateSelectedSubstationDisplay();
    computeAndDraw();

    showPopup(coords, `
        <div style="margin-bottom:5px;color:#ff3333;font-weight:bold;font-size:13px;text-transform:uppercase;">Grid Node</div>
        <div class="popup-row"><span>Name:</span><span class="popup-val" style="color:#fff;">${state.selectedSubstation.name}</span></div>
        <div class="popup-row"><span>Voltage:</span><span class="popup-val" style="color:#fff;">${state.selectedSubstation.voltage}</span></div>
        <div class="popup-row"><span>Lon:</span><span class="popup-val" style="color:#fff;">${Number(coords[0]).toFixed(6)}</span></div>
        <div class="popup-row"><span>Lat:</span><span class="popup-val" style="color:#fff;">${Number(coords[1]).toFixed(6)}</span></div>
    `);
}

function onInverterClick(e) {
    const prop = e.features[0].properties;
    const coords = e.features[0].geometry.coordinates.slice();
    const colourMap = {
        central_inverter: "#ff9900", string_substation: "#ffff00",
        bess_compound: "#ff00aa", mv_station: "#6633ff"
    };
    const colour = colourMap[prop.type] || "#00ffff";
    let html = `<div style="margin-bottom:5px;color:${colour};font-weight:bold;font-size:13px;text-transform:uppercase;">Block Info</div>
                <div class="popup-row"><span>Type:</span><span class="popup-val" style="color:#fff;">${prop.type}</span></div>`;
    if (prop.type === "bess_compound" && prop.mwh !== undefined) {
        html += `<div class="popup-row"><span>Capacity:</span><span class="popup-val" style="color:#fff;">${prop.mwh} MWh</span></div>`;
    }
    showPopup(coords, html);
}

function onCableRoutePinClick(e) {
    const prop = e.features[0].properties;
    const coords = e.features[0].geometry.coordinates.slice();
    const idx = prop.pin_index || "?";
    showPopup(coords, `
        <div style="margin-bottom:5px;color:#ff9900;font-weight:bold;font-size:13px;text-transform:uppercase;">Cable Route Pin</div>
        <div class="popup-row"><span>Pin:</span><span class="popup-val" style="color:#fff;">${idx}</span></div>
        <div class="popup-row"><span>Status:</span><span class="popup-val" style="color:#fff;">${prop.committed_to_route ? "Committed to cable route" : "Dropped but not drawn"}</span></div>
        <div class="popup-row"><span>Lon:</span><span class="popup-val" style="color:#fff;">${Number(coords[0]).toFixed(6)}</span></div>
        <div class="popup-row"><span>Lat:</span><span class="popup-val" style="color:#fff;">${Number(coords[1]).toFixed(6)}</span></div>
    `);
}


function onOperatingAssetClick(e) {
    const feature = e.features && e.features[0];
    if (!feature || !feature.geometry) return;
    const prop = feature.properties || {};
    const coords = feature.geometry.coordinates.slice();
    const name = pickProp(prop, ["name", "project", "Project Name", "site", "Site Name", "ref_name"], "Operating asset");
    const tech = pickProp(prop, ["raw_tech", "tech", "technology", "Technology Type"], "Unknown technology");
    const status = pickProp(prop, ["status", "Status"], "Unknown status");
    const capacity = pickProp(prop, ["capacity", "capacity_mw", "Installed Capacity (MWelec)", "Capacity (MW)"], "n/a");
    showPopup(coords, `
        <div style="margin-bottom:5px;color:#00ff88;font-weight:bold;font-size:13px;text-transform:uppercase;">Operating Asset</div>
        <div class="popup-row"><span>Name:</span><span class="popup-val" style="color:#fff;">${name}</span></div>
        <div class="popup-row"><span>Technology:</span><span class="popup-val" style="color:#fff;">${tech}</span></div>
        <div class="popup-row"><span>Status:</span><span class="popup-val" style="color:#fff;">${status}</span></div>
        <div class="popup-row"><span>Capacity:</span><span class="popup-val" style="color:#fff;">${capacity} MW</span></div>
    `);
}

function onPoiClick(e) {
    const prop = e.features[0].properties;
    const coords = e.features[0].geometry.coordinates.slice();
    const title = prop.type === "poi" ? "Point of Interconnection" : "Customer Substation";
    const colour = prop.type === "poi" ? "#ff3333" : "#00ff88";
    let html = `<div style="margin-bottom:5px;color:${colour};font-weight:bold;font-size:13px;text-transform:uppercase;">${title}</div>`;
    if (prop.selected_substation_name) html += `<div class="popup-row"><span>Name:</span><span class="popup-val" style="color:#fff;">${prop.selected_substation_name}</span></div>`;
    if (prop.selected_substation_voltage) html += `<div class="popup-row"><span>Voltage:</span><span class="popup-val" style="color:#fff;">${prop.selected_substation_voltage}</span></div>`;
    showPopup(coords, html);
}

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

GIS Single-Line Diagram (SLD) V5 State

A JavaScript file in the GIS SLD financial sandbox folder of GlobalGrid2050. 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-state.js · lines 1–29 of 29 · 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. State extracted by GridBot feature 004.
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-state.js:1-29 · blob 8c40ef9017a6bdd0ad52aaac6bb847493d266c2b · 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
// State extracted by GridBot feature 004.
// Must load after config and helpers, and before the inline app script.

const state = {
    activeTab: "string",
    currentGeoJSON: { type: "FeatureCollection", features: [] },
    activeDrawCenter: null,
    selectedSubstation: null,
    subsVisible: false,
    satActive: false,
    activePopup: null,
    lastStats: null,
    lastFinance: { fin_string: null, fin_central: null },
    arrayMoveMode: false,
    arrayOverrideCenter: null,
    arrayRotationDeg: 0,
    exportCableLengthKm: 0,
    cableRoutePinMode: false,
    cableRoutePins: [],
    cableRouteCommitted: false,
    suppressNextMapFit: false,
    arrayVisible: true,
    // Legacy aliases retained for older export and drawing logic if needed.
    cableRouteMode: false,
    cableRouteWaypoints: []
};

GIS Single-Line Diagram (SLD) V5 Substations

A JavaScript file in the GIS SLD financial sandbox folder of GlobalGrid2050 that fetches substations. Served with the page at https://globalgrid2050.com/solar-bess-topology-v7/gis-sld-financial-sandbox/. It normalises substations (`normaliseSubstations`) and loads substations (`loadSubstations`).

electricalglobalgrid2050 / solar-bess-topology-v7/gis-sld-financial-sandbox/gis-sld-v5-substations.js · lines 1–83 of 83 · Entry point · pattern normaliseSubstations (shared by 7 files)

What it does
It fetches substations. Defines normaliseSubstations, loadSubstations. Side effects: makes network requests.
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: substations.
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. Substation data loading extracted by GridBot feature 005.
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
normaliseSubstations, loadSubstations
Defines here
normaliseSubstations, loadSubstations
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-substations.js:1-83 · blob 44a84813b68713559e456abd9df4bfa154ff75f2 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: ingest · effects: network · domain stage: experimental · users: ICP_grid_engineer · canonical: production_core
"use strict";

// GIS SLD Financial Sandbox V7
// Substation data loading extracted by GridBot feature 005.
// Must load after config, helpers and state, and before the inline app script.

function normaliseSubstations(raw) {
    if (!raw) throw new Error("Empty dataset");

    let features = [];

    if (raw.type === "FeatureCollection" && Array.isArray(raw.features)) {
        features = raw.features;
    } else if (Array.isArray(raw)) {
        features = raw.map(item => ({
            type: "Feature",
            geometry: item.geometry || {
                type: "Point",
                coordinates: [
                    item.lon ?? item.lng ?? item.longitude ?? item.Longitude ?? item.X,
                    item.lat ?? item.latitude ?? item.Latitude ?? item.Y
                ]
            },
            properties: item.properties || item
        }));
    } else {
        throw new Error("Not a FeatureCollection or array");
    }

    const cleaned = features
        .filter(f => f && f.geometry && f.geometry.type === "Point")
        .map(f => {
            const c = f.geometry.coordinates.map(Number);
            if (!isValidLngLat(c)) return null;

            const p = f.properties || {};

            return {
                type: "Feature",
                geometry: { type: "Point", coordinates: [c[0], c[1]] },
                properties: {
                    ...p,
                    name_clean: pickProp(
                        p,
                        ["name", "Name", "site_name", "SiteName", "Site Name", "substation", "Substation", "substation_name", "Substation Name"],
                        "Substation"
                    ),
                    voltage_clean: pickProp(
                        p,
                        ["voltage", "Voltage", "kv", "kV", "KV", "voltage_kv", "Voltage kV"],
                        "Unknown"
                    )
                }
            };
        })
        .filter(Boolean);

    return { type: "FeatureCollection", features: cleaned };
}

async function loadSubstations() {
    setFetchStatus("Loading substations…", false);

    try {
        const url = SUBSTATIONS_URL + (SUBSTATIONS_URL.includes("?") ? "&" : "?") + "v=" + Date.now();
        const res = await fetch(url);

        if (!res.ok) throw new Error("HTTP " + res.status);

        const raw = await res.json();
        const cleaned = normaliseSubstations(raw);
        const src = map.getSource("src-subs");

        if (src) src.setData(cleaned);

        console.log("Substations loaded:", cleaned.features.length);
        setFetchStatus(`${cleaned.features.length.toLocaleString()} substations loaded`, false);
        setTimeout(() => setFetchStatus("", false), 2500);
    } catch (err) {
        console.error("Substation load failed:", err);
        setFetchStatus(`Substations unavailable: ${err.message}. Check SUBSTATIONS_URL.`, true);
    }
}