cesium加载批量模型
class CreateModel {
constructor() { }
// 添加单条数据
addEntity(item) {
// 删除实体
// viewer.entities.removeAll();
// 添加实体位置
var position = Cesium.Cartesian3.fromDegrees(
...item.latLon,
item.height
);
//弧度的航向分量。
var heading = Cesium.Math.toRadians(135);
//弧度的螺距分量。
var pitch = 0;
//滚动分量(以弧度为单位)
var roll = 0;
//HeadingPitchRoll旋转表示为航向,俯仰和滚动。围绕Z轴。节距是绕负y轴的旋转。滚动是关于正x轴。
var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);
var orientation = Cesium.Transforms.headingPitchRollQuaternion(
position,
hpr
);
//实体
var entity = viewer.entities.add({
name: item.url,
position: position,
orientation: orientation,
model: {
uri: item.url,
//不管缩放如何,模型的最小最小像素大小。
minimumPixelSize: 10000,
//模型的最大比例尺大小。 minimumPixelSize的上限。
maximumScale: 20000,
},
});
viewer.trackedEntity = entity;
// 获取或设置相机当前正在跟踪的Entity实例。
}
}
const createModel = new CreateModel();
// data是模型资源的数据
const data = [
{ url: '/model/untitled.glb', latLon: [114.35850419018853, 38.914157063533844], height: 50},
{ url: '/model/untitled.glb', latLon: [116.35850419018553, 39.914157063534844], height: 50},
{url: '/model/untitled.glb', latLon: [116.35850419018553, 39.914157063534844], height: 50},
{url: '/model/untitled.glb', latLon: [117.55850419018553, 39.914157063534844], height: 50},
{url: '/model/untitled.glb', latLon: [118.85850419018553, 39.914157063534844], height: 50},
{url: '/model/untitled.glb', latLon: [113.41850419018553, 39.914157063534844], height: 50},
{url: '/model/untitled.glb', latLon: [112.45850419018553, 39.914157063534844], height: 50},
{url: '/model/untitled.glb', latLon: [111.55850419018553, 39.914157063534844], height: 50},
{url: '/model/untitled.glb', latLon: [116.35850419018553, 31.914157063534844], height: 50},
{url: '/model/untitled.glb', latLon: [117.55850419018553, 32.914157063534844], height: 50},
{url: '/model/test.glb', latLon: [118.85850419018553, 33.914157063534844], height: 50},
{url: '/model/test.glb', latLon: [113.41850419018553, 34.914157063534844], height: 50},
{url: '/model/untitled6.glb', latLon: [116.35850419018553, 39.914157063534844], height: 50},
{url: '/model/untitled.glb', latLon: [111.55850419018553, 39.914157063534844], height: 50},
];
// 循环数据
data.forEach((item, i) => {
// item是数组中的单条
createModel.addEntity(item)
});