Detect whether mouse is on terrain, sky or object

Hi Dear Community,

I’m new to Cesium. I want to detect whether my mouse is on terrain, sky or object. I use pick function of scene but it returns undefined on map and sky. Are there any other way to do this correctly?

Here’s my sandcastle code: Sandcastle

Thanks in advance.

Hi @datum Welcome in Cesium community!
I’ve gone through your sandcastle example and I think you’ve already achieved that. As a beginner, I have done basic modifications on your example codes to check if the cursor is on Space, Map or on any object. Here is the link.

If you want to check if the cursor is on Land or Ocean, You can use Globe.getHeight or sampleTerrain function to get the surface height and match it with Ocean height which should be 0.

  • Regards,
1 Like

I always use a combination of something like;

  • var pos = pickPosition(), where undefined means I hit nothing, usually the sky, and
  • var things = drillPick() to see if I hit any objects

So, you can do something like;

  • var hittingSky = pos ? false : true
  • var hittingGround = !things || !things.length
  • var hittingThings = things && things.length

Should at least get you started.

Cheers,

Alex

1 Like