# Disabling rotation when dragging

**URL:** <https://community.cesium.com/t/disabling-rotation-when-dragging/4278>\
**Category:** CesiumJS\
**Created:** [June 24, 2016, 2:30am UTC](https://community.cesium.com/t/disabling-rotation-when-dragging/4278 "2016-06-24T02:30:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Scott\_Mills](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/scott_mills/32/2185_2.png) [@Scott\_Mills](https://community.cesium.com/u/Scott_Mills)\
**Post date:** [June 24, 2016, 2:30am UTC](https://community.cesium.com/t/disabling-rotation-when-dragging/4278/1 "2016-06-24T02:30:12Z")

</div>

I am having a bit of trouble stopping rotation from occurring when dragging things on the map. When dragging an object you of course stop rotation with scene.screenSpaceCameraController.enableRotate = false.

This mostly works, except if you quickly drag the object around and release the mouse button while the mouse is still moving. The globe will spin for some reason, and I am not sure how to combat this.

It doesn't make sense to me, because you are re-enabling rotation when the mouse is released, so why would the globe start spinning?

I tried disabling inertiaSpin on mouse down and re-enabling it on mouse up but that appears to make no difference.

In this example you can see the issue: [http://analyticalgraphicsinc.github.io/cesium-google-earth-examples/examples/pinDrag.html](http://analyticalgraphicsinc.github.io/cesium-google-earth-examples/examples/pinDrag.html)

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![Sarah\_Osay](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/sarah_osay/32/12309_2.png) [@Sarah\_Osay](https://community.cesium.com/u/Sarah_Osay)\
**Post date:** [March 28, 2023, 4:16am UTC](https://community.cesium.com/t/disabling-rotation-when-dragging/4278/2 "2023-03-28T04:16:50Z")

</div>

Hi @Scott_Mills ,

I am also having this kind of issue. I just wanted to do panning without the rotation when quickly dragging the object. Are you able to fix this issue or do you have a workaround on how to prevent this?

Thanks,  
Sarah

---

<div class="post-metadata">

**Author:** ![ka\_sc](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/ka_sc/32/2397_2.png) [@ka\_sc](https://community.cesium.com/u/ka_sc)\
**Post date:** [March 29, 2023, 12:52am UTC](https://community.cesium.com/t/disabling-rotation-when-dragging/4278/3 "2023-03-29T00:52:30Z")

</div>

We really dont like it on touch devices

---

<div class="post-metadata">

**Author:** ![nbes](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/nbes/32/8522_2.png) [@nbes](https://community.cesium.com/u/nbes)\
**Post date:** [September 17, 2024, 7:28am UTC](https://community.cesium.com/t/disabling-rotation-when-dragging/4278/4 "2024-09-17T07:28:23Z")

</div>

Hi, I know this is an old post, but I recently stumbled upon the very same issue while implementing draggable entities. The globe always kept spinning a little bit after dragging an object due to inertia, although I disabled the camera inputs with `scene.screenSpaceCameraController.enableInputs = false` upon the `LEFT_DOWN` mouse event and resetting it to `true` upon `LEFT_UP`. After some digging through the Cesium Source code and checking how the inertia gets applied etc., [I found this interesting little function inside `CameraEventAggregator`](https://github.com/CesiumGS/cesium/blob/165e0fb4fcc9a448b15de6a2df46db23c71fffda/packages/engine/Source/Scene/CameraEventAggregator.js#L232) and a workaround to stop the inertia spin from happening that seems to work for my dragging use case:

```javascript
function cancelMouseDownAction(cancelKey, aggregator) {
  const releaseTime = aggregator._releaseTime;
  const isDown = aggregator._isDown;
  if (isDown[cancelKey]) {
    aggregator._buttonsDown = Math.max(aggregator._buttonsDown - 1, 0);
  }
  isDown[cancelKey] = false;
  releaseTime[cancelKey] = new Date();
}

```

In this function, the `cancelKey` parameter is the _camera_ event key you want to cancel (`LEFT_DRAG` camera event is key ‘0’ (string)) and the _aggregator_ parameter is the `CameraEventAggregator` instance that is a private member inside the `ScreenSpaceCameraController` (`screen.screenSpaceCameraController._aggregator`).  
As far as I understand it, the `CameraEventAggregator` ‘collects’ `ScreenSpaceEventType` (input) events that happen between frames and aggregates them to _internal_ `CameraEventType` (camera) events, e.g. ‘left mouse down’, ‘mouse move’. ‘mouse move’, ‘left mouse up’ events get converted to a single `LEFT_DRAG` camera event with a start and end position and timestamps when the buttons were pressed/released. Based on the time difference between the mouse button press/release the inertia gets calculated (I think). So what I did is I utilitzed the above function to cancel the `LEFT_DRAG` event as soon as I ‘picked’ my draggable entity in the `LEFT_DOWN` event. This seems to work perfectly without any downsides. [I also re-created the ‘pinDrag’ Sandcastle that Scott\_Mills mentioned with a boolean `APPLY_DRAG_INERTIA_FIX` to enable or disable the workaround.](https://sandcastle.cesium.com/#c=tVaNT9tGFP9XTplUHCk9k0Ch5aNrAFPQQoOS0K1apuhsPydXzneR70yWTfzve+ezjUOD1FWbkcDv3fu+3++ZSEltyAOHFWTklEhYkXPQPE/p50LnTVtRIZ8raRiXkE1b7eOpjAo/HYEEdHP+tBDrw4ilkLGnUyfjsf3xfTIOJmRydT0mkyGZjO4C/7I/GAdWGgf45yogweVlcD4ZVwH7t7eDL7OLUf/j7PpTMJpc92eX179hApPlUMZ1lksuz3Iu4uc93dZ6r31cljFZcE2SXEaGK0nwPVJLDjFJMpWWfmSs8iyCSMVAPpDzoo/gAaTpz+cZzJlRWRFKA5CFMUt95PtzbhZ5SCOV+i7Ix7HvJumHQoV+9+AN7CbhfhJF79j+/tuw+yaGA9aLk/2DOOztRYfdJEli5i9ZdM/moH2Qc5y/72rxx3bW/tZa6Ff906C315vKuq2IyQjEjco1XKiV7Bdaz2l/gXWHsNq7Tf6eSkLcIDMQwDRMeGqv+cmIzhonx0/2XNvwz0ydsrDiCfGc+Hud/I8yI9lwCnNjMGQZ7oaZBU3Zn95LJq9Jt0N220WSxyLT8ywYJWFCu2ob1W+aWLBcMAMFPh5LiEQZoIowEudpurboIjhwbtYV3pz0BPVC5qApi2OvaE7iRR2RaetMMHlPQpGDDTNtdezhUmluL+Sowuk5ywy+MblHLQwvAJsG7b0+fEO7h7uHvYMO2XtH3/V23x4cHLaLGCEXIlQsi4+qafIUYXPU4EIR61wJlXlVHivQ0fBLf3A2uAs6ZP9tmxqFA2B3o4HnIhPyAJnhERPDjCME6yo/b6jp2XAyGd4ULo/4+7FmGMuArIBEeZbhYMSaxBleI5fzn6fygWW12Lghd7BgMhbPOTzG2wA5RlpAgfsrZ+TVWwZddZ1bQGJIanFPYosTsC5V4KksX6gGcy2XuSmJ4dqu2ONFgkf3NUqLiWB1S1RCPAy/QmSwxGL5Uat09rS6VQdK91j8l33EkCCdY68Zpk1evSIbGspjcnp6WiKsvVGEfZye1rePO5gJy9Uu7R1vmjbGXC7M5qkrXz8N160Wu/YzJUQBahYKGCljudAkU/U033H0djfblX0dXJCrYBSgrmnBE2/7Qv+mx+3La2d3p/MdVc8am+3YlmXsvhc4egQEaBQBx4ET7xBuylROy6WBTDJB3NquvmcFouwsHZY2S/0PHywVG8bvkMpcKYYzXyObKfk/c6bsHojOkbJGESWRrQgo4aa2WoAsRqMc6NcqJyuGfELTYiIrpsmOg+9Os8jHTWhseZ4MStvHcve8wPrJegl0EFxOZhfDXz9NZU14x/VUPcCPcd16pui3gUJL24o+L1GwojtSwyGl2AWBEHypFY/rwMij+HbLavgXfd8M78bB7Gb4Oagaf77r8uWPdb/R3Mu7pVH2luX9wyulsZa++/rvbu0MWp3WiTZrAe+r9B94ulSZIXkmPEp9A+lSYBbthznC09BI62r6J37T9STmD4THp1v+8SWRYFrjSZILMeZ/wbT1/sRH+29chWIxDmWIX07B1tZs0X0/cEpK6YmP4nZPo5QIWfYs8j8) When the boolean is false and you drag/flick the pin around the globe will spin due to inertia after letting go of the pin. When the boolean is true, this behavior is prevented.

Please note that the `cancelMouseDownAction` should NOT immediately be called every time the `LEFT_DOWN` event is triggered, but rather when the `LEFT_DOWN` event is called and some condition is met (like a draggable entity was picked, like in the Sandcastle)

Hope that helps.

**TL;DR**  
Check this [‘pinDrag’ Sandcastle](https://sandcastle.cesium.com/#c=tVaNT9tGFP9XTplUHCk9k0Ch5aNrAFPQQoOS0K1apuhsPydXzneR70yWTfzve+ezjUOD1FWbkcDv3fu+3++ZSEltyAOHFWTklEhYkXPQPE/p50LnTVtRIZ8raRiXkE1b7eOpjAo/HYEEdHP+tBDrw4ilkLGnUyfjsf3xfTIOJmRyd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WoAsRqMc6NcqJyuGfELTYiIrpsmOg+9Os8jHTWhseZ4MStvHcve8wPrJegl0EFxOZhfDXz9NZU14x/VUPcCPcd16pui3gUJL24o+L1GwojtSwyGl2AWBEHypFY/rwMij+HbLavgXfd8M78bB7Gb4Oagaf77r8uWPdb/R3Mu7pVH2luX9wyulsZa++/rvbu0MWp3WiTZrAe+r9B94ulSZIXkmPEp9A+lSYBbthznC09BI62r6J37T9STmD4THp1v+8SWRYFrjSZILMeZ/wbT1/sRH+29chWIxDmWIX07B1tZs0X0/cEpK6YmP4nZPo5QIWfYs8j8) and how the Cesium internal `cancelMouseDownAction` function is used within that Sandcastle.
