# ScreenSpaceEventHandler

**URL:** <https://community.cesium.com/t/screenspaceeventhandler/11951>\
**Category:** CesiumJS\
**Created:** [January 7, 2021, 4:36pm UTC](https://community.cesium.com/t/screenspaceeventhandler/11951 "2021-01-07T16:36:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rob](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/rob/32/5906_2.png) [@Rob](https://community.cesium.com/u/Rob)\
**Post date:** [January 7, 2021, 4:36pm UTC](https://community.cesium.com/t/screenspaceeventhandler/11951/1 "2021-01-07T16:36:05Z")

</div>

I am attempting to replicate the functionality of drawing lines on the terrain that is found in [this Sandcastle example](https://sandcastle.cesium.com/index.html#c=nVfrb9s2EP9XOH+ZDHhy0jZ7OGmw1PGaYEltxG6DrS4SRjpbRGlSICk73uD/fUeRsiQ/8li+OCLvfb873s2pInMGC1DkPRGwIF3QLJuFX/KzYNyI8u+uFIYyAWrcaJF/x4IQDRwiw6S4FDGLqJGqQyaUa2jZWyYm8oN8rB4ZUApFDJScsxiQ2muKFFADt1LxeORIgiYyrJrHYzEWbEKCH5yBoY5AQJiy6PtAamZ1D7M0lcpA3HRGLZiI5SKkHJRB20cJ0+RByYVG92IJmghpiHZMpCooHDesvpVV6bU5x29ZPAWDqhWAGKY0gt4chLmgIkYloYKZnMOlSDNzlkcjsGZ4z4YbTKNlCuFV74/R3Xn/84er3l336rL751hYzZNM5PzEhWMgmTDBwgalMNG7OMeEpfYW8+UtRdFIATqkcRzkRARJHFeH1IS0ilsU0CGelpBIcllmpGu/wtuLy1GvVVCk7BH4kP0DHXK0PkyATRNzAxNQICJYC7ion4fdq7Prwd2of/fxpv/507nnX+W/eZ4JUWAyJZxhLhHW0VhRTOn0WsaA7o4bHCE4blTDZSmGCU0hKDw+p4ZWYqXtZa7CQqkm8H0pslnEIid/OrQ2fHxp+SoRLCOuO6RqSqukiDidpSP5UclMxB1iVAaV2wWLTdIhb9dHqyJOLkIrAlhKe7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TPAjDtoFZyjHsuv2QRd9xUYz0+nU7aVdZT2I2Jyx+v2OjtouB1ngzyXi+Y40bpydtpN9ixeYRYzb7OChxurRkyeHplTsMw/CkjZ+7OY3LJLIUnpwY+sBhrdtu7AMqgFdILNGDjJen1TI6Mar2bU/i0yuYGJSFz1oOiTgmlKCVCGq0Cu9rEtobInaLvLFLZClTG8x2nn3X+Z8Ti5812/HbOlxEphKl/wA).

However, the only time points or lines are drawn is when my cursor is over an object that has been added to the scene such as a model, label, etc. When the cursor is just over the globe the events don’t work.

I’m convinced there’s a simple reason for this, but I’m not sure what to look for. Why would these listeners only fire when the cursor is over objects in the scene and not the globe itself?

UPDATE:  
I discovered that the listeners are firing just fine. It’s actually the value being returned from viewer.scene.pickPosition that’s the issue. It’s not returning the position under the cursor unless the cursor is over an object that has been added to the scene. Instead… if the cursor is just over the globe then the position being returned is quite a distance from the cursor. Any ideas about why this is happening would be appreciated.

Is viewer.scene.pickPosition the best way to get the most accurate point on the ground?

---

<div class="post-metadata">

**Author:** ![jos](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/jos/32/3102_2.png) [@jos](https://community.cesium.com/u/jos)\
**Post date:** [January 7, 2021, 11:14pm UTC](https://community.cesium.com/t/screenspaceeventhandler/11951/2 "2021-01-07T23:14:23Z")

</div>

I think it can depend on which ‘version’ of `pickPosition` you use. When moving over the globe i use the `event.EndPosition` inside the function (from `handler.setInputAction((event) => {})`); when clicking, i use `event.position`.

---

<div class="post-metadata">

**Author:** ![Rob](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/rob/32/5906_2.png) [@Rob](https://community.cesium.com/u/Rob)\
**Post date:** [January 9, 2021, 6:43am UTC](https://community.cesium.com/t/screenspaceeventhandler/11951/3 "2021-01-09T06:43:41Z")

</div>

Thanks, jos…

I’m interested to know if viewer.scene.pickPosition is the best approach for getting an accurate location on the ground as a result of a click of the mouse. I had difficulty getting this to work, so I ended up using:

```
var pickRay = scene.camera.getPickRay(event.position);
var earthPosition = scene.globe.pick(pickRay, scene); //returns a cartesian3 at the mouse position whether there is terrain or not

```

It seems there are several approaches. I’d like to understand when to use approach and why?

---

<div class="post-metadata">

**Author:** ![James\_B](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/james_b/32/2424_2.png) [@James\_B](https://community.cesium.com/u/James_B)\
**Post date:** [January 12, 2021, 8:56am UTC](https://community.cesium.com/t/screenspaceeventhandler/11951/4 "2021-01-12T08:56:20Z")

</div>

There are a couple of longstanding bugs with picking points on the surface depending on what map mode you’re in (2D/3D/Columbus). You can follow these on GitHub if you’re interested:

- [scene.pickPosition returns incorrect position · Issue #4368 · CesiumGS/cesium · GitHub](https://github.com/CesiumGS/cesium/issues/4368)
- [pickPosition doesn't pick ellipsoid in 2D and CV · Issue #5076 · CesiumGS/cesium · GitHub](https://github.com/CesiumGS/cesium/issues/5076)
- [Camera.computeViewRectangle doesn't work in 2D or CV · Issue #4346 · CesiumGS/cesium · GitHub](https://github.com/CesiumGS/cesium/issues/4346)

I wound up with a solution similar to yours, except using `scene.camera.pickEllipsoid`. The last link above shows some of the code I’m using.

---

<div class="post-metadata">

**Author:** ![Rob](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/rob/32/5906_2.png) [@Rob](https://community.cesium.com/u/Rob)\
**Post date:** [January 15, 2021, 4:34pm UTC](https://community.cesium.com/t/screenspaceeventhandler/11951/5 "2021-01-15T16:34:43Z")

</div>

James\_B thanks for the response and the links. These are helpful to read through.

This topic (best way to get the click location) seems to be a very common question with a big variety of answers.

I wish one of the Cesium guys would take this topic and summarize a “best practices” answer…
