Cylinder Cone
Runnable Cesium example: Cylinder Cone. 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
<!--
示例:圆柱、圆锥与圆台三种回转体
要点:CylinderGraphics 用 topRadius 与 bottomRadius 区分形状,length 控制总高
依赖: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%}
.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:250px}
.hud b{color:#e6e8ec;font-weight:600}
.hud .row{margin-top:6px}
.hud button{font:inherit;font-size:12px;padding:3px 9px;margin-right:4px;border-radius:4px;
cursor:pointer;border:1px solid #343b46;background:#1d232b;color:#cfd6e2}
.cesium-viewer-bottom .cesium-widget-credits,.cesium-viewer-animationContainer,
.cesium-viewer-timelineContainer{display:none!important}
</style>
</head>
<body>
<div id="c"></div>
<div class="hud">
<div><b>回转体三兄弟</b></div>
<div class="row">圆柱 · 圆锥 · 圆台</div>
<div class="row">
<button id="outline">切换棱线</button>
</div>
<div class="row" id="info">outline 默认开启</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.sun.show = false;
scene.moon.show = false;
if (scene.skyAtmosphere) scene.skyAtmosphere.show = false;
/* 经度、纬度、上半径、下半径、高度、颜色、名称 */
var SHAPES = [
[116.380, 39.906, 160, 160, 520, '#4d9bff', '圆柱'],
[116.388, 39.906, 0, 230, 520, '#ffb13d', '圆锥'],
[116.396, 39.906, 110, 240, 380, '#5fd0a8', '圆台']
];
var cylinders = [];
SHAPES.forEach(function (s) {
var e = viewer.entities.add({
position: Cesium.Cartesian3.fromDegrees(s[0], s[1], s[4] / 2),
cylinder: {
length: s[4],
topRadius: s[2],
bottomRadius: s[3],
material: Cesium.Color.fromCssColorString(s[5]).withAlpha(0.72),
outline: true,
outlineColor: Cesium.Color.fromCssColorString('#eaf2ff'),
numberOfVerticalLines: 12
},
label: {
text: s[6] + ' topRadius ' + s[2],
font: '500 12px "Microsoft YaHei", sans-serif',
fillColor: Cesium.Color.WHITE,
pixelOffset: new Cesium.Cartesian2(0, -14),
disableDepthTestDistance: Number.POSITIVE_INFINITY,
heightReference: Cesium.HeightReference.RELATIVE_TO_GROUND
}
});
cylinders.push(e);
});
/* 底座:把三个形体连在同一块地面上 */
viewer.entities.add({
position: Cesium.Cartesian3.fromDegrees(116.388, 39.906, -3),
box: {
dimensions: new Cesium.Cartesian3(2600, 700, 6),
material: Cesium.Color.fromCssColorString('#243140')
}
});
var outlineOn = true;
document.getElementById('outline').addEventListener('click', function () {
outlineOn = !outlineOn;
cylinders.forEach(function (e) { e.cylinder.outline = outlineOn; });
document.getElementById('info').textContent = outlineOn
? 'outline 开启 · 12 条母线' : 'outline 关闭 · 只留面';
});
viewer.camera.flyTo({
destination: Cesium.Cartesian3.fromDegrees(116.376, 39.894, 2400),
orientation: {
heading: Cesium.Math.toRadians(38),
pitch: Cesium.Math.toRadians(-30),
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.