代码:
// 设为椭球var obj = [6378137.0, 6378137.0, 6356752.3142451793];Cesium.Ellipsoid.WGS84 = Object.freeze(new Cesium.Ellipsoid(obj[0], obj[1], obj[2]));var viewer = new Cesium.Viewer('cesiumContainer');var scene = viewer.scenescene.lightSource.ambientLightColor = new Cesium.Color(0.65, 0.65, 0.65, 1);var tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({url: 'http://10.90.3.116:8999/3dTiles/995ab8c02e114841b758259df5305492/tileset.json'}));// 定位tileset.readyPromise.then(function () {var boundingSphere = tileset.boundingSphere;viewer.camera.viewBoundingSphere(boundingSphere, new Cesium.HeadingPitchRange(0.0, -0.5, boundingSphere.radius));viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);}).otherwise(function (error) {throw(error);});// 监听鼠标点击事件viewer.screenSpaceEventHandler.setInputAction(function(click) {// 使用ray和场景进行交互检测var pickedFeature = viewer.scene.pick(click.position);// 检查是否点击了模型if (Cesium.defined(pickedFeature) && pickedFeature instanceof Cesium.Cesium3DTileFeature) {// 获取点击的模型的属性var attribute = pickedFeature.getProperty('buildid');console.log('buildid:', attribute);}}, Cesium.ScreenSpaceEventType.LEFT_CLICK);