Triggering click event over cesium map

I saw in the source code that cesium listening to "pointerdown" DOM event for LEFT_CLICK (ScreenSpaceEventType). I tried to fire that event from my code but it didn't go well.

The classic events as click, mousedown, mouseup... don't trigger LEFT_CLICK.

Is there an easy way to trigger click events in Cesium? if not, how can i do it by myself?

Hi there,

I’m not sure exactly what problem you’re having, can you provide a code sample? This is an example of using different inputs in Cesium: https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/index.html?src=Camera%20Tutorial.html&label=Showcases

Thanks,

Gabby

I have no sample code. I only want to know how to trigger click events on cesium map. I know how to listen to those events already.

I tried to use jQuery click function, but it didn't trigger cesium click events.
So my question is - how to trigger cesium click events from code?

I would be most grateful if you could help me.

Take a look at that Sandcastle example (https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/index.html?src=Camera%20Tutorial.html&label=Showcases), it shows how to register an action to a screenSpaceEvent.

Thanks,

Gabby

As far as I understand the sandcastle example does not answer the question at all.

In the example you listen to mouse events with cesium event handlers and keydown events with document event handlers and record a dictionary of flags. Then this dicitonary is checked at every tick of the viewer to change the position and direction of the camera accordingly to the triggered event. However the events listened are normal mouse/key events.

Instead the question was: how can I trigger an event in cesium such that it can be listened to using the ScreenSpaceEventHandler?

By triggering that event through the web API, like https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click

Since that’s not really a Cesium-specific question, if you need an example, try a more general JavaScript forum.

Yeh i thougt maybe there is a Cesium API for this.

Its not so simple to implement it by yourself.
You’ll need to calculate the place to click on the screen from the coordinates you want. For zoom you’ll need to use wheel event and calculate the wheel rotation you need for the zoom you want.
In addition, you have to check if your browser supports pointer events, because Cesium wont listen to the old mouse events if your browser supports the new one (jQuery.click won’t help you either).

Indeed triggering using the web API does not work, thats why Im looking for info too.

It would be really great to let cesium intégrate with standard event handlers instead of only having its own. Otherwise it seems tricky to plug new kind of pointing and interaction devices.

Rather than simulating mouse inputs to trigger behavior in Cesium, you will probably have better results by simply executing the code you’re trying to trigger directly from JavaScript. What behavior are you trying to trigger? In general, anything that happens in response to mouse inputs should be accessible programmatically from the API directly.

I have been trying to mimic the mouse-drag and zoom behavior, but simply using rotate and move camera functions sadly won’t create the same effect as the default mouse behavior so I thought it would be nice to trigger mouse down/move/up click events given the pixel coordinates of the current and previous position instead.

If you want to see what is actually happening to the camera on these events, you can take a look at the source code fro ScreenSpaceCameraController.js, and look at the “handle” functions for each event. Then you can pick and choose the exact behavior you want.