//操作 倾斜影像数据的js 类库
|
function remove3dtileByPath(path) {
|
|
if (base3dtilesPrimitives != []) {
|
for (var i = 0; i < base3dtilesPrimitives.length; i++) {
|
path2 = serverIP + path;
|
if (base3dtilesPrimitives[i]._url == path2) {
|
viewer.scene.primitives.remove(base3dtilesPrimitives[i]);
|
//从数组中移除当前路径
|
base3dtilesPrimitives.splice(i, 1);
|
}
|
}
|
}
|
}
|
|
//卸载所有的3dtiles实景三维数据底图
|
function remove3dtilesmap() {
|
if (base3dtilesPrimitives != []) {
|
for (var i = 0; i < base3dtilesPrimitives.length; i++) {
|
viewer.scene.primitives.remove(base3dtilesPrimitives[i]);
|
}
|
base3dtilesPrimitives = [];
|
}
|
}
|
|
//判断是否存在
|
function is3dtileExsit(id,path) {
|
if (base3dtilesPrimitives != []) {
|
for (var i = 0; i < base3dtilesPrimitives.length; i++) {
|
if (base3dtilesPrimitives[i]._id == id && base3dtilesPrimitives[i]._url == path) {
|
return true;
|
}
|
|
}
|
}
|
return false;
|
}
|
/**
|
* 添加 3dties
|
* @returns options
|
*/
|
function add3dtiles(options) {
|
var id = options.id;
|
var path = options.url;
|
if (is3dtileExsit(id,path)) {
|
return;
|
}
|
var modelMatrix = Cesium.Matrix4.fromArray([
|
1.0, 0.0, 0.0, 0.0,
|
0.0, 1.0, 0.0, 0.0,
|
0.0, 0.0, 1.0, 0.0,
|
0.0, 0.0, 0.0, 1.0
|
]);
|
//配置数据
|
var tilesetOption = {
|
id: options.id,
|
url: options.url,
|
maximumScreenSpaceError: 16,
|
maximumNumberOfLoadedTiles: 2000,
|
maximumMemoryUsage: 8192,
|
skipLevels: 1,
|
modelMatrix: modelMatrix//引入转移矩阵
|
};
|
var tileset = new Cesium.Cesium3DTileset(tilesetOption);
|
tileset._id = options.id;
|
tileset._tilesType = options.tilesType;
|
tileset.loadJson = function (url) {
|
var resource = Resource.createIfNeeded(tilesetUrl);
|
return resource;
|
}
|
tileset.readyPromise.then(function () {
|
var a = tileset.boundingSphere.center.clone();
|
a.x += Number(options.x);
|
a.y += Number(options.y);
|
a.z += Number(options.z);
|
var cartographic = Cesium.Cartographic.fromCartesian(a);
|
var lng = Cesium.Math.toDegrees(cartographic.longitude);//经度值
|
var lat = Cesium.Math.toDegrees(cartographic.latitude);//纬度值
|
const cartographic2 = Cesium.Cartographic.fromCartesian(
|
tileset.boundingSphere.center
|
);
|
const surface = Cesium.Cartesian3.fromRadians(
|
cartographic2.longitude,
|
cartographic2.latitude,
|
0
|
);
|
const offset = Cesium.Cartesian3.fromRadians(
|
cartographic.longitude,
|
cartographic.latitude,
|
options.z
|
);
|
const translation = Cesium.Cartesian3.subtract(
|
offset,
|
surface,
|
new Cesium.Cartesian3()
|
);
|
var m = Cesium.Matrix4.fromTranslation(translation);
|
tileset._root.transform[12] += m[12];
|
tileset._root.transform[13] += m[13];
|
tileset._root.transform[14] += m[14];
|
})
|
// console.log(tileset._root);
|
//加载3dtiles数据
|
base3dtilesPrimitives.push(viewer.scene.primitives.add(tileset));
|
return tileset;
|
}
|
/**
|
* 更新位置
|
* @param {*} model
|
* @param {*} options
|
*/
|
function update3dtilesMaxtrixByXYZ(model, options) {
|
|
var mx = Cesium.Matrix4.fromArray([
|
1.0, 0.0, 0.0, 0.0,
|
0.0, 1.0, 0.0, 0.0,
|
0.0, 0.0, 1.0, 0.0,
|
options.x, options.y, options.z, 1.0
|
]);
|
model._modelMatrix = mx;
|
}
|
|
|
//随机颜色
|
function randomRgbaColor() { //随机生成RGBA颜色
|
var r = Math.floor(Math.random() * 256); //随机生成256以内r值
|
var g = Math.floor(Math.random() * 256); //随机生成256以内g值
|
var b = Math.floor(Math.random() * 256); //随机生成256以内b值
|
var alpha = Math.random(); //随机生成1以内a值
|
return "rgba(" + r + "," + g + "," + b + "," + 1 + ")"; //返回rgba(r,g,b,a)格式颜色
|
}
|
|
|
|
function update(url, lng, lat, height, head, pitch, roll, scaleparam) {
|
|
var modelMatrix = Cesium.Matrix4.fromArray([
|
1.0, 0.0, 0.0, 0.0,
|
0.0, 1.0, 0.0, 0.0,
|
0.0, 0.0, 1.0, 0.0,
|
0.0, 0.0, 0.0, 1.0
|
]);
|
|
var tilesetOption = {
|
url: url,
|
maximumScreenSpaceError: 16,
|
maximumNumberOfLoadedTiles: 2000,
|
maximumMemoryUsage: 8192,
|
skipLevels: 1,
|
modelMatrix: modelMatrix//引入转移矩阵
|
};
|
var tileset = new Cesium.Cesium3DTileset(tilesetOption);
|
|
let mx = Cesium.Matrix3.fromRotationX(Cesium.Math.toRadians(head));
|
let my = Cesium.Matrix3.fromRotationY(Cesium.Math.toRadians(pitch));
|
let mz = Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(roll));
|
let rotationX = Cesium.Matrix4.fromRotationTranslation(mx);
|
let rotationY = Cesium.Matrix4.fromRotationTranslation(my);
|
let rotationZ = Cesium.Matrix4.fromRotationTranslation(mz);
|
//平移
|
let position = Cesium.Cartesian3.fromDegrees(lng, lat, height);
|
let m = Cesium.Transforms.eastNorthUpToFixedFrame(position);
|
|
let scale = Cesium.Matrix4.fromUniformScale(scaleparam);
|
// //缩放
|
Cesium.Matrix4.multiply(m, scale, m);
|
//旋转、平移矩阵相乘
|
Cesium.Matrix4.multiply(m, rotationX, m);
|
Cesium.Matrix4.multiply(m, rotationY, m);
|
Cesium.Matrix4.multiply(m, rotationZ, m);
|
|
tileset.readyPromise.then(function () {
|
|
}).then(function () {
|
if (tileset._root.transform == undefined) {
|
console.log("瓦片未变换");
|
}
|
tileset._root.transform = m;
|
|
});
|
base3dtilesPrimitives.push(viewer.scene.primitives.add(tileset));
|
}
|