camera.positionCartographic is the position of the camera, not the position of the mouse. You need to use e.clientX and e.clientY to get the mouse position. In fact, you can use the same exact code in you have in mousemove as the wheel callback.
Here’s your example, updated to work in all cases.
var viewer = new Cesium.Viewer(‘cesiumContainer’, {
timeline: true,
animation: false,
homeButton: false,
screenModePicker: false,
navigationHelpButton: false,
baseLayerPicker: false,
geocoder: false,
sceneMode: Cesium.SceneMode.SCENE3D
}
);
var entity = viewer.entities.add({
id: ‘mousemoveLabel’,
label: {
show: false
}
});
var mouseLabelCb = function (e) {
var ellipsoid = viewer.scene.globe.ellipsoid;
// Mouse over the globe to see the cartographic position
var cartesian = viewer.camera.pickEllipsoid(new Cesium.Cartesian2(e.clientX, e.clientY), ellipsoid);
if (cartesian) {
var cartographic = ellipsoid.cartesianToCartographic(cartesian);
var longitudeString = Cesium.Math.toDegrees(cartographic.longitude).toFixed(10);
var latitudeString = Cesium.Math.toDegrees(cartographic.latitude).toFixed(10);
entity.position = cartesian;
entity.label.show = true;
entity.label.text = ‘(’ + longitudeString + ', ’ + latitudeString + ‘)’;
} else {
entity.label.show = false;
}
};
viewer.scene.canvas.addEventListener(‘mousemove’, mouseLabelCb);
viewer.scene.canvas.addEventListener(‘wheel’, mouseLabelCb);