Map: hide/collapse panels, compact mobile layout, touch pan and pinch zoom

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Maaxxs 2026-09-21 17:10:24 +02:00
parent 85ad31904b
commit 58c4dff016
4 changed files with 265 additions and 9 deletions

View file

@ -2,7 +2,7 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Aion 2 - Interactive Map Viewer</title> <title>Aion 2 - Interactive Map Viewer</title>
<link rel="stylesheet" href="styles.css"> <link rel="stylesheet" href="styles.css">
</head> </head>
@ -31,6 +31,7 @@
<!-- Zoom controls --> <!-- Zoom controls -->
<aside id="zoom-controls" class="panel"> <aside id="zoom-controls" class="panel">
<button id="btn-toggle-ui" title="Fenster aus-/einblenden (H)" aria-pressed="false">👁</button>
<button id="btn-zoom-in" title="Zoom In (+)">+</button> <button id="btn-zoom-in" title="Zoom In (+)">+</button>
<button id="btn-zoom-out" title="Zoom Out (-)">−</button> <button id="btn-zoom-out" title="Zoom Out (-)">−</button>
<button id="btn-reset-view" title="Reset View (0)">⟲</button> <button id="btn-reset-view" title="Reset View (0)">⟲</button>
@ -38,12 +39,17 @@
<!-- Category filter panel --> <!-- Category filter panel -->
<aside id="category-panel" class="panel"> <aside id="category-panel" class="panel">
<div class="tp-head">
<button type="button" class="tp-collapse" id="cp-collapse" title="Ein-/Ausklappen" aria-expanded="true">▾</button>
<h3>Categories</h3> <h3>Categories</h3>
</div>
<div class="cp-body">
<div class="category-bulk"> <div class="category-bulk">
<button type="button" id="btn-show-all">Alle anzeigen</button> <button type="button" id="btn-show-all">Alle anzeigen</button>
<button type="button" id="btn-hide-all">Alle verstecken</button> <button type="button" id="btn-hide-all">Alle verstecken</button>
</div> </div>
<div id="categories-list"></div> <div id="categories-list"></div>
</div>
</aside> </aside>
<!-- Taktiken: Liste, Schritte der gewaehlten Taktik --> <!-- Taktiken: Liste, Schritte der gewaehlten Taktik -->

View file

