Atlaslog / Field Notes / Styling & rendering
Field note · Styling & rendering
Two 50% translucent layers stack into 75% opacity
Quick answer
Two 0.5-opacity fills overlap and measure at about 0.75, much darker than the design. Alpha composites as a_top + a_bottom x (1 - a_top), and any CSS `opacity` on the pane multiplies the result again.
Symptom
- Single-layer area samples `#7fa8d8` while the overlap samples `#6c7ab0`, a brightness drop over 20%
- Overlap alpha computes to `0.5 + 0.5 * 0.5 = 0.75` rather than 0.5
- `getComputedStyle(map.getPane('overlayPane')).opacity` returns `0.8` while the path has `fill-opacity: 0.5`, giving 0.4
Checklist
- Read the pane's computed `opacity` in the Elements panel
- Compare the path's `fill-opacity` with the layer's `opacity` option for double application
- Sample single-layer and overlap pixels with a color picker and back-solve the alpha
- Check for global CSS setting `opacity` on `.leaflet-overlay-pane svg`
- Check Mapbox GL for `fill-opacity` multiplied by a layer-level opacity expression
Fix
Control transparency in one place with `fillOpacity` only (`fillOpacity: 0.35`), or back-solve the per-layer alpha for a target overlap: for 0.5 overlap, `2a - a*a = 0.5` gives a of about 0.293.
Code
α_result = α_top + α_bottom × (1 - α_top)
α = 0.5 + 0.5 × 0.5 = 0.75const pane = map.getPane('overlayPane');
console.log(getComputedStyle(pane).opacity); // 0.8 <- 额外的乘数
console.log(getComputedStyle(pane.querySelector('path')).fillOpacity); // 0.5
Watch out
- Setting both `opacity` and `fillOpacity`, so the values multiply and the result is darker than either intent
- Raising `fillOpacity` on the lower layer to compensate, which darkens the non-overlapping area too
English edition written for Atlaslog from the original Chinese field note. Code is unchanged and runs as-is.
Atlaslog (2026). Two 50% translucent layers stack into 75% opacity. https://www.jingweizhi.com/en/cookbook/opacity-multiply.html (accessed 2026-11-03).