learning_cesium/加载primiive对象review.html

97 lines
3.6 KiB
HTML
Raw Normal View History

2024-03-19 18:06:25 +08:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<script src="./Build/CesiumUnminified/Cesium.js"></script>
<style>
@import url(./Build/Cesium/Widgets/widgets.css);
html,
body,
#cesiumContainer {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}
</style>
</head>
<body>
<div id="cesiumContainer"></div>
<script>
Cesium.Ion.defaultAccessToken =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI5ZjRjNTZkNC01NDYxLTRhMjQtOGEwZC1kZjA3YzQ5YTJlZDkiLCJpZCI6MjYwODQsInNjb3BlcyI6WyJhc3IiLCJnYyJdLCJpYXQiOjE1ODcxOTMwODN9.prGsSKyAW_9Ow5zHYPhbm3LsQL-ApQw5-5PNJkDaHi8";
var viewer = new Cesium.Viewer("cesiumContainer", {
// terrainProvider: Cesium.createWorldTerrain({
// requestVertexNormal: true, //添加地形光照
// requestWaterMask: true, //添加水面波浪效果
// }),
baseLayerPicker: false, //底图选择器
// mapProjection : new Cesium.WebMercatorProjection(),
geocoder:false,//位置查找
homeButton:false,//视图返回初始位置
sceneModePicker:false,//视角选择器
navigationHelpButton:false,//导航帮助按钮
animation:false,//动画控制器
// creditContainer:"credit",//版权显示,指定dom对象的id,再通过id样式可以隐藏CESIUM 版本图标
timeline:false,//时间线
fullscreenButton:false,//全屏控件
vrButton:false,
infoBox:false ,
shouldAnimate:true,
scene3DOnly:true,//默认false若为true,所有几何体实例将仅会在3D模式中渲染(在GPU内存中)
imageryProvider:new Cesium.ArcGisMapServerImageryProvider({
url: "https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer",
// url: "http://server.arcgisonline.com/arcgis/rest/services/Specialty/DeLorme_World_Base_Map/MapServer",
})
});
var scene = viewer.scene;
// 1、BoxGeometry
// const aabb = Cesium.AxisAlignedBoundingBox.fromPoints(Cesium.Cartesian3.fromDegreesArray([
// -72.0, 40.0,
// -70.0, 35.0,
// -75.0, 30.0,
// -70.0, 30.0,
// -68.0, 40.0
// ]));
// const box = Cesium.BoxGeometry.fromAxisAlignedBoundingBox(aabb);
const box = new Cesium.BoxGeometry({
// vertexFormat : Cesium.VertexFormat.POSITION_ONLY,
maximum : Cesium.Cartesian3.fromDegrees(112,23,50000),
minimum : Cesium.Cartesian3.fromDegrees(110,22,10000)
});
const geometry = Cesium.BoxGeometry.createGeometry(box);
const instance = new Cesium.GeometryInstance({
geometry : geometry,
attributes : {
// 通过attributes属性统一指定线段颜色
color : Cesium.ColorGeometryInstanceAttribute.fromColor(new Cesium.Color(1.0, 1.0, 0, 1.0))
},
id : 'object returned when this instance is picked and to get/set per-instance attributes'
});
scene.primitives.add(new Cesium.Primitive({
geometryInstances : instance,
appearance: new Cesium.MaterialAppearance({
material : Cesium.Material.fromType('Color'),
faceForward : true
}),
asynchronous:false
}));
viewer.camera.flyTo({
destination: Cesium.Cartesian3.fromDegrees(112.0, 23.0,4000000),
orientation: {
heading: Cesium.Math.toRadians(0),
pitch: Cesium.Math.toRadians(-90),
roll: Cesium.Math.toRadians(0),
},
});
</script>
</body>
</html>