Name saved files with county, data type, and data date
This commit is contained in:
+24
-34
@@ -21,6 +21,8 @@ let multiSelectMode = false;
|
||||
|
||||
// Mobile controls state
|
||||
let mobileControlsOpen = false;
|
||||
let loadedCounty = '';
|
||||
let loadedDataType = '';
|
||||
|
||||
// Initialize map
|
||||
function initMap() {
|
||||
@@ -926,6 +928,8 @@ async function loadFiles() {
|
||||
|
||||
const county = document.getElementById('countySelect').value;
|
||||
const dataType = document.getElementById('dataTypeSelect').value;
|
||||
loadedCounty = county;
|
||||
loadedDataType = dataType;
|
||||
|
||||
// Build file paths based on county and data type
|
||||
let osmFile, diffFile, countyFile, diffAddedFile, diffRemovedFile;
|
||||
@@ -1055,43 +1059,29 @@ async function saveAcceptedItems() {
|
||||
}
|
||||
});
|
||||
|
||||
// Create and download added-approved.geojson
|
||||
if (acceptedAdded.length > 0) {
|
||||
const addedData = {
|
||||
type: 'FeatureCollection',
|
||||
features: acceptedAdded
|
||||
};
|
||||
const addedStr = JSON.stringify(addedData, null, 2);
|
||||
const addedBlob = new Blob([addedStr], { type: 'application/json' });
|
||||
const addedUrl = URL.createObjectURL(addedBlob);
|
||||
// Get the date of the loaded data from the server
|
||||
let dataDate = '';
|
||||
try {
|
||||
const dateResp = await fetch('/api/latest-date');
|
||||
if (dateResp.ok) dataDate = (await dateResp.json()).date || '';
|
||||
} catch (_) {}
|
||||
const prefix = [loadedCounty, loadedDataType, dataDate].filter(Boolean).join('-');
|
||||
|
||||
const addedLink = document.createElement('a');
|
||||
addedLink.href = addedUrl;
|
||||
addedLink.download = 'added-approved.geojson';
|
||||
document.body.appendChild(addedLink);
|
||||
addedLink.click();
|
||||
document.body.removeChild(addedLink);
|
||||
URL.revokeObjectURL(addedUrl);
|
||||
function triggerDownload(features, label) {
|
||||
const blob = new Blob([JSON.stringify({ type: 'FeatureCollection', features }, null, 2)],
|
||||
{ type: 'application/json' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = `${prefix}-${label}.geojson`;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
// Create and download removed-approved.geojson
|
||||
if (acceptedRemoved.length > 0) {
|
||||
const removedData = {
|
||||
type: 'FeatureCollection',
|
||||
features: acceptedRemoved
|
||||
};
|
||||
const removedStr = JSON.stringify(removedData, null, 2);
|
||||
const removedBlob = new Blob([removedStr], { type: 'application/json' });
|
||||
const removedUrl = URL.createObjectURL(removedBlob);
|
||||
|
||||
const removedLink = document.createElement('a');
|
||||
removedLink.href = removedUrl;
|
||||
removedLink.download = 'removed-approved.geojson';
|
||||
document.body.appendChild(removedLink);
|
||||
removedLink.click();
|
||||
document.body.removeChild(removedLink);
|
||||
URL.revokeObjectURL(removedUrl);
|
||||
}
|
||||
if (acceptedAdded.length > 0) triggerDownload(acceptedAdded, 'added-approved');
|
||||
if (acceptedRemoved.length > 0) triggerDownload(acceptedRemoved, 'removed-approved');
|
||||
|
||||
showStatus(`Saved ${acceptedAdded.length} added, ${acceptedRemoved.length} removed (approved only)`, 'success');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user