I have a model of a house and the polygons on the top of roofs. Since there is another 3d model which is expected to be moved with the mouse on the rooftops (like dragging), I was trying to use drillPick and pickPosition together to make this movement.
However, the picked height sometimes goes beyond the height of the model ( “24.04” in the first figure). The second figure is the one working well (the height is 8.37). Following is my code:
var ellipsoid = scene.globe.ellipsoid;
// Mouse over the globe to see the cartographic position
var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
handler.setInputAction(function (movement) {
var foundPosition = false;
var scene = viewer.scene;
var pickedObjects = scene.drillPick(movement.endPosition);
var foundPosition = false;
if (scene.pickPositionSupported && Cesium.defined(pickedObjects)) {
var cartesian = viewer.scene.pickPosition(movement.endPosition);
if (Cesium.defined(cartesian)) {
var cartographic = ellipsoid.cartesianToCartographic(cartesian);
lon = Cesium.Math.toDegrees(cartographic.longitude);
lat = Cesium.Math.toDegrees(cartographic.latitude);
hei = cartographic.height;
labelEntity.position = cartesian;
labelEntity.label.show = true;
labelEntity.label.text = ‘(’ + lon.toFixed(2) + ', ’ + lat.toFixed(2) + ', ’ + hei.toFixed(2) + ‘,’ + ‘)’;
var camera = scene.camera;
labelEntity.label.eyeOffset = new Cesium.Cartesian3(0.0, 0.0, camera.frustum.near * 1.5 - Cesium.Cartesian3.distance(cartesian, camera.position));
foundPosition = true;
}
}
if (!foundPosition) {
labelEntity.label.show = false;
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
``