Atlaslog
Atlaslog / Field Notes / MapLibre styles & layers
Field note · MapLibre styles & layers

Custom marker icons 404 and symbols render blank

Quick answer

The symbol layer references icon-image but every icon request returns 404, so markers show nothing or a placeholder square. Causes are a relative path breaking under a sub-route, registration before decode, or a missing @2x asset.

Last verified 2026-11-03 · Multiple versions · Cite this page
Applies to: MapLibre GL JS
Symptom
Checklist
  1. Load the image in a plain Image object and print width and height to confirm the URL.
  2. Check map.hasImage('pin') after registration.
  3. Verify the page base path, since ./icons/pin.png under /project/detail resolves to /project/icons/pin.png.
  4. Check pixelRatio and whether an @2x asset exists.
Fix

Use map.loadImage for both 1x and 2x, then map.addImage('pin', image.data, { pixelRatio: 1 }) and pixelRatio 2 before creating the symbol layer, building URLs from an absolute ICON_BASE.

Code
Uncaught Error: Could not load image because of 404 Not Found.
    at maplibre-gl.js:4211

GET /icons/pin.png 404 (Not Found)
GET /icons/pin@2x.png 404 (Not Found)
var img = new Image();
img.onload = function () { console.log('图片尺寸', img.width, img.height); };
img.onerror = function (e) { console.error('图片加载失败', e); };
img.src = '/icons/pin.png';
console.log('已注册图标', map.hasImage('pin'));
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). Custom marker icons 404 and symbols render blank. https://www.jingweizhi.com/en/cookbook/maplibre-icon-404.html (accessed 2026-11-03).