ScreenSpaceEventHandler LEFT_CLICK and LEFT_DOWN actions

Hello,

I’m not sure if this is intended but a LEFT_DOWN is also registered on a LEFT_CLICK. Running the snippet below in Cesium 1.21 sandcastle…

var viewer = new Cesium.Viewer(‘cesiumContainer’);

var scene = viewer.scene;

var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);

handler.setInputAction(function(movement) {

var cartesian = viewer.camera.pickEllipsoid(movement.position, scene.globe.ellipsoid);

if (cartesian) {

var cartographic = Cesium.Cartographic.fromCartesian(cartesian);

var longitudeString = Cesium.Math.toDegrees(cartographic.longitude).toFixed(2);

var latitudeString = Cesium.Math.toDegrees(cartographic.latitude).toFixed(2);

console.log(’(’ + longitudeString + ', ’ + latitudeString + ‘)’);

}

}, Cesium.ScreenSpaceEventType.LEFT_CLICK);

handler.setInputAction(function(movement) {

console.log(‘LEFT_DOWN’);

}, Cesium.ScreenSpaceEventType.LEFT_DOWN);

``

Our application uses various handler objects, each disabled and enabled programmatically, depending how the user wants to interact with the map. The handler object is basically a wrapper around Cesium.ScreenSpaceEventHandler and the callback action logic only execute if that handler is enabled.

In one of the capability, the handle object registers both a LEFT_CLICK and LEFT_DOWN action callback similar to the snippet above. I would think that the LEFT_DOWN is never called on a LEFT_CLICK but if you run the snippet above, you’ll get the console output of the LEFT_DOWN on every left click of the mouse. Is there a way to not let the console output ‘LEFT_DOWN’ from the snippet above? (without having to toggle some flag and checking it inside the LEFT_DOWN action)

Thank you.

Hello,

This behavior is caused by the browser. Left click is fired when left down is immediately followed by left up. So left down will always fire on click, but click will only fire if the button is not held down after it is pressed.

It is generally not recommended to have both a left click and left down action, since it is often not possible to distinguish between the two.

Best,

Hannah

Hi, Hannah - Thank you for the clarification!