fix:cesiumtest
This commit is contained in:
parent
52ecdb332b
commit
9387cca8a0
|
@ -366,6 +366,15 @@ export default {
|
|||
},
|
||||
series: [{ type: "line" }],
|
||||
},
|
||||
modelPosition: [
|
||||
{ lng: 88.64154268696439, lat: 42.721977308996635 },
|
||||
{ lng: 88.64217853109109, lat: 42.721910071501945 },
|
||||
{ lng: 88.64628960011686, lat: 42.72184710482201 },
|
||||
{ lng: 88.64619581826986, lat: 42.7215414346846 },
|
||||
{ lng: 88.64013560274894, lat: 42.72268219734449 },
|
||||
{ lng: 88.64035358529543, lat: 42.72266224153806 },
|
||||
{ lng: 88.64013259837789, lat: 42.722622240941305 },
|
||||
],
|
||||
};
|
||||
},
|
||||
created() {
|
||||
|
@ -402,157 +411,18 @@ export default {
|
|||
viewer.scene.fxaa = true;
|
||||
viewer.scene.postProcessStages.fxaa.enabled = true;
|
||||
|
||||
// 修改homeButton的默认返回位置
|
||||
// this.viewer.homeButton.viewModel.command.beforeExecute.addEventListener((e) => {
|
||||
// e.cancel = true;
|
||||
// //你要飞的位置
|
||||
// this.viewer.camera.flyTo({
|
||||
// destination: Cesium.Cartesian3.fromDegrees(119.196653, 26.031937, 50),
|
||||
// })
|
||||
// })
|
||||
// viewer.scene.globe.depthTestAgainstTerrain = false
|
||||
|
||||
//设置限制缩放大小
|
||||
// viewer.scene.screenSpaceCameraController.minimumZoomDistance = 1
|
||||
// 隐藏地球
|
||||
// viewer.scene.globe.show = false
|
||||
//隐藏logo信息
|
||||
viewer.scene.globe.enableLighting = true;
|
||||
viewer._cesiumWidget._creditContainer.style.display = "none";
|
||||
//*****cesium加载3dtiles*****//
|
||||
// const tileset = new Cesium.Cesium3DTileset({
|
||||
// url: "/3dtiles/tileset.json",
|
||||
// // url: "http://49.232.14.174:2226/pf/3dtiles/tileset.json",
|
||||
// });
|
||||
// tileset.readyPromise.then(function (tileset) {
|
||||
// viewer.scene.primitives.add(tileset);
|
||||
// //将tileset的包围球中心点坐标从笛卡尔坐标系转换为地理坐标系
|
||||
// const cartographic = Cesium.Cartographic.fromCartesian(
|
||||
// tileset.boundingSphere.center
|
||||
// );
|
||||
// console.log('cartographic',cartographic);
|
||||
// const { longitude, latitude, height } = cartographic;
|
||||
// // 模型包围球的中心点坐标,输出以笛卡尔坐标系表示的三维坐标点
|
||||
// const current = Cesium.Cartesian3.fromRadians(
|
||||
// longitude,
|
||||
// latitude,
|
||||
// height
|
||||
// )
|
||||
// //根据中心点坐标计算出的地表坐标点
|
||||
// const surface = Cesium.Cartesian3.fromRadians(
|
||||
// cartographic.longitude, //经度
|
||||
// cartographic.latitude, //纬度
|
||||
// 0 //高度
|
||||
// )
|
||||
// //根据中心点坐标和height值计算出的新的坐标点
|
||||
// const offset = Cesium.Cartesian3.fromRadians(
|
||||
// longitude, latitude, 0
|
||||
// );
|
||||
// //更新tileset模型矩阵(modelMatrix)的,实现tileset位置的平移变换
|
||||
// const translation = Cesium.Cartesian3.subtract(
|
||||
// offset, //根据中心点坐标和height值计算出的新的坐标点
|
||||
// surface, //根据中心点坐标计算出的地表坐标点
|
||||
// new Cesium.Cartesian3()
|
||||
// );
|
||||
// tileset.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
|
||||
// //tileset加载完成监听
|
||||
// // tileset.tileLoad.addEventListener(function (tile) {
|
||||
// // let content = tile.content;
|
||||
// // // let featuresLength = content.featuresLength;
|
||||
// // let feature = content.getFeature(0);
|
||||
// // //将tileset的包围球中心点坐标从笛卡尔坐标系转换为地理坐标系
|
||||
// // const cartographicMesh = Cesium.Cartographic.fromCartesian(
|
||||
// // feature._content._model._boundingSphere.center
|
||||
// // );
|
||||
// // // 模型包围球的中心点坐标,输出以笛卡尔坐标系表示的三维坐标点
|
||||
// // const currentMesh = Cesium.Cartesian3.fromRadians(
|
||||
// // cartographicMesh.longitude, //经度
|
||||
// // cartographicMesh.latitude, //纬度
|
||||
// // cartographicMesh.height
|
||||
// // )
|
||||
// // //根据中心点坐标计算出的地表坐标点
|
||||
// // const surfaceMesh = Cesium.Cartesian3.fromRadians(
|
||||
// // cartographicMesh.longitude, //经度
|
||||
// // cartographicMesh.latitude, //纬度
|
||||
// // 2 //高度
|
||||
// // )
|
||||
|
||||
// // })
|
||||
// //视野转到tileset模型
|
||||
// viewer.zoomTo(
|
||||
// tileset,
|
||||
// new Cesium.HeadingPitchRange(
|
||||
// -4.0,
|
||||
// -0.65,
|
||||
// 500
|
||||
// )
|
||||
// );
|
||||
// that.getEquipmentList();
|
||||
// });
|
||||
// // 监听鼠标左键点击事件
|
||||
// var handler = new Cesium.ScreenSpaceEventHandler(viewer.canvas);
|
||||
// handler.setInputAction(function (click) {
|
||||
// var feature = viewer.scene.pick(click.position);
|
||||
// console.log("feature",feature);
|
||||
// console.log("_attrs", feature.id._attrs);
|
||||
// that.objItem = feature.id._attrs;
|
||||
// that.getInfo(feature.id._id);
|
||||
// if (Cesium.defined(feature)) {
|
||||
// // 判断点击位置是否有模型被选中
|
||||
// var pickedPosition = viewer.scene.pickPosition(click.position);
|
||||
// if (Cesium.defined(pickedPosition)) {
|
||||
// // 将点击位置的世界坐标转换为地理坐标(经纬度)
|
||||
// var cartographic = Cesium.Cartographic.fromCartesian(pickedPosition);
|
||||
// var longitude = Cesium.Math.toDegrees(cartographic.longitude);//经度
|
||||
// var latitude = Cesium.Math.toDegrees(cartographic.latitude);//纬度
|
||||
// var height = cartographic.height; // 获取高度值
|
||||
// // console.log('Longitude: ' + longitude);
|
||||
// // console.log('Latitude: ' + latitude);
|
||||
// // console.log('Height: ' + height);
|
||||
// // 可以在这里执行更多操作,例如在点击位置添加标记等
|
||||
// //获取该点信息,查询相关数据
|
||||
|
||||
// }
|
||||
// }
|
||||
// },
|
||||
// Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
||||
// that.intervalequ = setInterval(() => {
|
||||
// that.getEquipmentList();
|
||||
// },60000)
|
||||
//*****cesium加载3dtiles*****//
|
||||
|
||||
console.log("");
|
||||
//*****cesium加载.glb格式的文件*****//
|
||||
//1、viewer.scene.primitives.add
|
||||
// var position = Cesium.Cartesian3.fromDegrees(-123.0744619, 44.0503706, 0.1);
|
||||
// var modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(position);
|
||||
// var url = "factory.glb";
|
||||
// // 加载 glb 模型
|
||||
// var model = viewer.scene.primitives.add(Cesium.Model.fromGltf({
|
||||
// url: url,
|
||||
// modelMatrix: modelMatrix,
|
||||
// scale: 1000// 可选:设置模型缩放比例
|
||||
// }));
|
||||
// // 监听模型加载完成事件
|
||||
// model.readyPromise.then(function(model) {
|
||||
// console.log('模型加载完成:', model);
|
||||
// // 计算模型包围盒的边界
|
||||
// var boundingSphere = model.boundingSphere;
|
||||
// // 将相机焦点移动到模型的包围球中心
|
||||
// viewer.camera.flyToBoundingSphere(boundingSphere, {
|
||||
// duration: 0 // 设置飞行动画持续时间(单位:秒)
|
||||
// });
|
||||
// // 设置相机跟随模型
|
||||
// viewer.trackedEntity = model;
|
||||
// }).otherwise(function(error) {
|
||||
// console.error('模型加载失败:', error);
|
||||
// });
|
||||
|
||||
//2、viewer.entities.add
|
||||
var url = "factory.glb";
|
||||
var url = "photon_tree.glb";
|
||||
var height = 0;
|
||||
viewer.entities.removeAll(); //加载之前先清楚所有entity
|
||||
var position = Cesium.Cartesian3.fromDegrees(88.644, 42.723, height);
|
||||
var position = Cesium.Cartesian3.fromDegrees(
|
||||
88.64349,
|
||||
42.72285,
|
||||
height
|
||||
);
|
||||
var heading = Cesium.Math.toRadians(191); //310度转弧度
|
||||
var pitch = Cesium.Math.toRadians(0);
|
||||
var roll = Cesium.Math.toRadians(0);
|
||||
|
@ -561,7 +431,7 @@ export default {
|
|||
position,
|
||||
hpr
|
||||
);
|
||||
var modelScale = 30.0; // 假设模型原始单位是厘米,需要转换为米
|
||||
var modelScale = 2.3; // 假设模型原始单位是厘米,需要转换为米
|
||||
var modelEntity = viewer.entities.add({
|
||||
name: "photon",
|
||||
position: position,
|
||||
|
@ -573,11 +443,9 @@ export default {
|
|||
Cesium.Transforms.eastNorthUpToFixedFrame(position),
|
||||
minimumPixelSize: 256, //最小像素大小,可以避免太小看不见
|
||||
maximumScale: 20000, //模型的最大比例尺大小。minimumPixelSize的上限
|
||||
incrementallyLoadTextures: true, //加载模型后纹理是否可以继续流入
|
||||
shadows: Cesium.ShadowMode.ENABLED,
|
||||
heightReference: Cesium.HeightReference.NONE,
|
||||
},
|
||||
});
|
||||
// that.setTrees(viewer, orientation);
|
||||
viewer.trackedEntity = modelEntity; // 聚焦模型
|
||||
//设置相机位置
|
||||
viewer.zoomTo(
|
||||
|
@ -615,6 +483,32 @@ export default {
|
|||
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
||||
},
|
||||
methods: {
|
||||
//单独加载树
|
||||
setTrees(viewer, orientation) {
|
||||
this.modelPosition.forEach((item) => {
|
||||
let position = Cesium.Cartesian3.fromDegrees(
|
||||
item.lng,
|
||||
item.lat,
|
||||
0
|
||||
);
|
||||
viewer.entities.add({
|
||||
name: "tree",
|
||||
position: position,
|
||||
orientation: orientation,
|
||||
model: {
|
||||
uri: "tree.glb", //注意entitits.add方式加载gltf文件时,这里是uri,不是url,并且这种方式只能加载.glb格式的文件
|
||||
scale: 1, //缩放比例
|
||||
modelMatrix:
|
||||
Cesium.Transforms.eastNorthUpToFixedFrame(position),
|
||||
minimumPixelSize: 10, //最小像素大小,可以避免太小看不见
|
||||
maximumScale: 20000, //模型的最大比例尺大小。minimumPixelSize的上限
|
||||
incrementallyLoadTextures: true, //加载模型后纹理是否可以继续流入
|
||||
shadows: Cesium.ShadowMode.ENABLED,
|
||||
heightReference: Cesium.HeightReference.NONE,
|
||||
},
|
||||
});
|
||||
});
|
||||
},
|
||||
getChartTime() {
|
||||
let endDate = new Date();
|
||||
let startDate = new Date();
|
||||
|
@ -717,7 +611,7 @@ export default {
|
|||
let imgUrl = that.getItemIcon(item.cate_code);
|
||||
let lon = parseFloat(item.coordinates.longitude);
|
||||
let lat = parseFloat(item.coordinates.latitude);
|
||||
let height = parseInt(item.coordinates.height) + 15;
|
||||
let height = parseInt(item.coordinates.height);
|
||||
let type = item.cate_code;
|
||||
let arrs = {
|
||||
name: item.name,
|
||||
|
|
Loading…
Reference in New Issue