Simplify map zoom with CSS transform instead of canvas resizing
This commit is contained in:
1 parent
368ae69b7e
commit
7e2c7128e5
1 file changed
+14
-17
+14
-17
@@ -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() {
|
||||
|
||||
Reference in new issue
Block a user