aboutsummaryrefslogtreecommitdiffstats
path: root/src/scripts/functionality/sheet-map/download-map-pdf-page-content.html
blob: 4d698ef6e4437b708df040ab901263bf3702b164 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<style>
	body {
		margin: 0;
		padding: 0;
	}
	svg {
		display: block;
		max-width: 100%;
		max-height: 100%;
	}
	text {
		font-family: "BNB-TTBidisha", sans-serif;
		font-weight: bold;
		font-size: 2;
		fill: blue;
		text-anchor: middle;
	}
	path {
		fill-rule: evenodd;
		fill: #ffcc66;
		fill-opacity: 0.8;
		stroke: #cc6633;
		stroke-opacity: 0.8;
		stroke-width: 0.2;
		stroke-linecap: round;
		stroke-linejoin: round;
	}
</style>
<svg>
	$mapContent$
</svg>
<script>
	let minx = Infinity;
	let miny = Infinity;
	let maxx = 0;
	let maxy = 0;
	const paths = document.querySelectorAll("path");

	for (const p of paths) {
		const b = p.getBBox();
		minx = b.x < minx ? b.x : minx;
		miny = b.y < miny ? b.y : miny;
		maxx = maxx < b.x + b.width ? b.x + b.width : maxx;
		maxy = maxy < b.y + b.height ? b.y + b.height : maxy;
	}

	for (const p of paths) {
		const m = "M " + p.getAttribute("d").substr(2).split(",").map(cood => {
			cood = cood.trim().split(" ");
			return cood[0] + " " + (miny + maxy - parseFloat(cood[1])).toString();
		}).join(", ");
		p.setAttribute("d", m);
	}

	for (const t of document.querySelectorAll("text")) {
		t.setAttribute("y", (miny + maxy - parseFloat(t.getAttribute("y"))).toString());
	}

	document.querySelector("svg")
		.setAttribute(
			"viewBox",
			[minx, miny, maxx - minx, maxy - miny]
				.map(e => e.toString()).join(" ")
		);
	window.addEventListener("afterprint", window.close);
	window.print();
</script>