Tag Archives: cesium CLAMP_TO_GROUND Error

cesium CLAMP_TO_GROUND Error Cannot read property ‘globe‘ of undefined

Billboardcollection needs to add highreference: Cesium.HeightReference.CLAMP_ TO_ GROUND

Statement:

var viewer = new Cesium.Viewer("cesiumContainer", {
  terrainProvider: new Cesium.EllipsoidTerrainProvider({}),
});
viewer.scene.globe.depthTestAgainstTerrain = true;

var billboardCollection = new Cesium.BillboardCollection({});
viewer.scene.primitives.add(billboardCollection);

billboardCollection.add({
		image: "../images/facility.gif",
		height: 20,
		width: 20,
		position: Cesium.Cartesian3.fromDegrees(77.273593, 38.191217),
		scale: 3.0,
		pixelOffset: new Cesium.Cartesian2(0.0, -20.0),
		heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
	});

In this case, an error will be reported:

Solution: scene: must be added viewer.scene

var billboardCollection = viewer.scene.primitives.add(
  new Cesium.BillboardCollection({
    scene: viewer.scene,
  })
);