Enable globe issue

export const viewer = new Viewer(‘cesiumContainer’, {
timeline: false,
animation: false,
sceneModePicker: false,
baseLayerPicker: false,
terrainProvider: createWorldTerrainAsync(), // Enable world terrain for clamping
globe: true, // Enable the globe (this should be true to show the terrain)
});

In here whenever I set true the “globe” variable I’m receiving following errors. Anyone have an idea?

  1. viewerInstance.js:8 Error constructing CesiumWidget.
  2. Scene.js:780 Uncaught TypeError: Cannot read properties of undefined (reading ‘addEventListener’)

Hi @PaoloPetra ,
Thanks for your post and welcome to the Cesium community.

It appears as if your are trying to load the Cesium viewer with CesiumWorldTerrain shown on the globe. Is that right?

If yes, this code will work, you can drop in a sandcastle to verify https://sandcastle.cesium.com/

const viewer = new Cesium.Viewer("cesiumContainer", {
  terrain: Cesium.Terrain.fromWorldTerrain(),
});

Running the code you provided, I get the same first error that you shared. Did you find this code suggested somewhere specific? Perhaps it is outdated and we need to review that part of our documentation.

Please let me know if this alternative code works as you expect and if you know the origin of the initial code you shared and where our docs can be improved.

Thanks,
Luke

Hi luke, thanks for the welcome :slight_smile: , yes actually I solved it, I don’t know if in the correct way but it seems that everything works.

The point of my application was to be able to add my 3d tiles from google to the standard cesim maps.

so the first step was to add my 3d tiles on the maps this is the code:

const google3DTileset = new window.Cesium.Cesium3DTileset({
url: ‘https://tile.googleapis.com/v1/3dtiles/root.json?key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx’, // Enter the URL of your Google tiles here
});

const baseLayerPicker = viewerRef.current.baseLayerPicker;

// const imageryViewModels = ;
// Define the custom provider const customProviderViewModel = new window.Cesium.ProviderViewModel({ name: ‘Google 3D Tiles’, tooltip: ‘View Google 3D Tiles’, iconUrl: ‘/earth.png’, category : ‘Tiles 3d’, creationFunction: function () { return null; } });
baseLayerPicker.viewModel.imageryProviderViewModels.push(customProviderViewModel);

then to be able to observe the clicks on the other maps: window.Cesium.knockout.getObservable(baseLayerPicker.viewModel, ‘selectedImagery’).subscribe((selectedLayer) => { if (selectedLayer.category !== ‘Tiles 3d’) { const primitives = viewerRef.current.scene.primitives; const length = primitives.length; let existGoogle = false; for (let i = 0; i < length; ++i) { if (primitives._primitives[i]._url !== undefined) { const p = primitives.length; false;

// search google3DTileset
for (let i = 0; i < length; ++i) {
if (primitives._primitives[i]._url !== undefined) {
const p = primitives.get(i);
p.show = true;
existGoogle = true;
break;
}
}
if (!existGoogle) {
viewerRef.current.scene.primitives.add(google3DTileset);
}
}

this allowed me to make the map change work, as you can see on my map there are also two markers, so I had to check if the primitive had a url or not
hope this is useful to other users

Paul

@PaoloPetra
Happy to hear you resolved your issue.

For future reference and others trying to work with Google Photorealistic 3DTiles in CesiumJS, these resources are available:

Thanks and please let us know if you have more questions.
Best,
Luke

Hi @PaoloPetra,

One additional item to share. The CesiumJS API also supports subscribing to the knockout observable with Cesium.subscribeAndEvaluate() (note: this function is marked private so it is not in the documentation, but you can still use it)

More on knockout subscriptions is available here in the docs cesium/Documentation/Contributors/CodingGuide at main · CesiumGS/cesium · GitHub

An alternative to using the baseLayerPicker is the create a separate HTML UI dropdown field to toggle the Google Photorealistic 3D Tiles as described here Adding and removing Tile provider to the menu? - #4 by omar

Thanks again for coming to the forums with your questions.
Best,
Luke