Cesium 加载地形数据


1.注册Cesium Ion账号,注册地址:Sign In | Cesium ion

否则,加载数据会报错{code: "InvalidCredentials", message: "Invalid access token"}

 2.在“Access Depot”中选择你需要的数据源,添加到“My Assets”。(此步骤可忽略。注册账号后,默认添加的数据源中已包含地形

3.获取token

4.设置token

// 在初始化 Cesium.Viewer 之前,设置token 
Cesium.Ion.defaultAccessToken = '你的token'

5.参考示例,加载地形数据

 6.效果图

 完整的js代码片段

Cesium.Ion.defaultAccessToken = '你的token'
var viewer = new Cesium.Viewer('cesiumContainer', {
  shouldAnimate: true,
  animation: false,
  baseLayerPicker: false,
  fullscreenButton: false,
  geocoder: false,
  homeButton: false,
  infoBox: false,
  sceneModePicker: false,
  selectionIndicator: false,
  timeline: false,
  navigationHelpButton: false,
  terrainProvider: new Cesium.CesiumTerrainProvider({
    url: Cesium.IonResource.fromAssetId(1)
  }),
  sceneMode: Cesium.SceneMode.SCENE3D
})
viewer.imageryLayers.addImageryProvider(
  new Cesium.IonImageryProvider({ assetId: 3 })
)