**getreadyPromise()**方法在模型加载完成后调用
url为模型地址
javascript
// tileset模型
function tilesetM(url) {
tileset = viewer.scene.primitives.add(
new Cesium.Cesium3DTileset({
// url: '../../public/asd/tileset.json',
url: url,
// type: "3dtiles",
maximumScreenSpaceError: 2, //最大的屏幕空间误差
show: true,
})
);
viewer.flyTo(tileset);
viewer.scene.globe.depthTestAgainstTerrain = true; // 开启地形深度检测
// viewer.extend(Cesium.viewerCesium3DTilesInspectorMixin); // 开启3D Tiles检测器
getreadyPromise();
}
javascript
let dataModeList: any = [];
function getreadyPromise() {
var model = viewer.scene.primitives.get(0);
// 监听模型加载完成
model.readyPromise.then(function (modelval) {
let tileset3dDate = [];
//构件数据放入对象中
tileset.tileLoad.addEventListener(function (tile) {
processTileFeatures(tile, function (data) {
});
});
});
}
function processTileFeatures(tile, callback) {
var content = tile.content;
var innerContents = content.innerContents;
if (Cesium.defined(innerContents)) {
var length = innerContents.length;
for (var i = 0; i < length; ++i) {
processContentFeatures(innerContents[i], callback);
}
} else {
processContentFeatures(content, callback);
}
console.log('dataModeList:', dataModeList);
}
function processContentFeatures(content, callback) {
var featuresLength = content.featuresLength;
for (var i = 0; i < featuresLength; ++i) {
var feature = content.getFeature(i);
// console.log("feature:",feature.getProperty("CODE"))
// console.log("Id:",feature.getProperty("id"))
dataModeList.push({
id: feature.getProperty('id'),
name: feature.getProperty('name'),
CODE: feature.getProperty('CODE'),
sid: feature.getProperty('sid'),
modeName: feature.getProperty('名称'),
modeType: feature.getProperty('类型'),
});
callback(feature);
}
}