Cesium Inspector
Runnable Cesium example: Cesium Inspector. Open the live demo, read the complete source, and copy the file into your project. No build step or API key.
single HTML file · CDN dependencies onlyinterface may contain Chinese labels
Source
<!--
示例:打开内置的 CesiumInspector 查看渲染统计
说明:面板里可以看图元数量、绘制调用、瓦片状态,还能开启点击拾取与线框模式
核心逻辑:new Cesium.CesiumInspector('inspector', viewer) + debugShowFramesPerSecond
依赖:CesiumJS 1.121 · jsDelivr CDN
-->
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta name="robots" content="noindex,follow">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>内置检查器</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/cesium@1.121.0/Build/Cesium/Widgets/widgets.css">
<style>
html,body{height:100%;margin:0}
body{background:#0e1116;color:#e6e8ec;overflow:hidden;
font:13px/1.6 -apple-system,"Segoe UI","PingFang SC",sans-serif}
#c{height:100%}
#inspector{position:absolute;right:12px;top:12px;width:300px;z-index:5}
.hud{position:absolute;left:12px;top:12px;z-index:5;background:rgba(23,28,35,.9);
border:1px solid #2a313b;border-radius:6px;padding:9px 12px;font-size:12px;
color:#a2a9b6;max-width:240px}
.hud b{color:#e6e8ec;font-weight:600}
.cesium-viewer-bottom .cesium-widget-credits,.cesium-viewer-animationContainer,
.cesium-viewer-timelineContainer{display:none!important}
</style>
</head>
<body>
<div id="c"></div>
<div id="inspector"></div>
<div class="hud">
<div><b>内置检查器</b></div>
<div>右上角面板可展开,Pick 打开后点画面看拾取结果</div>
<div>左下角显示实时帧率</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/cesium@1.121.0/Build/Cesium/Cesium.js"></script>
<script>
(function () {
'use strict';
var viewer = new Cesium.Viewer('c', {
baseLayer: false,
baseLayerPicker: false, geocoder: false, homeButton: false,
sceneModePicker: false, navigationHelpButton: false,
animation: false, timeline: false, fullscreenButton: false,
infoBox: false, selectionIndicator: false
});
var scene = viewer.scene;
scene.globe.baseColor = Cesium.Color.fromCssColorString('#1c2733');
scene.backgroundColor = Cesium.Color.fromCssColorString('#0e1116');
scene.skyBox.show = false;
scene.moon.show = false;
if (scene.skyAtmosphere) scene.skyAtmosphere.show = false;
scene.globe.enableLighting = true;
scene.debugShowFramesPerSecond = true;
/* 放一些图元,让检查器里有东西可看 */
var instances = [];
var palette = ['#4d9bff', '#39c0a0', '#f2a03d', '#e45c7a', '#8e7cf0'];
for (var i = 0; i < 40; i++) {
var lon = 116.3913 + ((i % 8) - 4) * 0.00042;
var lat = 39.9074 + (Math.floor(i / 8) - 2) * 0.00036;
var h = 20 + (i * 37) % 80;
instances.push(new Cesium.GeometryInstance({
geometry: new Cesium.BoxGeometry({
vertexFormat: Cesium.PerInstanceColorAppearance.VERTEX_FORMAT,
minimumCorner: new Cesium.Cartesian3(-14, -12, 0),
maximumCorner: new Cesium.Cartesian3(14, 12, h)
}),
modelMatrix: Cesium.Transforms.eastNorthUpToFixedFrame(
Cesium.Cartesian3.fromDegrees(lon, lat, 0)
),
attributes: {
color: Cesium.ColorGeometryInstanceAttribute.fromColor(
Cesium.Color.fromCssColorString(palette[i % palette.length])
)
}
}));
}
scene.primitives.add(new Cesium.Primitive({
geometryInstances: instances,
appearance: new Cesium.PerInstanceColorAppearance({ flat: false, translucent: false }),
asynchronous: false
}));
viewer.entities.add({
position: Cesium.Cartesian3.fromDegrees(116.3913, 39.9074, 140),
label: {
text: '点我可以试 Pick 模式',
font: '500 13px "Microsoft YaHei", sans-serif',
fillColor: Cesium.Color.WHITE,
disableDepthTestDistance: Number.POSITIVE_INFINITY
}
});
var inspector = new Cesium.CesiumInspector('inspector', viewer);
inspector.show = true;
viewer.camera.flyTo({
destination: Cesium.Cartesian3.fromDegrees(116.3888, 39.9028, 950),
orientation: {
heading: Cesium.Math.toRadians(40),
pitch: Cesium.Math.toRadians(-24),
roll: 0
},
duration: 0
});
})();
</script>
</body>
</html>
Language: the code and this page are in English; the full tutorial and API notes for this example are in Chinese. The demo itself is the authoritative version — it runs exactly as shown.