From c1dacc66880471ec436399863694268fb6083360 Mon Sep 17 00:00:00 2001 From: Maaxxs <61059039+MaaxxsDev@users.noreply.github.com> Date: Sun, 20 Sep 2026 15:10:07 +0200 Subject: [PATCH] Karte: allow zooming past the deepest tile level The map's zoom was capped at the deepest level that has tiles, which leaves almost no room on a shallow pyramid: a 1024px map only has levels 0 to 2, so fitBounds already landed at the maximum and the zoom-in button was disabled from the moment the page loaded. Reproduced against a copy of the live map (1024x1024, max_zoom 2): zoom-in disabled on load, clicking it did nothing. The tile layer now declares maxNativeZoom as the deepest level that really exists, and the map may zoom two levels beyond it - Leaflet scales those tiles up instead of requesting levels that would 404. Verified across the range: level 1 at zoom 1.25, native level 2 at zoom 2, and the same level 2 tiles upscaled to 362/512/724/1024px at zoom 2.5 through 4, with no request for the non-existent level 3. This also removes detectRetina, which made the problem worse rather than better: it costs a zoom level of magnification, not just resolution, so on a high-density display a three-level map lost a third of its already minimal range. tools/tile_viewer.html had the same constraint one level up and now allows two levels past native as well. Co-Authored-By: Claude Opus 5 --- assets/js/map.js | 19 ++++++++++--------- tools/tile_viewer.html | 9 +++++---- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/assets/js/map.js b/assets/js/map.js index 6eca3d2..8455522 100644 --- a/assets/js/map.js +++ b/assets/js/map.js @@ -36,13 +36,12 @@ // die maximale Zoomstufe in Leaflet-Koordinaten uebersetzt - dadurch bleiben // sie auch dann richtig, wenn die Karte spaeter neu gekachelt wird. // --------------------------------------------------------------------- - // Auf Bildschirmen mit hoher Pixeldichte (Retina, 4K-Laptops, Handys) entspricht ein - // CSS-Pixel mehreren echten Pixeln - die oberste Zoomstufe wuerde dort hochskaliert und - // damit unscharf. Leaflet holt mit detectRetina stattdessen die naechsthoehere - // Kachelstufe und zeichnet sie halb so gross: gleiche Vergroesserung, aber pixelgenau. - // Dafuer steht eine Zoomstufe weniger zur Verfuegung, deshalb hier abgezogen. - var retina = L.Browser.retina && manifest.max_zoom > manifest.min_zoom; - var mapMaxZoom = retina ? manifest.max_zoom - 1 : manifest.max_zoom; + // Ueber die tiefste vorhandene Kachelebene hinaus darf weiter gezoomt werden; dort + // vergroessert Leaflet die tiefsten Kacheln (etwas weicher, aber man kommt naeher + // heran). Ohne das waere bei einer flachen Pyramide - eine 1024er-Karte hat nur die + // Stufen 0 bis 2 - schon die Startansicht am Anschlag und Hineinzoomen unmoeglich. + var EXTRA_ZOOM = 2; + var mapMaxZoom = manifest.max_zoom + EXTRA_ZOOM; var map = L.map('map-canvas', { crs: L.CRS.Simple, @@ -86,8 +85,10 @@ L.tileLayer(manifest.url_template, { tileSize: manifest.tile_size, minZoom: manifest.min_zoom, - maxZoom: manifest.max_zoom, - detectRetina: true, + maxZoom: mapMaxZoom, + // Bis hierher gibt es wirklich Kacheln - alles darueber wird aus dieser Stufe + // hochskaliert, statt Kacheln anzufordern, die es nicht gibt. + maxNativeZoom: manifest.max_zoom, bounds: bounds, noWrap: true, // Randkacheln jenseits des Bildes gibt es nicht - statt eines kaputten diff --git a/tools/tile_viewer.html b/tools/tile_viewer.html index 55e9e8d..53b242e 100644 --- a/tools/tile_viewer.html +++ b/tools/tile_viewer.html @@ -234,13 +234,14 @@ function screenToWorldY(sy) { return (sy - viewH / 2) / k + camY; } * Auf Ebene z deckt ein Bildpixel 2^(ZMAX-z) Weltpixel ab, nativ gilt also * k * dpr * 2^(ZMAX-z) = 1. Fuer die hoechste Ebene (z = ZMAX) heisst das k = 1/dpr. * - * Laut Vorgabe darf der Nutzer die nutzbare Detailspanne um hoechstens eine Ebene - * verlassen: nach oben also eine Verdopplung ueber nativ hinaus, nach unten eine - * Halbierung unter "ganze Welt passt ins Fenster". + * Nach oben sind zwei Ebenen ueber nativ erlaubt (vierfache Vergroesserung), nach unten + * eine Halbierung unter "ganze Welt passt ins Fenster". Zwei statt einer Ebene deshalb, + * weil flache Pyramiden sonst kaum Spielraum lassen: eine 1024er-Karte hat nur die + * Stufen 0 bis 2, da waere die Startansicht schon fast am Anschlag. */ function scaleBounds() { const fit = Math.min(viewW, viewH) / WORLD; - return { min: fit / 2, max: 2 / dpr }; + return { min: fit / 2, max: 4 / dpr }; } function clampScale(value) {