2025-08-07 18:42:39 +08:00
|
|
|
|
const { Cesium } = window;
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-08-07 11:28:32 +08:00
|
|
|
|
|
|
|
|
|
|
export default class LayerMgr {
|
2025-08-07 18:42:39 +08:00
|
|
|
|
constructor() {
|
|
|
|
|
|
// this.viewer = viewer
|
2025-08-07 11:28:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//加载模型
|
2025-08-07 18:42:39 +08:00
|
|
|
|
getGltf(viewer) {
|
|
|
|
|
|
viewer.entities.add({
|
|
|
|
|
|
position: Cesium.Cartesian3.fromDegrees(114.97, 31.48),
|
|
|
|
|
|
model: {
|
|
|
|
|
|
uri: `${process.env.PUBLIC_URL}/models/dam/scene.gltf` ,
|
|
|
|
|
|
scale: 200,
|
|
|
|
|
|
runAnimations: false
|
|
|
|
|
|
},
|
2025-08-07 11:28:32 +08:00
|
|
|
|
});
|
2025-08-07 18:42:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
getWater(viewer) {
|
|
|
|
|
|
// let initialHeight = 130
|
|
|
|
|
|
// const geometry = new Cesium.PolygonGeometry({
|
|
|
|
|
|
// polygonHierarchy: new Cesium.PolygonHierarchy(
|
|
|
|
|
|
// Cesium.Cartesian3.fromDegreesArray(positions)
|
|
|
|
|
|
// ),
|
|
|
|
|
|
// extrudedHeight: initialHeight
|
|
|
|
|
|
// });
|
|
|
|
|
|
// const waterPrimitive = new Cesium.Primitive({
|
|
|
|
|
|
// geometryInstances: new Cesium.GeometryInstance({ geometry }),
|
|
|
|
|
|
// appearance: new Cesium.EllipsoidSurfaceAppearance({
|
|
|
|
|
|
// aboveGround: true,
|
|
|
|
|
|
// material: new Cesium.Material({
|
|
|
|
|
|
// fabric: {
|
|
|
|
|
|
// type: 'Water',
|
|
|
|
|
|
// uniforms: {
|
|
|
|
|
|
// normalMap: Cesium.buildModuleUrl(
|
|
|
|
|
|
// `${process.env.PUBLIC_URL}/models/waternormals.jpg`
|
|
|
|
|
|
// ),
|
|
|
|
|
|
// frequency: 1000.0,
|
|
|
|
|
|
// animationSpeed: 0.01,
|
|
|
|
|
|
// amplitude: 10,
|
|
|
|
|
|
// },
|
|
|
|
|
|
// },
|
|
|
|
|
|
// }),
|
|
|
|
|
|
// }),
|
|
|
|
|
|
// show: true,
|
|
|
|
|
|
// // releaseGeometryInstances: false
|
|
|
|
|
|
// });
|
|
|
|
|
|
// this.viewer.scene.primitives.add(waterPrimitive);
|
|
|
|
|
|
// // 自动抬升
|
|
|
|
|
|
// let height = 0;
|
|
|
|
|
|
// setInterval(() => {
|
|
|
|
|
|
// if (height < 0.4) {
|
|
|
|
|
|
// height += 0.001;
|
|
|
|
|
|
// // height += 0.02;
|
|
|
|
|
|
// // waterPrimitive.extrudedHeight = height; // 触发setter
|
|
|
|
|
|
// var currentModelMatrix = Cesium.Matrix4.clone(waterPrimitive.modelMatrix);
|
|
|
|
|
|
// // 定义平移向量(例如,沿x轴平移100单位)
|
|
|
|
|
|
// var translation = new Cesium.Cartesian3(-height*0.7, height, height*0.8);
|
|
|
|
|
|
// // 创建一个平移矩阵
|
|
|
|
|
|
// var translationMatrix = Cesium.Matrix4.fromTranslation(translation);
|
|
|
|
|
|
// // 计算新的modelMatrix(将平移矩阵应用到当前模型矩阵上)
|
|
|
|
|
|
// var newModelMatrix = Cesium.Matrix4.multiply(translationMatrix, currentModelMatrix, new Cesium.Matrix4());
|
|
|
|
|
|
// waterPrimitive.modelMatrix = newModelMatrix;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }, 100);
|
2025-08-07 11:28:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-07 18:42:39 +08:00
|
|
|
|
async getQxsy(viewer) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
let tileset = await Cesium.Cesium3DTileset.fromUrl(
|
2025-08-07 11:28:32 +08:00
|
|
|
|
'http://res3d.oss-cn-shenzhen.aliyuncs.com/macheng/xiaoyutan/Scene/3DTILE.json',
|
2025-08-07 18:42:39 +08:00
|
|
|
|
{
|
|
|
|
|
|
maximumScreenSpaceError: 1, //精细程度越小越精细
|
|
|
|
|
|
maximumMemoryUsage: 1000, //不可设置太高,目标机子空闲内存值以内,防止浏览器过于卡
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
viewer.scene.primitives.add(tileset);
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error(`Error creating tileset: ${error}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-08-07 11:28:32 +08:00
|
|
|
|
// fetch(`${process.env.PUBLIC_URL}/data/geojson/macheng/boua.geojson`)
|
|
|
|
|
|
// .then(resp => resp.json())
|
|
|
|
|
|
// .then(data => {
|
|
|
|
|
|
// let features = data.features;
|
|
|
|
|
|
// let positionArray = [];
|
|
|
|
|
|
// // 获取区域的经纬度坐标
|
|
|
|
|
|
// for (let i = 0; i < features[0].geometry.coordinates[0].length; i++) {
|
|
|
|
|
|
// let coor = features[0].geometry.coordinates[0][i];
|
|
|
|
|
|
// positionArray.push(coor[0]);
|
|
|
|
|
|
// positionArray.push(coor[1]);
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// // 遮罩
|
|
|
|
|
|
// let polygonEntity = new Cesium.Entity({
|
|
|
|
|
|
// polygon: {
|
|
|
|
|
|
// hierarchy: {
|
|
|
|
|
|
// // 添加外部区域为1/4半圆,设置为180会报错 [0, 0, 0, 90, 179, 90, 179, 0]
|
|
|
|
|
|
// positions: Cesium.Cartesian3.fromDegreesArray([100, 0, 100, 89, 150, 89, 150, 0]),
|
|
|
|
|
|
// // 中心挖空的“洞”
|
|
|
|
|
|
// holes: [{
|
|
|
|
|
|
// positions: Cesium.Cartesian3.fromDegreesArray(positionArray)
|
|
|
|
|
|
// }]
|
|
|
|
|
|
// },
|
|
|
|
|
|
// material: Cesium.Color.BLACK.withAlpha(0.7) //new Cesium.Color(236,242,249, 1)
|
|
|
|
|
|
// }
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
// // 边界线
|
|
|
|
|
|
// let lineEntity = new Cesium.Entity({
|
|
|
|
|
|
// polyline: {
|
|
|
|
|
|
// positions: Cesium.Cartesian3.fromDegreesArray(positionArray),
|
|
|
|
|
|
// width: 7,
|
|
|
|
|
|
// material: Cesium.Color.fromCssColorString('#7AE3C8'),//边界线颜色//Cesium.Color.YELLOW //new Cesium.Color(122,227,200, 1)
|
|
|
|
|
|
// clampToGround: true,
|
|
|
|
|
|
// zIndex: 10
|
|
|
|
|
|
// }
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
// viewer.entities.add(polygonEntity);
|
|
|
|
|
|
// viewer.entities.add(lineEntity);
|
|
|
|
|
|
// //viewer.flyTo(lineEntity);
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-08-07 18:42:39 +08:00
|
|
|
|
// tileset.readyPromise.then(function () {
|
|
|
|
|
|
// viewer.zoomTo(
|
|
|
|
|
|
// tileset,
|
|
|
|
|
|
// new Cesium.HeadingPitchRange(
|
|
|
|
|
|
// 0,
|
|
|
|
|
|
// -0.7,
|
|
|
|
|
|
// 2500
|
|
|
|
|
|
// // tileset.boundingSphere.radius * 10
|
|
|
|
|
|
// )
|
|
|
|
|
|
// );
|
|
|
|
|
|
// });
|
2025-08-07 11:28:32 +08:00
|
|
|
|
|
|
|
|
|
|
//设置倾斜摄影Z轴高度
|
2025-08-07 18:42:39 +08:00
|
|
|
|
// tileset.readyPromise.then(function (tileset) {
|
|
|
|
|
|
// const offsetHeight = 15
|
|
|
|
|
|
// const boundingSphere = tileset.boundingSphere
|
|
|
|
|
|
// const cartographic = Cesium.Cartographic.fromCartesian(boundingSphere.center)
|
|
|
|
|
|
// const surface = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, 0.0)
|
|
|
|
|
|
// const offset = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, offsetHeight)
|
|
|
|
|
|
// const translation = Cesium.Cartesian3.subtract(offset, surface, new Cesium.Cartesian3())
|
|
|
|
|
|
// tileset.modelMatrix = Cesium.Matrix4.fromTranslation(translation)
|
|
|
|
|
|
// // viewer.flyTo(tileset)
|
|
|
|
|
|
// })
|
2025-08-07 11:28:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|