Atlaslog
Atlaslog / Field Notes / 3D & Cesium
Field note · 3D & Cesium

CesiumWidget has zero size and the globe is never created

Quick answer

The container declares 100% width and height but measures 0 by 0, so Cesium throws during construction and the canvas stays at width 0. Percentage heights need a chain of definite heights, and a display none ancestor defeats them entirely.

Last verified 2026-11-03 · Multiple versions · Cite this page
Applies to: CesiumJS 1.121
Symptom
Checklist
  1. Print el.clientWidth and el.clientHeight before construction.
  2. Walk up the ancestors logging each clientHeight to find the first zero.
  3. Check for display none on any ancestor, such as an unopened tab, drawer or modal.
  4. Check flex parents, where flex 1 without min-height 0 collapses to zero.
  5. Check whether the script runs before DOMContentLoaded, before styles are applied.
Fix

Give the container a definite height chain with html and body at 100%, and cesiumContainer at flex 1, min-height 0 and position relative. Initialise only when the container is visible, waiting on a ResizeObserver before new Cesium.Viewer, and call viewer.resize on later size changes.

Code
DeveloperError: Expected width to be greater than 0, actual value was 0
    at CesiumWidget.draw (CesiumWidget.js:1042)
    at Viewer.resize (Viewer.js:1301)
var el = document.getElementById('cesiumContainer');
console.log(el.clientWidth, el.clientHeight);       // 0 0

var p = el;
while (p && p !== document.body) {
  console.log(p.tagName, p.className, p.clientHeight);
  p = p.parentElement;
}
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). CesiumWidget has zero size and the globe is never created. https://www.jingweizhi.com/en/cookbook/cesium-widget-zero-size.html (accessed 2026-11-03).