Remove Event Listeners in Cesium

Viewed 148

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 Answers

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);
Related