This commit is contained in:
Tykayn 2025-10-03 14:00:35 +02:00 committed by tykayn
parent f991aee8ed
commit bdb3728494
13 changed files with 283 additions and 20 deletions

View file

@ -19,6 +19,7 @@ export class Home {
OedbApi = inject(OedbApi);
features: Array<any> = [];
selected: any | null = null;
showTable = false;
constructor() {
this.OedbApi.getEvents({ when: 'now', limit: 500 }).subscribe((events: any) => {
@ -68,4 +69,49 @@ export class Home {
this.features = Array.isArray(events?.features) ? events.features : [];
});
}
// Menu callbacks
ngAfterViewInit() {
// Wire menu callbacks if needed via querySelector; left simple for now
// We keep logic here: toggling and downloads
}
toggleView() {
this.showTable = !this.showTable;
}
downloadGeoJSON() {
const blob = new Blob([JSON.stringify({ type: 'FeatureCollection', features: this.features }, null, 2)], { type: 'application/geo+json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'events.geojson';
document.body.appendChild(a);
a.click();
URL.revokeObjectURL(url);
a.remove();
}
downloadCSV() {
const header = ['id', 'what', 'label', 'start', 'stop', 'lon', 'lat'];
const rows = this.features.map((f: any) => [
JSON.stringify(f?.properties?.id ?? f?.id ?? ''),
JSON.stringify(f?.properties?.what ?? ''),
JSON.stringify(f?.properties?.label ?? f?.properties?.name ?? ''),
JSON.stringify(f?.properties?.start ?? f?.properties?.when ?? ''),
JSON.stringify(f?.properties?.stop ?? ''),
JSON.stringify(f?.geometry?.coordinates?.[0] ?? ''),
JSON.stringify(f?.geometry?.coordinates?.[1] ?? '')
].join(','));
const csv = [header.join(','), ...rows].join('\n');
const blob = new Blob([csv], { type: 'text/csv' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'events.csv';
document.body.appendChild(a);
a.click();
URL.revokeObjectURL(url);
a.remove();
}
}