var viewer = new Cesium.Viewer('cesiumContainer', { shadows : true }); // When true, the sphere will have an elevation occlusion effect (there will also be an elevation occlusion effect when there is no terrain) viewer.scene.globe.depthTestAgainstTerrain = true ; var viewModel = { height: 0 }; Cesium.knockout.track(viewModel); // Get the toolbar in the upper left corner var toolbar = document.getElementById('toolbar' ); Cesium.knockout.applyBindings(viewModel, toolbar); // Add 3D Tiles, the url is the path var tileset = new Cesium.Cesium3DTileset({ url: Cesium.IonResource.fromAssetId(3883 ) }); // The root of the tileset is ready tileset.readyPromise.then( function (tileset) { // Add tileset to the scene viewer.scene.primitives.add(tileset); // zoomTo (target, offset) target and offset viewer.zoomTo(tileset, new Cesium.HeadingPitchRange(0.0, -0.5, tileset.boundingSphere.radius * 2.0 )); }).otherwise( function (error) { // If the loading is not successful, it will prompt an error console.log(error); }); Cesium.knockout.getObservable(viewModel, 'height').subscribe(function(height) { height = Number(height); if (isNaN(height)) { return; } //地理位置 var cartographic = Cesium.Cartographic.fromCartesian(tileset.boundingSphere.center); var surface = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, 0.0); var offset = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, height); var translation = Cesium.Cartesian3.subtract(offset, surface, new Cesium.Cartesian3()); tileset.modelMatrix = Cesium.Matrix4.fromTranslation(translation); });