@ -364,6 +364,9 @@ class MapController {
this.view.isDragging = false; this.view.isDragging = false;
}); });
this.setupTouch();
this.setupPanelToggles();
// Keyboard shortcuts // Keyboard shortcuts
window.addEventListener('keydown', (e) => { window.addEventListener('keydown', (e) => {
if (e.key === '+' || e.key === '=') { if (e.key === '+' || e.key === '=') {
@ -377,6 +380,130 @@ class MapController {
}); });
} }
/**
* Fenster ausblenden: der Augen-Knopf (oder Taste H) blendet alles ausser der
* Zoom-Leiste aus. Die Kategorien lassen sich ausserdem einzeln einklappen. Auf
* schmalen Bildschirmen starten Kategorien und Taktiken eingeklappt, sonst
* verdecken sie fast die ganze Karte.
*/
setupPanelToggles() {
const overlay = document.getElementById('ui-overlay');
const toggleBtn = document.getElementById('btn-toggle-ui');
const setUiHidden = hidden => {
overlay.classList.toggle('ui-hidden', hidden);
toggleBtn.setAttribute('aria-pressed', String(hidden));
this.tooltip.classList.add('hidden');
};
toggleBtn.addEventListener('click', () => setUiHidden(!overlay.classList.contains('ui-hidden')));
window.addEventListener('keydown', (e) => {
const tag = e.target && e.target.tagName;
if (tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT') return;
if (e.key === 'h' || e.key === 'H') setUiHidden(!overlay.classList.contains('ui-hidden'));
});
const panel = document.getElementById('category-panel');
const collapseBtn = document.getElementById('cp-collapse');
collapseBtn.addEventListener('click', () => {
const collapsed = panel.classList.toggle('collapsed');
collapseBtn.textContent = collapsed ? '▸' : '▾';
collapseBtn.setAttribute('aria-expanded', String(!collapsed));
});
if (window.matchMedia('(max-width: 700px)').matches) {
collapseBtn.click();
const tacticCollapse = document.getElementById('tp-collapse');
if (tacticCollapse && tacticCollapse.getAttribute('aria-expanded') === 'true') tacticCollapse.click();
}
}
/**
* Touch: ein Finger verschiebt die Karte, zwei Finger zoomen (Pinch) und verschieben.
* Die Kacheln gibt es nur in ganzen Zoomstufen - deshalb wird eine Stufe gewechselt,
* sobald die Finger sich um einen festen Faktor auseinander- bzw. zusammenbewegt haben.
* Doppeltippen zoomt eine Stufe hinein.
*/
setupTouch() {
const PINCH_STEP = 1.5;
let lastX = 0;
let lastY = 0;
let pinchBase = 0; // Fingerabstand bei der letzten Zoomstufe
let lastTap = 0;
let moved = false;
const midpoint = touches => {
const rect = this.canvas.getBoundingClientRect();
let x = 0;
let y = 0;
for (const t of touches) {
x += t.clientX;
y += t.clientY;
}
return { x: x / touches.length - rect.left, y: y / touches.length - rect.top };
};
const distance = touches => Math.hypot(
touches[0].clientX - touches[1].clientX,
touches[0].clientY - touches[1].clientY
);
const resetTracking = touches => {
const mid = midpoint(touches);
lastX = mid.x;
lastY = mid.y;
pinchBase = touches.length >= 2 ? distance(touches) : 0;
};
this.canvas.addEventListener('touchstart', (e) => {
e.preventDefault();
this.tooltip.classList.add('hidden');
if (e.touches.length === 1) moved = false;
resetTracking(e.touches);
}, { passive: false });
this.canvas.addEventListener('touchmove', (e) => {
e.preventDefault();
const mid = midpoint(e.touches);
const dx = mid.x - lastX;
const dy = mid.y - lastY;
if (Math.abs(dx) + Math.abs(dy) > 2) moved = true;
this.view.panBy(dx, dy);
lastX = mid.x;
lastY = mid.y;
if (e.touches.length >= 2 && pinchBase > 0) {
moved = true;
const ratio = distance(e.touches) / pinchBase;
if (ratio >= PINCH_STEP || ratio <= 1 / PINCH_STEP) {
this.view.zoomAt(ratio > 1 ? 1 : -1, mid.x, mid.y);
pinchBase = distance(e.touches);
this.render();
return;
}
}
this.view.requestRender(this.tileService, this.mapData);
}, { passive: false });
this.canvas.addEventListener('touchend', (e) => {
e.preventDefault();
if (e.touches.length > 0) {
// Ein Finger bleibt liegen: von dort aus ohne Sprung weiterschieben.
resetTracking(e.touches);
return;
}
if (moved || e.changedTouches.length !== 1) return;
const touch = e.changedTouches[0];
const now = Date.now();
if (now - lastTap < 300) {
const rect = this.canvas.getBoundingClientRect();
if (this.view.zoomAt(1, touch.clientX - rect.left, touch.clientY - rect.top)) this.render();
lastTap = 0;
} else {
lastTap = now;
// Antippen zeigt den Namen eines Markers (statt Mauszeiger-Hover).
this.checkHover(touch);
}
}, { passive: false });
}
/** /**
* Check for marker hover and show tooltip * Check for marker hover and show tooltip
*/ */

View file

@ -260,6 +260,20 @@ class MapView {
return false; return false;
} }
/**
* Eine Stufe rein (+1) oder raus (-1) zoomen, wobei der Weltpunkt unter
* screenX/screenY an seiner Stelle bleibt (z.B. zwischen zwei Fingern).
*/
zoomAt(step, screenX, screenY) {
const before = this.screenToWorld(screenX, screenY);
const changed = step > 0 ? this.zoomIn() : this.zoomOut();
if (!changed) return false;
const after = this.screenToWorld(screenX, screenY);
const scale = this.worldToScreen(1, 0).x - this.worldToScreen(0, 0).x;
this.panBy((after.x - before.x) * scale, (after.y - before.y) * scale);
return true;
}
/** /**
* Reset view to default * Reset view to default
*/ */

View file

@ -34,6 +34,8 @@ body {
canvas { canvas {
display: block; display: block;
cursor: grab; cursor: grab;
/* Wischen und Pinch-Zoom steuert die Karte selbst (MapController.setupTouch). */
touch-action: none;
} }
canvas:active { canvas:active {
@ -152,14 +154,42 @@ button:hover {
width: 300px; width: 300px;
} }
#category-panel h3 { #category-panel .tp-head {
font-size: 14px;
color: var(--accent-gold);
margin-bottom: 8px; margin-bottom: 8px;
border-bottom: 1px solid rgba(255, 215, 0, 0.3); border-bottom: 1px solid rgba(255, 215, 0, 0.3);
padding-bottom: 4px; padding-bottom: 4px;
} }
#category-panel h3 {
flex: 1;
font-size: 14px;
color: var(--accent-gold);
}
#category-panel.collapsed {
width: auto;
}
#category-panel.collapsed .tp-head {
margin-bottom: 0;
padding-bottom: 0;
border-bottom: none;
}
#category-panel.collapsed .cp-body {
display: none;
}
/* Fenster ausgeblendet: nur die Zoom-Leiste (mit dem Augen-Knopf) bleibt stehen. */
#ui-overlay.ui-hidden > :not(#zoom-controls) {
display: none !important;
}
#btn-toggle-ui[aria-pressed="true"] {
border-color: var(--accent-gold);
background: rgba(255, 215, 0, 0.2);
}
.category-group { .category-group {
margin-bottom: 12px; margin-bottom: 12px;
} }
@ -735,3 +765,82 @@ button.tp-item.active {
min-width: 180px; min-width: 180px;
} }
} }
/* Handy: Fenster schmal und kompakt, damit von der Karte etwas uebrig bleibt. */
@media (max-width: 700px) {
#title-bar {
top: 8px;
left: 8px;
right: 64px;
padding: 6px 8px;
display: flex;
align-items: center;
gap: 8px;
}
#title-bar h1 {
font-size: 15px;
margin-bottom: 0;
}
.map-selector-container {
flex: 1;
min-width: 0;
}
.map-selector-container select {
width: 100%;
min-width: 0;
padding: 6px 8px;
}
#zoom-controls {
top: 8px;
right: 8px;
padding: 4px;
}
#zoom-controls button {
padding: 6px 10px;
}
#tactic-panel {
top: 60px;
left: 8px;
right: 64px;
width: auto;
max-height: 45%;
padding: 6px 8px;
}
#category-panel {
left: 8px;
bottom: 8px;
width: calc(100% - 16px);
max-height: 45%;
padding: 8px 10px;
}
#category-panel.collapsed {
width: auto;
}
#zoom-indicator {
display: none;
}
#step-bar {
left: 8px;
right: 8px;
bottom: 56px;
width: auto;
min-width: 0;
max-width: none;
}
#toast {
left: 8px;
right: 8px;
bottom: 120px;
}
}