// ============================================ // LEGEND EXPORT - Legenden SVG/PNG Export // ============================================ function exportLegendSVG() { if (legendItems.length === 0) { showNotification('Legende ist leer', 'error'); return; } const itemHeight = 50; const width = 400; const height = legendItems.length * itemHeight + 60; let svg = ` Legende `; legendItems.forEach((item, index) => { const y = 60 + index * itemHeight; svg += ` ${item.svg.replace(/]*>/, '').replace('', '')} ${escapeHtml(item.name)} ${item.description ? `${escapeHtml(item.description)}` : ''} `; }); svg += ''; const blob = new Blob([svg], { type: 'image/svg+xml' }); const url = URL.createObjectURL(blob); const link = document.createElement('a'); link.href = url; link.download = 'legende.svg'; link.click(); URL.revokeObjectURL(url); showNotification('Legende als SVG exportiert!'); } function exportLegendPNG() { if (legendItems.length === 0) { showNotification('Legende ist leer', 'error'); return; } const itemHeight = 50; const width = 400; const height = legendItems.length * itemHeight + 60; const canvas = document.createElement('canvas'); canvas.width = width * 2; canvas.height = height * 2; const ctx = canvas.getContext('2d'); ctx.scale(2, 2); ctx.fillRect(0, 0, width, height); ctx.fillStyle = '#000'; ctx.font = 'bold 18px Arial'; ctx.fillText('Legende', 20, 30); ctx.strokeStyle = '#ccc'; ctx.beginPath(); ctx.moveTo(20, 40); ctx.lineTo(width - 20, 40); ctx.stroke(); let loadedCount = 0; legendItems.forEach((item, index) => { const y = 60 + index * itemHeight; const img = new Image(); const svgBlob = new Blob([item.svg], { type: 'image/svg+xml' }); img.src = URL.createObjectURL(svgBlob); img.onload = () => { ctx.drawImage(img, 20, y - 5, 32, 32); ctx.fillStyle = '#000'; ctx.font = 'bold 14px Arial'; ctx.fillText(item.name, 60, y + 15); if (item.description) { ctx.fillStyle = '#666'; ctx.font = '11px Arial'; ctx.fillText(item.description, 60, y + 30); } loadedCount++; if (loadedCount === legendItems.length) { canvas.toBlob(blob => { const url = URL.createObjectURL(blob); const link = document.createElement('a'); link.href = url; link.download = 'legende.png'; link.click(); URL.revokeObjectURL(url); showNotification('Legende als PNG exportiert!'); }, 'image/png'); } }; }); }