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.
Symptom
- DeveloperError: Expected width to be greater than 0, actual value was 0 at CesiumWidget.draw and Viewer.resize.
- viewer.canvas.width is 0.
- Zoom handles and credits pile up in the top-left corner.
Checklist
- Print el.clientWidth and el.clientHeight before construction.
- Walk up the ancestors logging each clientHeight to find the first zero.
- Check for display none on any ancestor, such as an unopened tab, drawer or modal.
- Check flex parents, where flex 1 without min-height 0 collapses to zero.
- 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
- Creating the Viewer while hidden and calling resize afterwards, when internal buffers were already sized at 0 and some versions keep a broken canvas.
- Setting height 100% on the container without giving any ancestor a height, so the percentage resolves against auto.
English edition written for Atlaslog from the original Chinese field note. Code is unchanged and runs as-is.
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).