这是cc导出来的cesium项目目录:
这个是index.html:
下面的代码是main.js
// 设置你的bing地图key
Cesium.BingMapsApi.defaultKey = 'Ap2z3Su_tKy7X9Zdy5EuFqzLmEa6bPKtLCS8_Gnsq-btg91SoZDGTto22NoEO4FB';
//构造地形源的默认列表
var terrainModels = Cesium.createDefaultTerrainProviderViewModels();
//用我们需要的基本应用程序来构造查看器
var viewer = new Cesium.Viewer('cesiumContainer', {
timeline:false,
animation:false,
vrButton:true,
sceneModePicker:false,
infoBox:true,
scene3DOnly:true,
terrainProviderViewModels: terrainModels,
selectedTerrainProviderViewModel: terrainModels[1] // 选择STK高分辨率地形
});
// No depth testing against the terrain to avoid z-fighting
viewer.scene.globe.depthTestAgainstTerrain =false;
//添加奔特力的logo
viewer.scene.frameState.creditDisplay.addDefaultCredit(new Cesium.Credit('Cesium 3D Tiles produced by Bentley ContextCapture', 'Resources/logoBentley.png', 'http://www.bentley.com/'));
//创建视角包围球
var boundingSphere = new Cesium.BoundingSphere(Cesium.Cartesian3.fromDegrees(114.3471862, 22.71530611, 141.5000843), 130.8524335);
// 重载home键的行为
viewer.homeButton.viewModel.command.beforeExecute.addEventListener(function(commandInfo) {
//飞到自定义位置
viewer.camera.flyToBoundingSphere(boundingSphere);
//告诉home键不要做任何事情。
commandInfo.cancel = true;
});
//设置自定义初始位置
viewer.camera.flyToBoundingSphere(boundingSphere, {duration: 0});
// 用于调整屏幕空间错误和内存使用的功能
var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Opera: function() {
return navigator.userAgent.match(/Opera Mini/i);
},
Windows: function() {
return navigator.userAgent.match(/IEMobile/i);
},
any: function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
}
};
// 添加 tileset.不要忘记将默认屏幕空间错误减少到1
var tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
url: '../Scene/cesium_3d_tite.json',
maximumScreenSpaceError : isMobile.any() ? 8 : 1, // Temporary workaround for low memory mobile devices - Increase maximum error to 8.
maximumNumberOfLoadedTiles : isMobile.any() ? 10 : 1000 // Temporary workaround for low memory mobile devices - Decrease (disable) tile cache.
}));