原文链接及内容

效果如下视频所示:

示例代码如下:

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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const viewer = new Cesium.Viewer("cesiumContainer", {
geocoder: false,
sceneModePicker: false,
homeButton: false,
navigationHelpButton: false,
baseLayerPicker: false,
navigationInstructionsInitiallyVisible: false,
animation: false,
timeline: false,
fullscreenButton: false,
selectionIndicator: false,
skyBox: false,
shouldAnimate: true,
infoBox: false,
shadows: true,
});

viewer.cesiumWidget.creditContainer.style.display = "none";
viewer.scene.debugShowFramesPerSecond = true;

const scene = viewer.scene;
scene.globe.depthTestAgainstTerrain = true;

if (!scene.sampleHeightSupported) {
window.alert("This browser does not support sampleHeight.");
}

const longitude = -2.1480545852753163;
const latitude = 0.7688240036937101;
const range = 0.000001;
const duration = 4.0;

const entity = viewer.entities.add({
position: Cesium.Cartesian3.fromRadians(longitude, latitude),
model: {
uri: "../SampleData/models/GroundVehicle/GroundVehicle.glb",
},
});

const point = viewer.entities.add({
position: new Cesium.CallbackProperty(updatePosition, false),
point: {
pixelSize: 10,
color: Cesium.Color.YELLOW,
disableDepthTestDistance: Number.POSITIVE_INFINITY,
},
label: {
show: false,
showBackground: true,
font: "14px monospace",
horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
pixelOffset: new Cesium.Cartesian2(5, 5),
disableDepthTestDistance: Number.POSITIVE_INFINITY,
},
});

const objectsToExclude = [point];
const cartographic = new Cesium.Cartographic();

function updatePosition(time, result) {
const offset = (time.secondsOfDay % duration) / duration;
cartographic.longitude = longitude - range + offset * range * 2.0;
cartographic.latitude = latitude;

let height;
if (scene.sampleHeightSupported) {
height = scene.sampleHeight(cartographic, objectsToExclude);
}

if (Cesium.defined(height)) {
cartographic.height = height;
point.label.text = `${Math.abs(height).toFixed(2).toString()} m`;
point.label.show = true;
} else {
cartographic.height = 0.0;
point.label.show = false;
}

return Cesium.Cartographic.toCartesian(
cartographic,
Cesium.Ellipsoid.WGS84,
result,
);
}
viewer.trackedEntity = entity;