# how to draw figure at right position by mouse when 3d, terrainProvider and groundPrimitive

**URL:** <https://community.cesium.com/t/how-to-draw-figure-at-right-position-by-mouse-when-3d-terrainprovider-and-groundprimitive/3332>\
**Category:** CesiumJS\
**Created:** [November 18, 2015, 6:04am UTC](https://community.cesium.com/t/how-to-draw-figure-at-right-position-by-mouse-when-3d-terrainprovider-and-groundprimitive/3332 "2015-11-18T06:04:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cecn](https://avatars.discourse-cdn.com/v4/letter/c/aca169/32.png) [@cecn](https://community.cesium.com/u/cecn)\
**Post date:** [November 18, 2015, 6:04am UTC](https://community.cesium.com/t/how-to-draw-figure-at-right-position-by-mouse-when-3d-terrainprovider-and-groundprimitive/3332/1 "2015-11-18T06:04:13Z")

</div>

I can't obtain the correct coordinates by mouse.

&nbsp;&nbsp;&nbsp;&nbsp;In 2d scene mode, It could get the rigth coordinates on mouse pointer, but when 3D or 2.5D, and have terrainProvider, the coordinates on mouse pointer have some offset, earth window center's point coordinate is rigth, and the point more farther center the offset is bigger. so I think maybe the terrain influence, the same window screen location(x, y) have diffirent coordinate.

&nbsp;&nbsp;&nbsp;&nbsp;Could we get the same and right coordinate by mouse on 3d or 2.5d and overlay terrainProvider? because this is very important when draw mark, polyline, polygon, rectangle when clam to gound(use groundPrimitive).

---

<div class="post-metadata">

**Author:** ![hannah](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/hannah/32/4509_2.png) [@hannah](https://community.cesium.com/u/hannah)\
**Post date:** [November 20, 2015, 3:47am UTC](https://community.cesium.com/t/how-to-draw-figure-at-right-position-by-mouse-when-3d-terrainprovider-and-groundprimitive/3332/2 "2015-11-20T03:47:00Z")

</div>

Hello,

If you are using camera.pickEllipsoid, this could give unexpected results with terrain enabled.

Instead, try using viewer.camera.getPickRay and viewer.scene.globe.pick. Here is an example that gets the position on the terrain:

var handler = new Cesium.ScreenSpaceEventHandler(viewer.canvas, false);  
handler.setInputAction(  
function(click) {  
var ray = viewer.camera.getPickRay(click.position);  
var position = viewer.scene.globe.pick(ray, viewer.scene);  
if (Cesium.defined(position)) {  
// Make the height of the position = 0 so it works with groundPrimitive  
var positionCartographic = viewer.scene.globe.ellipsoid.cartesianToCartographic(position);  
positionCartographic.height = 0;  
position = viewer.scenne.globe.ellipsoid.cartographicToCartesian(positionCartographic);  
}  
},  
Cesium.ScreenSpaceEventType.LEFT\_CLICK  
);

``

Best,

Hannah

---

<div class="post-metadata">

**Author:** ![cecn](https://avatars.discourse-cdn.com/v4/letter/c/aca169/32.png) [@cecn](https://community.cesium.com/u/cecn)\
**Post date:** [November 23, 2015, 3:42pm UTC](https://community.cesium.com/t/how-to-draw-figure-at-right-position-by-mouse-when-3d-terrainprovider-and-groundprimitive/3332/3 "2015-11-23T15:42:07Z")

</div>

Thank you very much, I have resolved my problem by your code.
