I have a canvas element in which I draw something using WebGL.
Depending on what is drawn I am adding an event listener.
Now when I am redrawing the canvas, I want to remove the old event listener and add a new one.
Simply doing this will not work:
canvas.removeEventListener("click", function(event){
colorbarClicked(event, viewdata);
}, false);
canvas.addEventListener("click", function(event){
colorbarClicked(event, viewdata);
}, false);
I think it is because the colorbarClicked function has already changed (maybe because its parameters have different values?) and not matching the old one which I want to remove any more.
So my problem is that each time I am redrawing event listeners get added and therefore doubled. But the colorbarClicked function depends on what is drawn in the canvas, so I definitely need to change it.