Render from a denser pyramid level to fix soft tiles
Leaflet chooses its tile level with Math.round(mapZoom), so the default fit view at zoom 2.25 took level 2 and stretched it 1.19x. With a devicePixelRatio of 1.5 that compounded to a 1.78x upscale of every source pixel. DENSITY_BOOST halves a tile's CSS size and adds a matching zoomOffset, so Leaflet downscales a denser level instead of upscaling a coarser one. The per-cell tile offset is now derived from baseTileSize rather than assuming 2**z, so the world-grid translation stays exact under the boost. Source pixels per device pixel at DPR 1.5, higher being sharper: view zoom 0-4 0.56 -> 1.33 view zoom 5 0.67 (unchanged; this is the 1:1 source level) Costs ~4x the tiles in view, ~17 KB each, cached for a week. z5 is a genuine ceiling: the embedded terrain smart object is a PSB of exactly 7832x3720 placed 1:1, so no further source detail exists. Verified zoom 0-7: zero broken tiles. Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
1 parent
6c2bd6d27b
commit
f997c2c5e2
4 files changed
+73
-13
No files matched your search
@@ -124,7 +124,8 @@ sources/ build/ web/tiles/ gitignored
|
||||
| --- | --- | --- |
|
||||
| psd-tools fills stroke-only vector `shape` layers as solid colour | Customs rendered white over the whole playable area until `Map Borders` was excluded | Worked around via `excludeLayers`; documented as a check in the runbook |
|
||||
| Excluding `Map Borders` also removes the playable-area boundary outline | Customs no longer shows the dotted play-area edge; the out-of-bounds grey-out still marks it | Accepted. Revisit only if the boundary is missed |
|
||||
| No retina / DPR-2 tiles | Slightly soft on high-DPI phones at 1:1 | Stage 7 |
|
||||
| ~~No retina / DPR tiles~~ | ~~Soft on high-DPI screens~~ | **Fixed** — `DENSITY_BOOST` requests one level deeper; 0.56 → 1.33 source px per device px at DPR 1.5 |
|
||||
| z5 is a hard detail ceiling | Upscaling past zoom 5 is browser-side and blurry | Inherent. The embedded terrain smart object is 7832 × 3720 placed 1:1, so there is no further source detail to extract |
|
||||
| `flyToBounds` depends on `requestAnimationFrame` | Picker doesn't move the view in a non-compositing tab | Cosmetic; not seen in a real browser |
|
||||
| Dorms has no scale bar | No px/m for that map | Fine — `pxPerMeter` is optional |
|
||||
|
||||
@@ -197,7 +198,7 @@ sources/ build/ web/tiles/ gitignored
|
||||
- [x] Collapsible picker; zoom buttons hidden under 640 px in favour of pinch
|
||||
- [ ] **Test on a real iOS Safari and a real Android Chrome over LAN** — nothing here is proven until this happens
|
||||
- [ ] Check pinch, double-tap and inertial pan don't fight page scroll
|
||||
- [ ] Decide on retina: one extra zoom level vs. `@2x` tiles vs. accept
|
||||
- [x] Retina decided: `DENSITY_BOOST` requests one pyramid level deeper instead of shipping `@2x` tiles — no extra build output, fixes fractional-zoom softness too
|
||||
- [ ] First-paint budget on LAN (target ~2 s)
|
||||
|
||||
#### Stage 8 — Third map by someone else
|
||||
|
||||
@@ -85,6 +85,34 @@ up front (z3 is 49 tiles / 471 KB) — z2 is the sweet spot.
|
||||
| Customs | 7832 × 5016 | 7832 × 3015 | 503 (8.4 MB) |
|
||||
| Customs — Dorms | 4301 × 4904 | 4301 × 4904 | 469 (1.4 MB) |
|
||||
|
||||
## Tile resolution and sharpness
|
||||
|
||||
`maxZoom` is derived from the largest map: `ceil(log2(7832 / 256)) = 5`. At z5
|
||||
one source pixel is one CSS pixel, and z5 *is* the full PSD — verified by
|
||||
reading the embedded terrain smart object, which is exactly 7832 × 3720 placed
|
||||
1:1. There is no hidden detail to recover, so z5 is a hard ceiling.
|
||||
|
||||
Sharpness is therefore about **level selection**, not pyramid depth. Leaflet
|
||||
picks its level with `Math.round(mapZoom)`, so at zoom 2.25 it takes level 2 and
|
||||
stretches it 1.19×. On a 150 %-scaled Windows display (`devicePixelRatio` 1.5)
|
||||
that compounds to a **1.78× upscale** — visibly soft.
|
||||
|
||||
`DENSITY_BOOST` in `app.js` fixes it: halve the CSS size of a tile and request
|
||||
one level deeper, so we downscale a denser level instead of upscaling a coarser
|
||||
one. Measured at `devicePixelRatio` 1.5, in source pixels delivered per device
|
||||
pixel (higher is sharper, 1.0 is pixel-perfect):
|
||||
|
||||
| View zoom | Before | After |
|
||||
| --- | --- | --- |
|
||||
| 0–4 | 0.56 | **1.33** |
|
||||
| 5 (1:1 source) | 0.67 | 0.67 |
|
||||
|
||||
It costs ~4× the tiles in view (99 at the busiest level on a 1315 px viewport,
|
||||
~17 KB each). Cached for a week and served by Caddy, that is a fair trade.
|
||||
|
||||
At z5 and beyond you are past the source resolution and the browser upscales —
|
||||
unavoidable, and `ZOOM_HEADROOM` deliberately allows two levels of it.
|
||||
|
||||
## Serving
|
||||
|
||||
Two options, both driven by `server/run.ps1`:
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.3 MiB |
+42
-11
@@ -9,15 +9,37 @@
|
||||
*/
|
||||
|
||||
const ZOOM_HEADROOM = 2; // how far past 1:1 the user may zoom
|
||||
const ZOOM_SNAP = 0.25;
|
||||
const BLANK = 'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=';
|
||||
|
||||
/* Pixel density.
|
||||
*
|
||||
* Leaflet picks its tile level with Math.round(mapZoom), so at zoom 2.25 it
|
||||
* takes level 2 and stretches it 1.19x. Multiply that by a devicePixelRatio
|
||||
* of 1.5 and each source pixel covers ~1.8 device pixels -- visibly soft.
|
||||
*
|
||||
* DENSITY_BOOST fixes it by halving the CSS size of a tile and asking for one
|
||||
* level deeper, so we downscale a denser level instead of upscaling a coarser
|
||||
* one. Costs ~4x the tiles in view, which at ~17 KB each is a fair trade.
|
||||
*
|
||||
* Worth it whenever the screen is not 1:1, or whenever fractional zoom can
|
||||
* land us between levels. Both are true almost everywhere.
|
||||
*/
|
||||
const DENSITY_BOOST =
|
||||
(window.devicePixelRatio > 1.05 || ZOOM_SNAP < 1) ? 1 : 0;
|
||||
|
||||
const OffsetTileLayer = L.TileLayer.extend({
|
||||
getTileUrl(coords) {
|
||||
const n = 2 ** coords.z;
|
||||
// Tiles are numbered from each map's own top-left corner, so shift world
|
||||
// tile coordinates into the map's local grid. A grid cell spans
|
||||
// baseTileSize * 2**z pixels at this level; divided by the layer's own
|
||||
// tile size that is always a whole number of tiles, boost or no boost.
|
||||
const o = this.options;
|
||||
const perCell = (o.baseTileSize * 2 ** coords.z) / o.tileSize;
|
||||
return L.Util.template(this._url, {
|
||||
z: coords.z,
|
||||
x: coords.x - this.options.cell[0] * n,
|
||||
y: coords.y - this.options.cell[1] * n,
|
||||
z: coords.z + o.zoomOffset,
|
||||
x: coords.x - o.cell[0] * perCell,
|
||||
y: coords.y - o.cell[1] * perCell,
|
||||
});
|
||||
},
|
||||
});
|
||||
@@ -60,7 +82,7 @@ async function main() {
|
||||
crs: CRS,
|
||||
minZoom: 0,
|
||||
maxZoom: ZMAX + ZOOM_HEADROOM,
|
||||
zoomSnap: 0.25,
|
||||
zoomSnap: ZOOM_SNAP,
|
||||
zoomDelta: 0.5,
|
||||
wheelPxPerZoomLevel: 90,
|
||||
maxBounds: extent.pad(0.08),
|
||||
@@ -74,12 +96,18 @@ async function main() {
|
||||
|
||||
const UNDERLAY_Z = Math.min(world.underlayZoom ?? 2, ZMAX);
|
||||
|
||||
// With the boost on, a level-N request is served by the level-(N+1) files,
|
||||
// so the deepest level we may ask Leaflet for is one shallower.
|
||||
const boost = Math.min(DENSITY_BOOST, ZMAX, UNDERLAY_Z);
|
||||
|
||||
for (const m of world.maps) {
|
||||
const url = `tiles/${m.id}/{z}/{x}/{y}.webp`;
|
||||
const common = {
|
||||
cell: m.cell,
|
||||
bounds: rectOf(m),
|
||||
tileSize: world.tileSize,
|
||||
baseTileSize: world.tileSize,
|
||||
tileSize: world.tileSize / 2 ** boost,
|
||||
zoomOffset: boost,
|
||||
minZoom: 0,
|
||||
maxZoom: ZMAX + ZOOM_HEADROOM,
|
||||
noWrap: true,
|
||||
@@ -93,9 +121,9 @@ async function main() {
|
||||
// blurry map instead of the page background.
|
||||
new OffsetTileLayer(url, {
|
||||
...common,
|
||||
minNativeZoom: UNDERLAY_Z,
|
||||
maxNativeZoom: UNDERLAY_Z,
|
||||
keepBuffer: 8,
|
||||
minNativeZoom: UNDERLAY_Z - boost,
|
||||
maxNativeZoom: UNDERLAY_Z - boost,
|
||||
keepBuffer: 8 * 2 ** boost,
|
||||
updateWhenIdle: false,
|
||||
updateWhenZooming: false,
|
||||
zIndex: 1,
|
||||
@@ -104,8 +132,11 @@ async function main() {
|
||||
|
||||
new OffsetTileLayer(url, {
|
||||
...common,
|
||||
maxNativeZoom: ZMAX,
|
||||
keepBuffer: 3,
|
||||
maxNativeZoom: ZMAX - boost,
|
||||
// Small on purpose: boosted tiles are half-size, so a wide buffer costs
|
||||
// 4x the requests, and the underlay already covers anything a pan
|
||||
// outruns.
|
||||
keepBuffer: 2,
|
||||
updateWhenIdle: false,
|
||||
zIndex: 2,
|
||||
}).addTo(map);
|
||||
|
||||
Reference in new issue
Block a user