Atlaslog
Atlaslog / Field Notes / Tiles
Field note · Tiles

TMS tiles render upside down because the Y axis counts from the bottom

Quick answer

Every tile loads and the mosaic is seamless, but the whole map is flipped vertically: at z18 Beijing lands in the southern hemisphere while east-west orientation is correct. The directory uses TMS numbering while the client requests XYZ.

Last verified 2026-11-03 · Multiple versions · Cite this page
Applies to: Leaflet 1.9.x / OpenLayers 9.x / GeoServer GWC
Symptom
Checklist
  1. Open one tile of known location and back-compute its lat/lng to see whether north and south are swapped
  2. Read the top row's y value: close to 2^z indicates TMS numbering
  3. Check the service documentation; GeoServer GWC exposes both `/gwc/service/tms/1.0.0` and XYZ
  4. Request `y=0` and `y=2^z-1` manually and see which one is the south pole
  5. Apply `y_tms = 2^z - 1 - y_xyz` and reload
Fix

Use Leaflet's `{-y}` placeholder (`L.tileLayer('/tiles/{z}/{x}/{-y}.png')`), or in OpenLayers flip inside `tileUrlFunction`: `const n = Math.pow(2, z); return '/tiles/' + z + '/' + x + '/' + (n - 1 - y) + '.png'`.

Code
const z = 18, n = Math.pow(2, z);     // 262144
const yXyz = 105000;
const yTms = n - 1 - yXyz;            // 157143
L.tileLayer('/tiles/{z}/{x}/{-y}.png', {
  tileSize: 256,
  minZoom: 3,
  maxZoom: 18,
  tms: false
}).addTo(map);
L.tileLayer('/tiles/{z}/{x}/{y}.png', { tileSize: 256 }).addTo(map);
Watch out
All 120 field notesChinese originalRunnable examples
English edition written for Atlaslog from the original Chinese field note. Code is unchanged and runs as-is.
Cite this page

Atlaslog (2026). TMS tiles render upside down because the Y axis counts from the bottom. https://www.jingweizhi.com/en/cookbook/tms-y-flip.html (accessed 2026-11-03).