cesium加载3dTileset代码如下
palaceTileset = await Cesium.Cesium3DTileset.fromUrl(
"url", {
skipLevelOfDetail: true,
baseScreenSpaceError: 1024,
skipScreenSpaceErrorFactor: 16,
skipLevels: 1,
immediatelyLoadDesiredLevelOfDetail: false,
loadSiblings: false,
cullWithChildrenBounds: true,
progressiveResolutionHeightFraction: 1,
dynamicScreenSpaceErrorDensity: 1,
maximumScreenSpaceError: 1
});
viewer.scene.primitives.add(palaceTileset);
加载三维模型 视频参考地址:
https://www.bilibili.com/video/BV14g411s7DX/?spm_id_from=333.1007.top_right_bar_window_history.content.click&vd_source=4716b12357fe8e4b33b293b4bbbbfcd8文章来源地址https://www.toymoban.com/news/detail-818076.html
const initThreeModel = async () => {
let res = await queryTrajectory(monitoringStore.$state.trajectoryId)
let newArray = res.data.map(item => [item.longitude, item.latitude, item.heightValue]);
//其中newArray中的参数为[ [117.4603186710001, 31.14388249900003, 15.147400000001653]]分别是经纬度以及高度
var viewer = new Cesium.Viewer("cesiumContainer", {
//搜索框
geocoder: false,
//home键
homeButton: false,
// 动画控件
animation: true,
//全屏按钮
fullscreenButton: false,
//场景模式选择器
sceneModePicker: false,
//时间轴
timeline: true,
//导航提示
navigationHelpButton: false,
//地图选择器
baseLayerPicker: false,
})
viewer.cesiumWidget.creditContainer.style.display = 'none'
//创建DataSource
var datasource = new Cesium.CustomDataSource("enetiestestdata");
viewer.dataSources.add(datasource)
let resImg = await reqQueryImgVideo(monitoringStore.$state.trajectoryId)
let testArrayImg = resImg.data
// 使用map方法遍历数组并创建Billboard
testArrayImg.map(function (item) {
const position = Cesium.Cartesian3.fromDegrees(item.longitude, item.latitude);
let testBillboard = viewer.entities.add({
position: position,
billboard: {
image: 'https://img9.png',
scale: 0.03, // 图片缩放比例
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND
},
});
testBillboard.myCustomProperty = item.url
// 注册点击事件
viewer.screenSpaceEventHandler.setInputAction(function onLeftClick (movement) {
var pickedObject = viewer.scene.pick(movement.position);
if (Cesium.defined(pickedObject) && Cesium.defined(pickedObject.id)) {
var billboard = pickedObject.id;
var description = billboard.myCustomProperty;
imgurl.value=description
checkDetail.value=true
console.log('点击了:' + description);
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
});
//添加线
datasource.entities.add({
name: "line",
polyline: {
positions: Cesium.Cartesian3.fromDegreesArrayHeights(newArray.flat()),
material: Cesium.Color.MEDIUMSPRINGGREEN,
width: 5
}
})
var property = new Cesium.SampledPositionProperty();
var starttime = new Date();
var stoptime;
var timestamp = starttime.getTime();
newArray.forEach((pos, index) => {
var time = new Date(timestamp + index * 5000);
stoptime = time;
var position = Cesium.Cartesian3.fromDegrees(pos[0], pos[1], pos[2])
property.addSample(Cesium.JulianDate.fromDate(time), position);
})
property.setInterpolationOptions({
interpolationDegree: 0.0001,
interpolationAlgorithm: Cesium.LagrangePolynomialApproximation
});
var entitydd = datasource.entities.add({
availability: new Cesium.TimeIntervalCollection([new Cesium.TimeInterval({
start: Cesium.JulianDate.fromDate(starttime),
stop: Cesium.JulianDate.fromDate(new Date(stoptime))
})]),
position: property, // 点集
//开启模型自定义视角
//orientation: new Cesium.VelocityOrientationProperty(property),
model: {
uri: '/uav-processed.glb',
//uri: './scenewZ.glb',
scale: 5,
minimumPixelSize: 120,
maximumScale: 500
},
path: {
leadTime: 0,
resolution: 1,
material: new Cesium.PolylineGlowMaterialProperty({
glowPower: 0.1,
color: Cesium.Color.GREEN
}),
width: 10
}
});
viewer.clock.currentTime = Cesium.JulianDate.fromDate(starttime); //修改时间轴的当前时间
viewer.clock.stopTime = Cesium.JulianDate.fromDate(new Date(stoptime));
viewer.clock.clockRange = Cesium.ClockRange.LOOP_STOP;
viewer.clock.shouldAnimate = true; //开始播放
viewer.zoomTo(datasource)
}
文章来源:https://www.toymoban.com/news/detail-818076.html
到了这里,关于vue中加载使用cesium加载3dTileset以及三维模型移动(1.108版本)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!