Czml Billboard Label
Runnable Cesium example: Czml Billboard Label. 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
<!--
示例:用 CZML 描述广告牌与标签
说明:billboard 与 label 挂在同一个 position 上,图标由 canvas 生成 dataURL 写进 CZML
核心逻辑:CzmlDataSource.load → dataSources.add → 相机飞到城市上方
依赖: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>CZML 广告牌与标签</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%}
.cesium-viewer-bottom .cesium-widget-credits,.cesium-viewer-animationContainer,
.cesium-viewer-timelineContainer{display:none!important}
</style>
</head>
<body>
<div id="c"></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;
/* ---------- 图标:圆形标记 ---------- */
function makeIcon(fill) {
var canvas = document.createElement('canvas');
canvas.width = 64;
canvas.height = 64;
var g = canvas.getContext('2d');
g.beginPath();
g.arc(32, 32, 26, 0, Math.PI * 2);
g.fillStyle = fill;
g.fill();
g.lineWidth = 5;
g.strokeStyle = '#ffffff';
g.stroke();
g.beginPath();
g.arc(32, 32, 9, 0, Math.PI * 2);
g.fillStyle = 'rgba(255,255,255,.9)';
g.fill();
return canvas.toDataURL('image/png');
}
var data = [
{ id: 'document', name: '广告牌与标签', version: '1.0' },
{
id: 'beijing',
position: { cartographicDegrees: [116.391263, 39.907359, 300] },
billboard: {
image: makeIcon('#4d9bff'),
scale: 1.6,
verticalOrigin: 'BOTTOM',
disableDepthTestDistance: Number.POSITIVE_INFINITY
},
label: {
text: '北京 · 主标记',
font: '500 14px "Microsoft YaHei", sans-serif',
fillColor: { rgba: [255, 255, 255, 255] },
outlineColor: { rgba: [14, 17, 22, 255] },
outlineWidth: 4,
style: 'FILL_AND_OUTLINE',
verticalOrigin: 'TOP',
pixelOffset: { cartesian2: [0, 6] },
disableDepthTestDistance: Number.POSITIVE_INFINITY
}
},
{
id: 'tianjin',
position: { cartographicDegrees: [117.201, 39.084, 300] },
billboard: {
image: makeIcon('#39c0a0'),
scale: 0.9,
verticalOrigin: 'BOTTOM',
disableDepthTestDistance: Number.POSITIVE_INFINITY
},
label: {
text: '天津 · 小图标',
font: '500 12px "Microsoft YaHei", sans-serif',
fillColor: { rgba: [214, 226, 240, 255] },
outlineColor: { rgba: [14, 17, 22, 255] },
outlineWidth: 3,
style: 'FILL_AND_OUTLINE',
verticalOrigin: 'TOP',
pixelOffset: { cartesian2: [0, 6] },
disableDepthTestDistance: Number.POSITIVE_INFINITY
}
}
];
Cesium.CzmlDataSource.load(data).then(function (ds) {
viewer.dataSources.add(ds);
});
viewer.camera.flyTo({
destination: Cesium.Cartesian3.fromDegrees(116.80, 39.40, 120000),
orientation: {
heading: 0,
pitch: Cesium.Math.toRadians(-58),
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.