Skip to content

Commit 9400b4e

Browse files
perfecto
1 parent 414242b commit 9400b4e

2 files changed

Lines changed: 90 additions & 2 deletions

File tree

dist/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<title>🗺️ MapPornCircleJerk - Create Cursed Maps</title>
88
<meta name="description" content="Color countries however you want and create the most cursed maps the internet has ever seen! No rules, just chaos! 🎨" />
9-
<script type="module" crossorigin src="/assets/index-d0564ca1.js"></script>
9+
<script type="module" crossorigin src="/assets/index-83d59d34.js"></script>
1010
<link rel="stylesheet" href="/assets/index-a2b07217.css">
1111
</head>
1212
<body>
@@ -15,6 +15,6 @@
1515
<div id="map"></div>
1616
</div>
1717

18-
<script defer src="http://cloud.umami.is/script.js" data-website-id="3b3aa24f-7565-42d9-b4f2-f4471bc7039c"></script>
18+
<script defer src="https://cloud.umami.is/script.js" data-website-id="3b3aa24f-7565-42d9-b4f2-f4471bc7039c"></script>
1919
</body>
2020
</html>

src/map/MapManager.ts

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,94 @@ export class MapManager {
175175
}
176176
};
177177

178+
// Patch the _print method to add footer text before converting to blob
179+
const originalPrint = bigImageControl._print.bind(bigImageControl);
180+
bigImageControl._print = function() {
181+
const self = this;
182+
183+
self.tilesImgs = {};
184+
self.markers = {};
185+
self.path = {};
186+
self.circles = {};
187+
188+
let dimensions = self._map.getSize();
189+
190+
self.zoom = self._map.getZoom();
191+
self.bounds = self._map.getPixelBounds();
192+
193+
self.canvas = document.createElement('canvas');
194+
self.canvas.width = dimensions.x;
195+
self.canvas.height = dimensions.y;
196+
self.ctx = self.canvas.getContext('2d');
197+
198+
bigImageControl._changeScale.call(self, document.getElementById('scale').value);
199+
200+
let promise = new Promise(function (resolve, reject) {
201+
bigImageControl._getLayers.call(self, resolve);
202+
});
203+
204+
promise.then(() => {
205+
return new Promise(((resolve, reject) => {
206+
for (const [key, value] of Object.entries(self.tilesImgs)) {
207+
self.ctx.drawImage(value.img, value.x, value.y, self.tileSize, self.tileSize);
208+
}
209+
for (const [key, value] of Object.entries(self.path)) {
210+
bigImageControl._drawPath.call(self, value);
211+
}
212+
for (const [key, value] of Object.entries(self.markers)) {
213+
self.ctx.drawImage(value.img, value.x, value.y);
214+
}
215+
for (const [key, value] of Object.entries(self.circles)) {
216+
bigImageControl._drawCircle.call(self, value);
217+
}
218+
219+
// ADD FOOTER TEXT HERE - after all drawing is complete
220+
const canvas = self.canvas;
221+
const ctx = self.ctx;
222+
223+
// Set text style
224+
const fontSize = Math.max(16, Math.floor(canvas.width / 80)); // Dynamic font size
225+
ctx.font = `${fontSize}px Arial, sans-serif`;
226+
ctx.textAlign = 'center';
227+
ctx.textBaseline = 'bottom';
228+
229+
// Draw text background for better readability
230+
const text = 'Generated by https://mapporncirclejerk.xyz/';
231+
const textMetrics = ctx.measureText(text);
232+
const textWidth = textMetrics.width;
233+
const textHeight = fontSize * 1.5;
234+
const padding = fontSize * 0.5;
235+
236+
const x = canvas.width / 2;
237+
const y = canvas.height - padding;
238+
239+
// Draw semi-transparent background
240+
ctx.fillStyle = 'rgba(255, 255, 255, 0.8)';
241+
ctx.fillRect(
242+
x - textWidth / 2 - padding,
243+
y - textHeight,
244+
textWidth + padding * 2,
245+
textHeight
246+
);
247+
248+
// Draw text
249+
ctx.fillStyle = 'rgba(0, 0, 0, 0.9)';
250+
ctx.fillText(text, x, y - padding / 2);
251+
252+
resolve();
253+
}));
254+
}).then(() => {
255+
self.canvas.toBlob(function (blob) {
256+
let link = document.createElement('a');
257+
link.download = "my-image.png";
258+
link.href = URL.createObjectURL(blob);
259+
link.click();
260+
});
261+
self._containerParams.classList.remove('print-disabled');
262+
self._loader.style.display = 'none';
263+
});
264+
};
265+
178266
// Prepare map for export when export button is clicked
179267
this.map.on('click', (e: L.LeafletMouseEvent) => {
180268
const target = e.originalEvent.target as HTMLElement;

0 commit comments

Comments
 (0)