dok/public/js/map-scale.js
2026-04-10 09:19:21 +01:00

34 lines
900 B
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* ================================================
map-scale.js Skaliert die Worldmap auf den
Viewport (cross-browser: Chrome, Firefox, Safari)
================================================ */
(function () {
const MAP_W = 2037;
const MAP_H = 1018;
function scaleMap() {
const map = document.querySelector(".worldmap");
if (!map) return;
// window.innerWidth/Height = Viewport ohne Scrollbars, konsistent in
// Chrome, Firefox und Safari
const scale = Math.min(
window.innerWidth / MAP_W,
window.innerHeight / MAP_H
);
map.style.transform = `scale(${scale})`;
}
// Beim Laden
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", scaleMap);
} else {
scaleMap();
}
// Bei Größenänderung (z.B. Zoom-Level-Wechsel im Browser)
window.addEventListener("resize", scaleMap);
})();