Terrain view model using fromUrl

In earlier versions of CesiumJS I have used the following snippet to add a terrain server to the view model:

var terrainProviders = [];

terrainProviders.push(new Cesium.ProviderViewModel({
	name: "90m Australia",
	iconUrl: './icon/opentopomap.png',
	tooltip: '90m Australia Terrain',
	category: 'Offline',
	creationFunction: function() {
		return new Cesium.CesiumTerrainProvider({
      url: 'https://terrain.datr.dev/data/90m_australia/',
		});
	}
}));

var viewer = new Cesium.Viewer("cesiumContainer", {
	baseLayerPicker: true,
	imageryProviderViewModels: imageryProviders,
	terrainProviderViewModels: terrainProviders,
	geocoder: false,
	shouldAnimate: false,
	selectionIndicator: false
});

In newer versions (1.114) clicking this terrain server makes the globe go blank. I understand this was a change from version 1.104. I can’t understand how to integrate the example snippet into my code - here is my attempt which also results in a blank globe;

terrainProviders.push(new Cesium.ProviderViewModel({
	name: "90m Australia",
	iconUrl: './icon/opentopomap.png',
	tooltip: '90m Australia Terrain',
	category: 'Offline',
	creationFunction: function() {
		return new Cesium.Terrain(Cesium.CesiumTerrainProvider.fromUrl(
      'https://terrain.datr.dev/data/90m_australia/'
		));
	}
}));
1 Like

You should only need to provide the CesiumTerrainProvider.fromUrl, no need to wrap it in a Terrain object. I believe this should work:

terrainProviders.push(new Cesium.ProviderViewModel({
	name: "90m Australia",
	iconUrl: './icon/opentopomap.png',
	tooltip: '90m Australia Terrain',
	category: 'Offline',
	creationFunction: function() {
		return Cesium.CesiumTerrainProvider.fromUrl(
      'https://terrain.datr.dev/data/90m_australia/'
		);
	}
}));

If you’re still having issues are you able to replicate the problem in Sandcastle and share that minimal example with us?

1 Like

Works perfect, very simple fix, much appreciated!