Scene.pickPosition returns "undefined"

The following Sandcastle example attempt to print the world coordinates on a right click.

This works in 3D, but in 2D it returns undefined.

Thoughts?

Example

Hi @poncho524,

the following code will work:

var viewer = new Cesium.Viewer("cesiumContainer", {
  sceneMode: Cesium.SceneMode.SCENE2D,
});

viewer.scene.canvas.addEventListener("contextmenu", function (event) {
  if (viewer.scene.pickPositionSupported) {
    var point = new Cesium.Cartesian2(event.clientX, event.clientY);
    console.log("point " + point);

    //modification starts
    var cart = viewer.camera.pickEllipsoid(point, viewer.scene.globe.ellipsoid);
    //modification ends

    console.log("cart " + cart);

  }
});

It seems in 2D pickPosition can’t find the correct ellipsoid on itself, so u have to take the walkaround through camera.pickEllipsoid and defining the ellipsoid with viewer.scene.globe.ellipsoid.

Maybe there is an other solution to this and I am completly wrong with my explanation, but at least this is a workaround :wink:

Best, Lennart

2 Likes

@lennart.imberg

Thank you for posting a response! We really appreciate your input :grinning: :rocket:

-Sam