Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenLayers 3: Remove event listener

In Openlayers 3 how to remove a event listener attached like this:

var a = map.on("pointerdrag",function (e) {
             // event handler
});

var b = map.on("pointerdrag",function (e) {
             // event handler
});

How do I remove only listner a and keep b active?

like image 832
Shaunak Avatar asked Aug 27 '15 15:08

Shaunak


1 Answers

Ah its pretty simple! Its in the API Docs: unByKey, but very counter-intuitive name for an off function.

So to remove the event listener a:

map.unByKey(a);

Will remove a listener but keep the b on.

Note: this will work across any object in Open Layers 3 that emits an event. like Layers, Interactions etc..

like image 152
Shaunak Avatar answered Sep 19 '22 18:09

Shaunak