Ellipsoids are not creating on same clicked position if the terrain is On

Hi Cesium Team,
I’m trying to create ellipsoids on click event (means on clicked position on the globe) it’s working fine if the terrain is off but if the terrain is On it’s not creating on the same clicked location, it’s creating somewhere else please provide the solution to fix the problem. Code is given below:-
var that = this;
this.viewer.scene.canvas.addEventListener(“click”, function (e) {
if (that.cesiumContainerStyle == “crosshair”) {
that.diameterflag = true;
console.log(“clicked on map”)
var ellipsoid = that.viewer.scene.globe.ellipsoid;
that.longitudeString = null;
that.latitudeString = null;
that.mapheightString = null;
var cartesian = that.viewer.camera.pickEllipsoid(
new Cesium.Cartesian3(e.clientX, e.clientY),
ellipsoid
);
if (cartesian) {
var cartographic = ellipsoid.cartesianToCartographic(cartesian);
that.longitudeString = Cesium.Math.toDegrees(cartographic.longitude);
that.latitudeString = Cesium.Math.toDegrees(cartographic.latitude);
}
}
});
var dome = this.viewer.entities.add({
name: “Dome”,
position: Cesium.Cartesian3.fromDegrees(
this.longitudeString,
this.latitudeString
),
ellipsoid: {
radii: new Cesium.Cartesian3(domeX, domeX, domeZ),
heightReference: Cesium.HeightReference.RELATIVE_TO_GROUND,
maximumCone: Cesium.Math.PI_OVER_TWO,
material: Cesium.Color.WHITE.withAlpha(0.5),
outline: true,
},
});

With Best Regards
Shashi Verma

Hi Shashi,

If the terrain is turned on, you would want to use a function like drillPick or pick to accurately get the position on the globe. Here is an example: Sandcastle.

1 Like

Thanks