Cesium-Examples/examples/cesiumEx/5.3.2、手动视锥体.html
2025-11-21 15:06:34 +08:00

142 lines
4.9 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!--********************************************************************
* by jiawanlong
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" href="./../../libs/cesium/Cesium1.98/Widgets/widgets.css">
<script type="text/javascript" src="./../../libs/cesium/Cesium1.98/Cesium.js"></script>
</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">
const viewer = new Cesium.Viewer('map', {
imageryProvider: false,
baseLayerPicker: false,
});
var xyz = new Cesium.UrlTemplateImageryProvider({
"url": '///data.mars3d.cn/tile/img/{z}/{x}/{y}.jpg'
})
viewer.imageryLayers.addImageryProvider(xyz)
// Cesium地形
viewer.terrainProvider = new Cesium.CesiumTerrainProvider({
url: 'http://data.mars3d.cn/terrain'
});
// 深度监测
viewer.scene.globe.depthTestAgainstTerrain = true;
// extrudedHeight是本身高度
// height是离地高度
// --------注意贴地时候没extrudedHeight所以outline不会生效---------------
let p1 = { x: -90, y: 40, z: 0 }
let p2 = { x: -90, y: 30, z: 0 }
let p3 = { x: -100, y: 30, z: 0 }
let p4 = { x: -100, y: 40, z: 0 }
let p5 = { x: -95, y: 35, z: 2000000 }
let c1 = new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArrayHeights([
p1.x, p1.y, p1.z,
p2.x, p2.y, p2.z,
p5.x, p5.y, p5.z
]))
let c2 = new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArrayHeights([
p3.x, p3.y, p3.z,
p2.x, p2.y, p2.z,
p5.x, p5.y, p5.z
]))
let c3 = new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArrayHeights([
p3.x, p3.y, p3.z,
p4.x, p4.y, p4.z,
p5.x, p5.y, p5.z
]))
let c4 = new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArrayHeights([
p1.x, p1.y, p1.z,
p4.x, p4.y, p4.z,
p5.x, p5.y, p5.z
]))
const cyanPolygon = viewer.entities.add({
polygon: {
hierarchy: new Cesium.CallbackProperty(() => {
return c1;
}, false),
perPositionHeight: true,
material: Cesium.Color.CYAN.withAlpha(0.5),
outline: true,
outlineColor: Cesium.Color.BLACK,
},
});
let i = 0;
setInterval(() => {
i = i + 0.01
c1 = new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArrayHeights([
p1.x + i, p1.y + i, p1.z,
p2.x + i, p2.y + i, p2.z,
p5.x + i, p5.y + i, p5.z
]))
c2 = new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArrayHeights([
p3.x + i, p3.y + i, p3.z,
p2.x + i, p2.y + i, p2.z,
p5.x + i, p5.y + i, p5.z
]))
c3 = new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArrayHeights([
p3.x + i, p3.y + i, p3.z,
p4.x + i, p4.y + i, p4.z,
p5.x + i, p5.y + i, p5.z
]))
c4 = new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArrayHeights([
p1.x + i, p1.y + i, p1.z,
p4.x + i, p4.y + i, p4.z,
p5.x + i, p5.y + i, p5.z
]))
}, 20)
const cyanPolygon1 = viewer.entities.add({
polygon: {
hierarchy: new Cesium.CallbackProperty(() => {
return c2;
}, false),
perPositionHeight: true,
material: Cesium.Color.CYAN.withAlpha(0.5),
outline: true,
outlineColor: Cesium.Color.BLACK,
},
});
const cyanPolygon2 = viewer.entities.add({
polygon: {
hierarchy: new Cesium.CallbackProperty(() => {
return c3;
}, false),
perPositionHeight: true,
material: Cesium.Color.CYAN.withAlpha(0.5),
outline: true,
outlineColor: Cesium.Color.BLACK,
},
});
const cyanPolygon3 = viewer.entities.add({
polygon: {
hierarchy: new Cesium.CallbackProperty(() => {
return c4;
}, false),
perPositionHeight: true,
material: Cesium.Color.CYAN.withAlpha(0.5),
outline: true,
outlineColor: Cesium.Color.BLACK,
},
});
viewer.zoomTo(viewer.entities);
</script>
</body>
</html>