Atlaslog
Atlaslog / Field Notes / Styling & rendering
Field note · Styling & rendering

Polygon layer covers the road lines, and zIndex makes it worse

Quick answer

Areas are added before roads yet render on top of them, and setting `{ zIndex: 999 }` on the line layer makes the lines vanish. Leaflet's `zIndex` is a renderer and pane property, not a per-layer ordering control inside one renderer.

Last verified 2026-11-03 · Multiple versions · Cite this page
Applies to: Leaflet 1.9.x / OpenLayers 9.x
Symptom
Checklist
  1. Inspect each layer's `.leaflet-pane` and its computed `z-index` in the Elements panel
  2. Check whether layers were given different `renderer` or `pane` options
  3. Check `addLayer` order, since within one pane the later layer is on top
  4. Set `interactive: false` on the area layer to rule out pointer-event interference
  5. List every pane with its z-index value
Fix

Create dedicated panes with explicit z-index (`areas` 410, `roads` 420, `pois` 430) and pass `pane` to each layer; in OpenLayers `setZIndex(20)` on roads and `10` on areas does take effect as expected.

Code
console.log(map.getPane('overlayPane').style.zIndex);   // 400
document.querySelectorAll('.leaflet-pane').forEach(p =>
  console.log(p.className, getComputedStyle(p).zIndex));
map.createPane('areas');
map.getPane('areas').style.zIndex = 410;

map.createPane('roads');
map.getPane('roads').style.zIndex = 420;

map.createPane('pois');
map.getPane('pois').style.zIndex = 430;

L.geoJSON(areaData, {
  pane: 'areas',
  style: { fillOpacity: 0.35, color: '#1a6fd4', weight: 1 }
}).addTo(map);

L.geoJSON(roadData, {
  pane: 'roads',
  style: { color: '#e8590c', weight: 3 }
}).addTo(map);

L.geoJSON(poiData, { pane: 'pois' }).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). Polygon layer covers the road lines, and zIndex makes it worse. https://www.jingweizhi.com/en/cookbook/layer-order-cover.html (accessed 2026-11-03).