1 | import {Class} from './Class';
|
2 |
|
3 | /*
|
4 | L.Handler is a base class for handler classes that are used internally to inject
|
5 | interaction features like dragging to classes like Map and Marker.
|
6 | */
|
7 |
|
8 | // @class Handler
|
9 | // @aka L.Handler
|
10 | // Abstract class for map interaction handlers
|
11 |
|
12 | export var Handler = Class.extend({
|
13 | initialize: function (map) {
|
14 | this._map = map;
|
15 | },
|
16 |
|
17 | // @method enable(): this
|
18 | // Enables the handler
|
19 | enable: function () {
|
20 | if (this._enabled) { return this; }
|
21 |
|
22 | this._enabled = true;
|
23 | this.addHooks();
|
24 | return this;
|
25 | },
|
26 |
|
27 | // @method disable(): this
|
28 | // Disables the handler
|
29 | disable: function () {
|
30 | if (!this._enabled) { return this; }
|
31 |
|
32 | this._enabled = false;
|
33 | this.removeHooks();
|
34 | return this;
|
35 | },
|
36 |
|
37 | // @method enabled(): Boolean
|
38 | // Returns `true` if the handler is enabled
|
39 | enabled: function () {
|
40 | return !!this._enabled;
|
41 | }
|
42 |
|
43 | // @section Extension methods
|
44 | // Classes inheriting from `Handler` must implement the two following methods:
|
45 | // @method addHooks()
|
46 | // Called when the handler is enabled, should add event hooks.
|
47 | // @method removeHooks()
|
48 | // Called when the handler is disabled, should remove the event hooks added previously.
|
49 | });
|
50 |
|
51 | // @section There is static function which can be called without instantiating L.Handler:
|
52 | // @function addTo(map: Map, name: String): this
|
53 | // Adds a new Handler to the given map with the given name.
|
54 | Handler.addTo = function (map, name) {
|
55 | map.addHandler(name, this);
|
56 | return this;
|
57 | };
|