Cesium-Examples/examples/cesiumEx/5.3.6、曲线插值.html

116 lines
3.1 KiB
HTML
Raw Normal View History

2025-03-11 08:25:45 +00:00
<!--********************************************************************
* by jiawanlong
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
2025-03-19 03:00:22 +00:00
<link rel="stylesheet" href="./../../libs/cesium/Cesium1.98/Widgets/widgets.css" />
<script type="text/javascript" src="./../../libs/cesium/Cesium1.98/Cesium.js"></script>
2025-03-11 08:25:45 +00:00
</head>
<body style="
margin: 0;
overflow: hidden;
background: #fff;
width: 100%;
height: 100%;
position: absolute;
top: 0;
">
<div id="map" style="margin: 0 auto; width: 100%; height: 100%"></div>
<script type="text/javascript">
Cesium.Ion.defaultAccessToken =
2025-05-29 02:59:44 +00:00
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIyNDMxOTA2NS1lY2Q3LTQ0YmUtOTE1Mi1iNWE2OGYwZjc0MjkiLCJpZCI6MjM1NjMwLCJpYXQiOjE3MzA3MjQzMTJ9.Xhu-9FyVEyqBKWEr0V9Sybt-elTCWHt9peL9-mNh-4E";
2025-03-11 08:25:45 +00:00
const viewer = new Cesium.Viewer("map", {
contextOptions: {
requestWebgl1: true,
},
});
viewer.scene.debugShowFramesPerSecond = true;
var controls = [
Cesium.Cartesian3.fromDegrees(110, 10),
Cesium.Cartesian3.fromDegrees(111, 11),
Cesium.Cartesian3.fromDegrees(112, 9),
Cesium.Cartesian3.fromDegrees(114, 10),
Cesium.Cartesian3.fromDegrees(113, 8),
];
for (var i = 0; i < controls.length; i++) {
viewer.entities.add({
position: controls[i],
point: {
color: Cesium.Color.RED,
pixelSize: 10,
},
});
}
// -----------------------直线--------------------------
var spline = new Cesium.LinearSpline({
times: [0.0, 0.25, 0.5, 0.75, 1],
points: controls,
});
var positions = [];
for (var i = 0; i <= 100; i++) {
var cartesian3 = spline.evaluate(i / 100);
positions.push(cartesian3);
viewer.entities.add({
position: cartesian3,
point: {
color: Cesium.Color.YELLOW,
pixelSize: 6,
},
});
}
viewer.entities.add({
name: "LinearSpline",
polyline: {
positions: positions,
width: 3,
material: Cesium.Color.GREEN,
},
});
// -----------------------直线--------------------------
// -----------------------曲线--------------------------
// 创建CatmullRomSpline对象
var spline = new Cesium.CatmullRomSpline({
points: controls,
times: [0.0, 0.25, 0.5, 0.75, 1],
});
// 插值100个点
var positions = [];
for (var i = 0; i <= 100; i++) {
var cartesian3 = spline.evaluate(i / 100);
positions.push(cartesian3);
viewer.entities.add({
position: cartesian3,
point: {
color: Cesium.Color.BLUE,
pixelSize: 6,
},
});
}
// 将插值所有的点绘制成线
viewer.entities.add({
name: "CatmullRomSpline",
polyline: {
positions: positions,
width: 3,
material: Cesium.Color.WHITE,
},
});
// -----------------------曲线--------------------------
viewer.zoomTo(viewer.entities);
</script>
</body>
</html>