Added metadata export

+Added basic metadata to the exported svg
This commit is contained in:
izawartka 2025-08-17 18:04:01 +02:00
parent 6a04b5feec
commit cfe28689ff
2 changed files with 21 additions and 2 deletions

View File

@ -1,5 +1,6 @@
const Constants = { const Constants = {
buildVersion: '1.6.2', buildVersion: '1.6.2',
originalPublicBuildUrl: 'https://maseuko.pl/soft/td2-visualizer-2/', // do NOT change
map: { map: {
zoomSensitivity: 0.002, zoomSensitivity: 0.002,
zoomMin: 0.03, zoomMin: 0.03,

View File

@ -1,3 +1,5 @@
import Constants from "./constants";
const applyStyles = ['fill', 'stroke', 'stroke-width', 'font-size', 'font-family', 'text-anchor', 'dominant-baseline']; const applyStyles = ['fill', 'stroke', 'stroke-width', 'font-size', 'font-family', 'text-anchor', 'dominant-baseline'];
function processExportNode(svgNode, currentGroupStyles = {}) { function processExportNode(svgNode, currentGroupStyles = {}) {
@ -105,6 +107,23 @@ function serializeAndDownload(svgNode, filename) {
URL.revokeObjectURL(url); URL.revokeObjectURL(url);
} }
function addMetadata(svg) {
const metadata = document.createElementNS('http://www.w3.org/2000/svg', 'metadata');
const rdf = document.createElementNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'rdf:RDF');
const description = document.createElementNS('http://purl.org/dc/elements/1.1/', 'dc:description');
description.textContent = `Exported using TD2 Visualizer v${Constants.buildVersion}`;
const source = document.createElementNS('http://purl.org/dc/elements/1.1/', 'dc:source');
source.textContent = Constants.originalPublicBuildUrl;
rdf.appendChild(description);
rdf.appendChild(source);
metadata.appendChild(rdf);
svg.appendChild(metadata);
svg.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
svg.setAttribute('version', '1.1');
}
function exportSvg(filename) { function exportSvg(filename) {
const mapElement = document.getElementsByClassName('map')[0]; const mapElement = document.getElementsByClassName('map')[0];
if (!mapElement) return false; if (!mapElement) return false;
@ -119,8 +138,7 @@ function exportSvg(filename) {
mapElement.appendChild(exportContainer); mapElement.appendChild(exportContainer);
exportContainer.appendChild(svg); exportContainer.appendChild(svg);
svg.setAttribute('xmlns', 'http://www.w3.org/2000/svg'); addMetadata(svg);
svg.setAttribute('version', '1.1');
processExportNode(svg); processExportNode(svg);
removeNonVisibleObjects(svg); removeNonVisibleObjects(svg);