Remove Event Listners in Cesium

I looked around quite a bit to find out the correct way to remove event listners in Cesium. I believe the confusion I have is around whether to treat Cesium events as regular DOM events or as Cesium specific ones (due to a lack of knowledge about events in general in javascript). I am creating a screen space event like below:

    var handler = new Cesium.ScreenSpaceEventHandler(canvas);

    handler.setInputAction(function (m) {
        var picked = scene.pick(m.endPosition);
        if (Cesium.defined(picked) && === someEntity) {
   = true;
        } else {
   = false;
    }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

My question is, how can I remove this event listner? Does handler.destroy() remove all the event listners associated with handler, or do I specifically have to remove event listners by pointing to the cesium map DOM element and calling removeEventListner on it? If that’s the case, what parameters should be passed on to removeEventListner ?

You can remove event listener by this:

1 Like

Thank you @onsummer . If I want to remove all the event listeners attached to the handler and also the handler itself, will it be fine to do handler.destroy()? Will that guarantee that those listeners are not going to be present in the cesium view from which I removed the events?


1 Like

Hi @onsummer,

Thanks for the suggestion! I think removeInputAction is the perfect method for this use case :+1: