From 7e2c7128e55def69c3c1f145264a86230c6d3f5d Mon Sep 17 00:00:00 2001 From: Sutider Date: Sat, 16 May 2026 14:25:09 +0100 Subject: [PATCH] Simplify map zoom with CSS transform instead of canvas resizing --- templates/map.html | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/templates/map.html b/templates/map.html index c840d92..7b1cd55 100644 --- a/templates/map.html +++ b/templates/map.html @@ -76,6 +76,7 @@ overflow: auto; cursor: grab; position: relative; + z-index: 1; } .map-scroll.dragging { @@ -88,22 +89,23 @@ margin: 24px; background: #0d0f0f; box-shadow: 0 10px 34px rgba(0, 0, 0, 0.35); - overflow: hidden; + display: inline-block; } .map-image { - position: absolute; - inset: 0; + position: relative; width: 100%; height: 100%; object-fit: contain; user-select: none; pointer-events: none; + display: block; + transform-origin: top left; } .map-image-credit { position: absolute; - bottom: 8px; + bottom: 32px; left: 50%; transform: translateX(-50%); font-size: 11px; @@ -534,22 +536,17 @@ function setZoom(nextZoom, keepCenter = true) { const map = selectedMapConfig(); if (!map) return; - const oldZoom = currentZoom; - const viewportCenterX = els.scroll.scrollLeft + els.scroll.clientWidth / 2; - const viewportCenterY = els.scroll.scrollTop + els.scroll.clientHeight / 2; - const relativeX = oldZoom ? viewportCenterX / oldZoom : 0; - const relativeY = oldZoom ? viewportCenterY / oldZoom : 0; - currentZoom = Math.min(3.5, Math.max(0.15, nextZoom)); - els.canvas.style.width = `${map.width * currentZoom}px`; - els.canvas.style.height = `${map.height * currentZoom}px`; + + const scale = currentZoom; + els.canvas.style.transform = `scale(${scale})`; + els.canvas.style.transformOrigin = 'top left'; + els.canvas.style.width = '100%'; + els.canvas.style.height = '100%'; + els.canvas.style.display = 'block'; + els.zoomSlider.value = Math.round(currentZoom * 100); els.zoomReadout.textContent = `${Math.round(currentZoom * 100)}%`; - - if (keepCenter) { - els.scroll.scrollLeft = relativeX * currentZoom - els.scroll.clientWidth / 2; - els.scroll.scrollTop = relativeY * currentZoom - els.scroll.clientHeight / 2; - } } function renderChoices() {