原文链接及内容

效果如下图所示:

示例代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const viewer = new Cesium.Viewer("cesiumContainer", {
geocoder: false,
homeButton: false,
navigationHelpButton: false,
navigationInstructionsInitiallyVisible: false,
animation: false,
timeline: false,
fullscreenButton: false,
skyBox: false,
sceneModePicker: false,
baseLayerPicker: false,
infoBox: false,
});
viewer.cesiumWidget.creditContainer.style.display = "none";

Cesium.Math.setRandomNumberSeed(1234);

const entities = viewer.entities;

//创建实体“folders”,以便我们可以整体开启或关闭实体的可见性。
const spheres = entities.add(new Cesium.Entity());
const boxes = entities.add(new Cesium.Entity());
const ellipsoids = entities.add(new Cesium.Entity());

// 创建实体并为每个实体设置parent属性,以便将其分配到其所属的组。
for (let i = 0; i < 5; ++i) {
const height = 100000.0 + 200000.0 * i;
entities.add({
parent: boxes,
position: Cesium.Cartesian3.fromDegrees(-106.0, 45.0, height),
box: {
dimensions: new Cesium.Cartesian3(90000.0, 90000.0, 90000.0),
material: Cesium.Color.fromRandom({ alpha: 1.0 }),
},
});

entities.add({
parent: ellipsoids,
position: Cesium.Cartesian3.fromDegrees(-102.0, 45.0, height),
ellipsoid: {
radii: new Cesium.Cartesian3(45000.0, 45000.0, 90000.0),
material: Cesium.Color.fromRandom({ alpha: 1.0 }),
},
});

entities.add({
parent: spheres,
position: Cesium.Cartesian3.fromDegrees(-98.0, 45.0, height),
ellipsoid: {
radii: new Cesium.Cartesian3(67500.0, 67500.0, 67500.0),
material: Cesium.Color.fromRandom({ alpha: 1.0 }),
},
});
}

viewer.zoomTo(viewer.entities);

Sandcastle.addToolbarButton("切换Boxes组的可见性", function () {
boxes.show = !boxes.show;
});

Sandcastle.addToolbarButton("切换Ellipsoids组的可见性", function () {
ellipsoids.show = !ellipsoids.show;
});

Sandcastle.addToolbarButton("切换Spheres组的可见性", function () {
spheres.show = !spheres.show;
});