Remove Event Listeners in Cesium

I searched quite a bit to find out the correct way to remove event listeners in Cesium. I believe the confusion I have is around whether to treat Cesium events as regular dom events (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 (movement) {
        var picked = scene.pick(movement.endPosition);
        if (Cesium.defined(picked) && picked.id === someEntity) {
            labelEntity.position = someEntity.position;
            labelEntity.label.show = true;
        } else {
            labelEntity.label.show = false;
        }
    }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

My question is, how can I remove this event? Is handler.destroy() removes all the event listeners associated with handler, or do I specifically have to remove event listeners by pointing to the cesium map dom element and calling removeEventListener on it? If that's the case, what parameters should be passed to removeEventListener?

1 Answer

The parameters for removeInputAction are just the type and optionally the modifer, and it looks like you're not using the modifier (SHIFT key, ALT key etc.)

So for the code you posted above, the removal would be:

handler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

David Miller

David Miller

Executive Financial & Market Analyst

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.

Share this article
Twitter Facebook Pinterest