From 3083db603f0eb4d5da7011526e45a6506d8564d6 Mon Sep 17 00:00:00 2001 From: James Smith Date: Mon, 13 Apr 2026 23:27:36 +0100 Subject: [PATCH] refactor(radiosonde): use MapUtils.init + Settings tile layer on sonde map Replace hardcoded L.map() + CartoCD dark tile layer with MapUtils.init() and add tactical overlays. Adds test verifying the cartocdn URL is gone. Co-Authored-By: Claude Sonnet 4.6 --- templates/partials/modes/radiosonde.html | 24 ++++++++++++++++-------- tests/test_map_utils.py | 13 +++++++++++++ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/templates/partials/modes/radiosonde.html b/templates/partials/modes/radiosonde.html index 7726989..c7ff659 100644 --- a/templates/partials/modes/radiosonde.html +++ b/templates/partials/modes/radiosonde.html @@ -278,6 +278,7 @@ // Map management let radiosondeMap = null; + let radiosondeMapOverlays = null; let radiosondeMarkers = new Map(); let radiosondeTracks = new Map(); let radiosondeTrackPoints = new Map(); @@ -295,16 +296,23 @@ } const hasLocation = radiosondeStationLocation.lat !== 0 || radiosondeStationLocation.lon !== 0; - radiosondeMap = L.map('radiosondeMapContainer', { - center: hasLocation ? [radiosondeStationLocation.lat, radiosondeStationLocation.lon] : [40, -95], - zoom: hasLocation ? 7 : 4, - zoomControl: true, - }); + const observerLocation = hasLocation + ? { lat: radiosondeStationLocation.lat, lon: radiosondeStationLocation.lon } + : { lat: 40, lon: -95 }; - L.tileLayer('https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png', { - attribution: '© OpenStreetMap © CARTO', + radiosondeMap = MapUtils.init('radiosondeMapContainer', { + center: [observerLocation.lat, observerLocation.lon], + zoom: hasLocation ? 7 : 4, + minZoom: 2, maxZoom: 18, - }).addTo(radiosondeMap); + }); + if (radiosondeMap) { + window.radiosondeMap = radiosondeMap; + radiosondeMapOverlays = MapUtils.addTacticalOverlays(radiosondeMap, { + hudPanels: { modeName: 'RADIOSONDE', getContactCount: () => 0 }, + scaleBar: true, + }); + } // Add station marker if we have a location if (hasLocation) { diff --git a/tests/test_map_utils.py b/tests/test_map_utils.py index 8a0660f..8fa0f15 100644 --- a/tests/test_map_utils.py +++ b/tests/test_map_utils.py @@ -62,3 +62,16 @@ def test_index_includes_map_utils(client): html = resp.data.decode() assert "map-utils.js" in html assert "MapUtils.init" in html + + +def test_radiosonde_mode_uses_map_utils(client): + """Main SPA index (which includes radiosonde partial) uses MapUtils for radiosonde map.""" + with client.session_transaction() as sess: + sess["logged_in"] = True + resp = client.get("/") + assert resp.status_code == 200 + html = resp.data.decode() + # Radiosonde map init in partial should call MapUtils.init, not bare L.tileLayer + assert "radiosondeMap" in html + # The bare cartocdn URL that was previously hardcoded should be gone + assert "basemaps.cartocdn.com/dark_all" not in html or html.count("basemaps.cartocdn.com/dark_all") == 0