Skip to content

Commit 4ee5b30

Browse files
authored
Merge pull request #35 from E4Warning/copilot/fix-spain-training-data-map
2 parents 02625d8 + ff0854a commit 4ee5b30

1 file changed

Lines changed: 22 additions & 4 deletions

File tree

js/app.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@ function setupLayerControls() {
236236
const datePicker = document.getElementById('data-date-picker');
237237
const dateToLoad = datePicker && datePicker.value ? datePicker.value : new Date().toISOString().split('T')[0];
238238
await loadSpainMosquitoAlertData(dateToLoad, this.value);
239-
if (mapManager.currentRegion === 'spain' && CONFIG.regions.spain?.dataSources?.mosquitoAlertES?.observationsUrl) {
239+
// For grid model, load observations here (municipalities model loads in map's load handler)
240+
if (this.value === 'mosquito-alert-grid' && CONFIG.regions.spain?.dataSources?.mosquitoAlertES?.observationsUrl) {
240241
await loadObservationOverlay('spain');
241242
}
242243
});
@@ -469,8 +470,10 @@ async function showRegion(regionKey) {
469470
await loadObservationOverlay('barcelona');
470471
}
471472
} else if (regionKey === 'spain') {
472-
await loadSpainMosquitoAlertData(this.value, getSelectedModel());
473-
if (CONFIG.regions.spain?.dataSources?.mosquitoAlertES?.observationsUrl) {
473+
const selectedModel = getSelectedModel();
474+
await loadSpainMosquitoAlertData(this.value, selectedModel);
475+
// For grid model, load observations here (municipalities model loads in map's load handler)
476+
if (selectedModel === 'mosquito-alert-grid' && CONFIG.regions.spain?.dataSources?.mosquitoAlertES?.observationsUrl) {
474477
await loadObservationOverlay('spain');
475478
}
476479
}
@@ -518,7 +521,15 @@ async function showRegion(regionKey) {
518521
}
519522

520523
if (supportsObservations) {
521-
await loadObservationOverlay(regionKey);
524+
// For Spain with municipalities model, observations are loaded in the Mapbox map's load handler
525+
// For other regions and Spain grid model, load observations here
526+
const isSpainMunicipalities = regionKey === 'spain' &&
527+
region.dataSources.mosquitoAlertES &&
528+
region.dataSources.mosquitoAlertES.enabled &&
529+
selectedModel === 'mosquito-alert-municipalities';
530+
if (!isSpainMunicipalities) {
531+
await loadObservationOverlay(regionKey);
532+
}
522533
}
523534

524535
mapManager.toggleLayer('risk', riskLayerCheckbox ? riskLayerCheckbox.checked : true);
@@ -852,6 +863,13 @@ async function loadSpainMosquitoAlertData(date, modelSelection = 'mosquito-alert
852863
<p><strong>Avg VRI:</strong> ${avgRisk.toFixed(3)}</p>
853864
`;
854865
}
866+
867+
// Load observations after map is ready
868+
if (CONFIG.regions.spain?.dataSources?.mosquitoAlertES?.observationsUrl) {
869+
loadObservationOverlay('spain').catch(err => {
870+
console.error('Failed to load observations:', err);
871+
});
872+
}
855873
});
856874
} else {
857875
// Fallback message if Mapbox not available

0 commit comments

Comments
 (0)