stamen/modestmaps-js — Issue #82: Map.addHandler() and Map.removeHandler()
Author: shawnbot
Created: 2012-01-04 18:32:52+00:00
State: open
Labels: nice-to-have

Currently, adding or removing a handler (mouse, touch, etc.) after a `Map` initializes requires some specific knowledge of the class's internals. It would be nice to provide a friendlier interface for adding and removing handlers by reference:

```javascript
MM.Map.prototype.removeHandler = function(handler) {
var handlers = this.eventHandlers,
len = handlers.length;
// assumes the handler only exists once in the array
for (var i = 0; i < len; i++) {
if (handlers[i] === handler) {
handlers.splice(i, 1);
break;
}
}
handler.remove();
};

MM.Map.prototype.addHandler = function(handler) {
this.eventHandlers.push(handler);
handler.init(this);
};
```