Pick object by cartesian3 (without using mouse events)

Hello, I want to collect all the entities of a specific location (cartesian3). I’ve gone through Picking example in sandcastle in which objects can be picked by mouse click/movement.etc. But I want to pick objects without mouse interaction, simply by passing cartesian3 position.

Here is the experimental sandcastle link of what I’m doing.

In this example, If you click on Yellow point or anywhere in Red colored area, you can see on console number objects located on the clicked location.

Now, If you click on “Pick Entity” button, you will not get any picked objects number.

Below code can be used to convert canvas cordinates (cartesian2) to cartesian3:

//on mouse click handler
let ray = viewer.camera.getPickRay(click.position);
scene.globe.pick(ray, scene);

But how do it’s vice versa?

I just want to collect number of objects without using mouse events.

  • Thanks & Regards,

Hello @Jacky,

I tried to solve your problem using SceneTransforms.wgs84ToWindowCoordinates.

Check this Sandcastle. I hope it helps :slight_smile:

1 Like

Thank you so much @clementchdn . It really helped me. :slightly_smiling_face:

@clementchdn , Though your Sandcastle example is working, But it doesn’t work if entities are on the opposite side of the globe.
Please check this sandcastle link, click on the Pick Entity, it will work. Now rotate the globe to opposite side, and press again “Pick Entity”. It will not work.

drillPick is using canvas coordinates. Is there any other method to pick entities without using canvas coordinates?

UPDATE: Tried drillPickFromRay But it’s just returning the intersection point, not the exact entity object present on the intersection.

It’s really a serious issue/requirement for me. Please suggest if someone has already faced such issue and got it’s solution.

  • Regards,