Atlaslog
Atlaslog / Field Notes / Loading & display
Field note · Loading & display

Tiles return 404 or are blocked by CORS

Quick answer

The basemap shows grey squares because requests fail: 404 from a bad URL template or a swapped y-axis, 403 from an invalid key or referer, or CORS when crossOrigin is enabled for canvas export.

Last verified 2026-11-03 · Multiple versions · Cite this page
Applies to: Leaflet · OpenLayers · Cesium
Symptom
Checklist
  1. Read the status code first and classify 404, 403 or CORS.
  2. Open one tile URL directly in the browser to test whether the address itself is valid.
  3. For 404, check {z}/{x}/{y} order (some services use {z}/{y}/{x}) and the y-axis flip ({-y} in Leaflet, a custom tileUrlFunction in OpenLayers).
  4. For 403, check the key, the domain whitelist (localhost and file:// are often rejected), the daily quota and the HTTPS requirement.
  5. For CORS, confirm whether crossOrigin is only needed for toDataURL export and remove it otherwise.
Fix

Correct the URL template and y-flip, whitelist the domain or renew the key, and enable crossOrigin only when the canvas must be exported. Add a tileerror handler so failures surface to users instead of leaving grey blocks.

Code
'https://tile.openstreetmap.org/{z}/{x}/{y}.png'
'{z}/{x}/{-y}.png'
L.tileLayer(url, {
  crossOrigin: 'anonymous'
}).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). Tiles return 404 or are blocked by CORS. https://www.jingweizhi.com/en/cookbook/tile-404-cors.html (accessed 2026-11-03).